@atlaskit/badge
Version:
A badge is a visual indicator for numeric values such as tallies and scores.
36 lines • 1.43 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)
*/
const Badge = /*#__PURE__*/memo(function Badge({
appearance = 'default',
children = 0,
max = 99,
style,
testId
}) {
// Map old appearance names to new ones
const 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.
const 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;