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.0.0.pre.alpha.PLAY1475bumpaxecoredependency3483 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-14.0.0.pre.alpha.PLAY14733479 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-14.0.0.pre.alpha.dependabotnpmandyarnreactjoyride2823478 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-14.0.0.pre.alpha.play1447alphatest3462 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-14.1.0 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-13.34.1.pre.alpha.PLAY14043436 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-13.34.1.pre.alpha.pbntr258paginationkitforreact3413 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-13.34.1.pre.alpha.pbntr258paginationkitforreact3411 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-13.34.1.pre.alpha.pbntr258paginationkitforreact3409 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-13.34.1.pre.alpha.pbntr258paginationkitforreact3404 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-13.34.1.pre.alpha.powerfontsexternal3403 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-14.0.0 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-13.34.1.pre.alpha.PLAY14633399 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-13.34.1.pre.alpha.play1407statvaluekitinconsistencies3388 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-13.34.1.pre.alpha.PLAY14703378 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-13.34.0.pre.alpha.PLAY14143373 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-13.34.0.pre.alpha.PLAY14143372 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-13.34.1 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-13.34.0.pre.alpha.PBNTR358responsiveadvancedtablereact3370 app/pb_kits/playbook/pb_badge/_badge.tsx
playbook_ui-13.34.0.pre.alpha.PBNTR358responsiveadvancedtablereact3369 app/pb_kits/playbook/pb_badge/_badge.tsx