UNPKG

@atlaskit/badge

Version:

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

87 lines (85 loc) 4.32 kB
/* badge.tsx generated by @compiled/babel-plugin v3.0.2 */ "use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _typeof = require("@babel/runtime/helpers/typeof"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; require("./badge.compiled.css"); var _react = _interopRequireWildcard(require("react")); var React = _react; var _runtime = require("@compiled/react/runtime"); var _fg = require("@atlaskit/platform-feature-flags/fg"); var _compiled = require("@atlaskit/primitives/compiled"); var _appearanceMapping = require("./appearance-mapping"); var _appearanceMappingToOld = require("./appearance-mapping-to-old"); var _badgeNew = _interopRequireDefault(require("./badge-new")); var _formatValueWithNegativeSupport = require("./internal/format-value-with-negative-support"); function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); } /** * 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' ? (0, _formatValueWithNegativeSupport.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__*/(0, _react.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 ((0, _fg.fg)('platform-dst-lozenge-tag-badge-visual-uplifts')) { // Map old appearance names to new ones var newAppearance = _appearanceMapping.appearanceMapping[appearance]; return /*#__PURE__*/React.createElement(_badgeNew.default, { appearance: newAppearance, max: max, style: style, testId: testId }, children); } var oldAppearance = _appearanceMappingToOld.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: (0, _runtime.ax)([styles.root, styles[oldAppearance]]) }, /*#__PURE__*/React.createElement(_compiled.Text, { size: "small", align: "center", color: "inherit" }, badgeValueWithNegativeNumberSupported(children, max))); }); var _default = exports.default = Badge;