Sha256: 3f80a6d76c97721561e96ddab828f9283db3486a0ee73e66f726d19c556a718e

Contents?: true

Size: 1.93 KB

Versions: 214

Compression:

Stored size: 1.93 KB

Contents

import React from 'react'
import classnames from 'classnames'

import { globalProps, GlobalProps } from '../utilities/globalProps'
import {
  buildAriaProps,
  buildCss,
  buildDataProps,
  buildHtmlProps } from '../utilities/props'

import Icon from '../pb_icon/_icon'

type BadgeProps = {
  aria?: {[key: string]: string},
  className?: string,
  closeProps?: {
    onClick?: React.MouseEventHandler<HTMLSpanElement>,
    onMouseDown?: React.MouseEventHandler<HTMLSpanElement>,
    onTouchEnd?: React.TouchEventHandler<HTMLSpanElement>,
  },
  data?: {[key: string]: string},
  htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
  id?: string,
  removeIcon?: boolean,
  removeOnClick?: React.MouseEventHandler<HTMLSpanElement>,
  rounded?: boolean,
  text?: string,
  variant?: "error" | "info" | "neutral" | "notification" | "primary" | "success" | "warning",
} & GlobalProps
const Badge = (props: BadgeProps): React.ReactElement => {
  const {
    aria = {},
    className,
    closeProps = {},
    data = {},
    htmlOptions = {},
    id,
    removeIcon = false,
    removeOnClick,
    rounded = false,
    text,
    variant = 'neutral',
  } = props
  const ariaProps = buildAriaProps(aria)
  const dataProps = buildDataProps(data)
  const htmlProps = buildHtmlProps(htmlOptions)
  const css = classnames(
    buildCss('pb_badge_kit', variant === "success" ? "success_sm" : variant, rounded ? 'rounded' : null),
    globalProps(props),
    className
  )

  return (
    <div
        {...ariaProps}
        {...dataProps}
        {...htmlProps}
        className={css}
        id={id}
    >
      <span>
        {text}
        {removeIcon && (
          <span
              onClick={removeOnClick}
              style={{ cursor: 'pointer' }}
              {...closeProps}
          >
            <Icon
                fixedWidth
                icon="times"
            />
          </span>
        )}
      </span>
    </div>
  )
}

export default Badge

Version data entries

214 entries across 214 versions & 1 rubygems

Version Path
playbook_ui-14.1.0.pre.alpha.PBNTR455ganttchartPOC3569 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-14.1.0.pre.alpha.fixaction3547 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-14.1.0.pre.alpha.PA1477timestampkit3536 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-14.0.0.pre.alpha.testthemeexport3533 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-14.0.0.pre.alpha.updateviewcomponentgem3527 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-14.0.0.pre.alpha.PLAY15063526 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-14.0.0.pre.alpha.PLAY15063525 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-14.0.0.pre.alpha.PLAY15063524 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-14.0.0.pre.alpha.PLAY15063523 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-14.0.0.pre.alpha.PLAY15063522 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-14.0.0.pre.alpha.PBNTR416formpillsizes3521 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-14.0.0.pre.alpha.PLAY15063520 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-14.0.0.pre.alpha.PLAY14923518 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-14.0.0.pre.alpha.PLAY15063511 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-14.0.0.pre.alpha.PA1477timestampkit3509 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-14.0.0.pre.alpha.PLAY14733507 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-14.0.0.pre.alpha.PBNTR416formpillsizes3506 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-14.0.0.pre.alpha.PA1477timestampkit3502 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-14.0.0.pre.alpha.PBNTR415starratingform3493 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-14.0.0.pre.alpha.PBNTR415starratingform3492 app/pb_kits/playbook/pb_badge/_badge.tsx