UNPKG

@atlaskit/badge

Version:

A badge is a visual indicator for numeric values such as tallies and scores.

76 lines (75 loc) 2.94 kB
/* badge.tsx generated by @compiled/babel-plugin v3.0.2 */ import "./badge.compiled.css"; import * as React from 'react'; import { ax, ix } from "@compiled/react/runtime"; import { memo } from 'react'; import { fg } from '@atlaskit/platform-feature-flags/fg'; import { Text } from '@atlaskit/primitives/compiled'; import { appearanceMapping } from './appearance-mapping'; import { appearanceMappingToOld } from './appearance-mapping-to-old'; import BadgeNew from './badge-new'; import { formatValueWithNegativeSupport } from './internal/format-value-with-negative-support'; /** * Visual refresh colors. * Hardcoded hex colors are used as the they will be updated in the labelling system work and we want to avoid frequent UI changes.\ * * Using separate variables as opposed to an object, to comply with UI styling standard * https://atlassian.design/components/eslint-plugin-ui-styling-standard/no-unsafe-values/usage#object-access */ const neutral300 = '#DDDEE1'; const red300 = '#FD9891'; const blue300 = '#8FB8F6'; const neutral1000 = '#292A2E'; const styles = { root: "_2rkolb4i _18zr1b66 _1e0c116y _vchhusvi _1ul91ejb _1bah1h6o _1o9zidpf _1kz6184x", added: "_bfhk1y9u _syazi7uo", default: "_bfhk1fkg _syazwwip", important: "_bfhk1366 _syazwwip", primary: "_bfhk1ymo _syazwwip", primaryInverted: "_bfhkvuon _syaz1oa5", removed: "_bfhk1gly _syazi7uo" }; const badgeValueWithNegativeNumberSupported = (children, max) => { return typeof children === 'number' && typeof max === 'number' ? formatValueWithNegativeSupport(children, max) : children; }; /** * __Badge__ * * This component gives you the full badge functionality and automatically formats the number you provide in \`children\`. * * - [Examples](https://atlassian.design/components/badge/examples) * - [Code](https://atlassian.design/components/badge/code) * - [Usage](https://atlassian.design/components/badge/usage) */ const Badge = /*#__PURE__*/memo(function Badge({ appearance = 'default', children = 0, max = 99, style, testId }) { if (fg('platform-dst-lozenge-tag-badge-visual-uplifts')) { // Map old appearance names to new ones const newAppearance = appearanceMapping[appearance]; return /*#__PURE__*/React.createElement(BadgeNew, { appearance: newAppearance, max: max, style: style, testId: testId }, children); } const oldAppearance = appearanceMappingToOld[appearance]; return /*#__PURE__*/React.createElement("span", { "data-testid": testId, style: { background: style === null || style === void 0 ? void 0 : style.backgroundColor, color: style === null || style === void 0 ? void 0 : style.color }, className: ax([styles.root, styles[oldAppearance]]) }, /*#__PURE__*/React.createElement(Text, { size: "small", align: "center", color: "inherit" }, badgeValueWithNegativeNumberSupported(children, max))); }); export default Badge;