UNPKG

@itwin/itwinui-react

Version:

A react component library for iTwinUI

42 lines (41 loc) 1.3 kB
import * as React from 'react'; import cx from 'classnames'; import { isSoftBackground, SoftBackgrounds, Box } from '../../utils/index.js'; let getBadgeColorValue = (color) => { if (!color) return ''; return isSoftBackground(color) ? SoftBackgrounds[color] : color; }; let getStatusValue = (color) => { let statuses = ['positive', 'negative', 'warning', 'informational']; return color && statuses.includes(color) ? color : void 0; }; export const Badge = React.forwardRef((props, forwardedRef) => { let { backgroundColor, style, className, children, ...rest } = props; let reducedBackgroundColor = 'primary' === backgroundColor ? 'informational' : backgroundColor; let statusValue = getStatusValue(reducedBackgroundColor); let _style = reducedBackgroundColor && !statusValue ? { '--iui-badge-background-color': getBadgeColorValue( reducedBackgroundColor, ), ...style, } : { ...style, }; return React.createElement( Box, { as: 'span', className: cx('iui-badge', className), style: _style, 'data-iui-status': statusValue, ref: forwardedRef, ...rest, }, children, ); }); if ('development' === process.env.NODE_ENV) Badge.displayName = 'Badge';