UNPKG

@atlaskit/badge

Version:

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

78 lines (77 loc) 3.22 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 */ var neutral300 = '#DDDEE1'; var red300 = '#FD9891'; var blue300 = '#8FB8F6'; var neutral1000 = '#292A2E'; var 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" }; var badgeValueWithNegativeNumberSupported = function 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) */ var Badge = /*#__PURE__*/memo(function Badge(_ref) { var _ref$appearance = _ref.appearance, appearance = _ref$appearance === void 0 ? 'default' : _ref$appearance, _ref$children = _ref.children, children = _ref$children === void 0 ? 0 : _ref$children, _ref$max = _ref.max, max = _ref$max === void 0 ? 99 : _ref$max, style = _ref.style, testId = _ref.testId; if (fg('platform-dst-lozenge-tag-badge-visual-uplifts')) { // Map old appearance names to new ones var newAppearance = appearanceMapping[appearance]; return /*#__PURE__*/React.createElement(BadgeNew, { appearance: newAppearance, max: max, style: style, testId: testId }, children); } var 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;