UNPKG

@atlaskit/badge

Version:

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

47 lines (46 loc) • 2.72 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; var _react = _interopRequireWildcard(require("react")); var React = _react; var _runtime = require("@compiled/react/runtime"); var _appearanceMapping = require("./appearance-mapping"); 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); } /** * __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; // Map old appearance names to new ones var newAppearance = _appearanceMapping.appearanceMapping[appearance]; // Pre-format the value using the backward-compatible formatter (supports negative numbers) // then pass max={false} to BadgeNew so it doesn't apply its own (clamping) formatting. var formattedValue = typeof children === 'number' && typeof max === 'number' ? (0, _formatValueWithNegativeSupport.formatValueWithNegativeSupport)(children, max) : children; return /*#__PURE__*/React.createElement(_badgeNew.default, { appearance: newAppearance, max: false, style: style, testId: testId }, formattedValue); }); var _default = exports.default = Badge;