@atlaskit/badge
Version:
A badge is a visual indicator for numeric values such as tallies and scores.
38 lines • 1.69 kB
JavaScript
/* badge.tsx generated by @compiled/babel-plugin v3.0.2 */
import * as React from 'react';
import { ax, ix } from "@compiled/react/runtime";
import { memo } from 'react';
import { appearanceMapping } from './appearance-mapping';
import BadgeNew from './badge-new';
import { formatValueWithNegativeSupport } from './internal/format-value-with-negative-support';
/**
* __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;
// Map old appearance names to new ones
var newAppearance = 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' ? formatValueWithNegativeSupport(children, max) : children;
return /*#__PURE__*/React.createElement(BadgeNew, {
appearance: newAppearance,
max: false,
style: style,
testId: testId
}, formattedValue);
});
export default Badge;