{"version":3,"file":"badge.mjs","names":[],"sources":["../../../../package/common/badge/badge.tsx"],"sourcesContent":["import type { ReactElement } from 'react';\nimport cx from 'classnames';\n\nimport { BadgeStyleType, BadgePosition } from './badge.types';\nimport type { BadgeProps } from './badge.types';\nimport styles from './badge.module.pcss';\nimport { useComponentDefaults } from '../configProvider';\nimport { ThemeColor } from '../themeProvider/color.types';\nimport { toneProps, useToneCheck } from '../styles/tone';\n\nconst CLASS_BY_STYLE: Record<BadgeStyleType, string> = {\n  [BadgeStyleType.Filled]: styles.badgeStyleFilled,\n  [BadgeStyleType.Light]: styles.badgeStyleLight,\n  [BadgeStyleType.Outlined]: styles.badgeStyleOutlined,\n};\n\nconst CLASS_BY_POSITION: Record<BadgePosition, string> = {\n  [BadgePosition.TopRight]: styles.badgePositionTopRight,\n  [BadgePosition.TopLeft]: styles.badgePositionTopLeft,\n  [BadgePosition.BottomRight]: styles.badgePositionBottomRight,\n  [BadgePosition.BottomLeft]: styles.badgePositionBottomLeft,\n};\n\nfunction Badge(props: BadgeProps): ReactElement {\n  const {\n    count,\n    max = 99,\n    content,\n    dot = false,\n    showZero = false,\n    styleType = BadgeStyleType.Filled,\n    color = ThemeColor.Primary,\n    position = BadgePosition.TopRight,\n    children = null,\n    className,\n    style,\n    classNames,\n    styles: slotStyles,\n    ...rest\n  } = useComponentDefaults('Badge', props);\n  const hasCount = typeof count === 'number';\n  const hasContent = content != null;\n  const isHiddenByZero = !dot && !hasContent && hasCount && count === 0 && !showZero;\n  const showBadge = (dot || hasContent || hasCount) && !isHiddenByZero;\n\n  const displayValue = hasContent ? content : hasCount ? (count > max ? `${max}+` : count) : null;\n  const isOverlay = children != null;\n  const tone = toneProps(color);\n  useToneCheck('Badge', [color]);\n\n  return (\n    <span {...rest} className={cx(styles.wrapper, className)} style={style}>\n      {children}\n      {showBadge && (\n        <span\n          className={cx(\n            styles.badge,\n            tone.className,\n            dot ? styles.badgeDot : CLASS_BY_STYLE[styleType],\n            isOverlay && styles.badgeOverlay,\n            isOverlay && CLASS_BY_POSITION[position],\n            classNames?.badge,\n          )}\n          style={{ ...tone.style, ...slotStyles?.badge }}\n        >\n          {!dot && displayValue}\n        </span>\n      )}\n    </span>\n  );\n}\n\nexport default Badge;\n"],"mappings":"kZAUA,IAAM,EAAiD,EACpD,EAAe,QAAS,EAAO,kBAC/B,EAAe,OAAQ,EAAO,iBAC9B,EAAe,UAAW,EAAO,kBACpC,EAEM,EAAmD,EACtD,EAAc,UAAW,EAAO,uBAChC,EAAc,SAAU,EAAO,sBAC/B,EAAc,aAAc,EAAO,0BACnC,EAAc,YAAa,EAAO,uBACrC,EAEA,SAAS,EAAM,EAAiC,CAC9C,GAAM,CACJ,QACA,MAAM,GACN,UACA,MAAM,GACN,WAAW,GACX,YAAY,EAAe,OAC3B,QAAQ,EAAW,QACnB,WAAW,EAAc,SACzB,WAAW,KACX,YACA,QACA,aACA,OAAQ,EACR,GAAG,GACD,EAAqB,QAAS,CAAK,EACjC,EAAW,OAAO,GAAU,SAC5B,EAAa,GAAW,KAExB,GAAa,GAAO,GAAc,IAAa,EAD9B,CAAC,GAAO,CAAC,GAAc,GAAY,IAAU,GAAK,CAAC,GAGpE,EAAe,EAAa,EAAU,EAAY,EAAQ,EAAM,GAAG,EAAI,GAAK,EAAS,KACrF,EAAY,GAAY,KACxB,EAAO,EAAU,CAAK,EAG5B,OAFA,EAAa,QAAS,CAAC,CAAK,CAAC,EAG3B,EAAC,OAAD,CAAM,GAAI,EAAM,UAAW,EAAG,EAAO,QAAS,CAAS,EAAU,QAAjE,SAAA,CACG,EACA,GACC,EAAC,OAAD,CACE,UAAW,EACT,EAAO,MACP,EAAK,UACL,EAAM,EAAO,SAAW,EAAe,GACvC,GAAa,EAAO,aACpB,GAAa,EAAkB,GAC/B,GAAY,KACd,EACA,MAAO,CAAE,GAAG,EAAK,MAAO,GAAG,GAAY,KAAM,EAE5C,SAAA,CAAC,GAAO,CACL,CAAA,CAEJ,GAEV"}