import React, { forwardRef, memo, useMemo, ForwardedRef, type JSX } from 'react' import { useObjectRef } from '@react-aria/utils' import Icon from '../Icon' import { useClassNames } from '../../_lib/useClassNames' import './index.css' type SizeMap = { S: 32 M: 40 } export type TagItemProps = { label: string translatedLabel?: string bgColor?: string bgImage?: string status?: 'default' | 'active' | 'inactive' size?: keyof SizeMap /** * The component used for root element. * @type T extends React.ElementType = 'button' */ component?: T } & Omit, 'children'> const TagItem = forwardRef( function TagItemInner( { component, label, translatedLabel, bgColor = '#7ACCB1', bgImage, size = 'M', status = 'default', ...props }: TagItemProps, _ref: ForwardedRef, ) { const ref = useObjectRef(_ref) const hasTranslatedLabel = translatedLabel !== undefined && translatedLabel.length > 0 const className = useClassNames( 'charcoal-tag-item', 'charcoal-tag-item__bg', props.className, ) const bgVariant = bgImage !== undefined && bgImage.length > 0 ? 'image' : 'color' const bg = bgVariant === 'color' ? bgColor : `url(${bgImage ?? ''})` const Component = useMemo(() => component ?? 'button', [component]) return (
{hasTranslatedLabel && ( {translatedLabel} )} {label}
{status === 'active' && }
) }, ) as (p: TagItemProps) => JSX.Element export default memo(TagItem)