// @flow strict import * as React from 'react'; import {classify} from '../../utils/classify'; import type {IconType} from '../Icon'; import {Icon} from '../Icon'; import {Truncate} from '../Truncate'; import css from './Chip.module.css'; type ClassNames = $ReadOnly<{wrapper?: string}>; export const CHIP_SEMANTIC = Object.freeze({ primary: 'primary', information: 'information', success: 'success', warning: 'warning', danger: 'danger', secondary: 'secondary', }); export type ChipSemanticType = $Values; export type BaseChipProps = { classNames?: ClassNames, semantic?: ChipSemanticType, children: React.Node, disabled?: boolean, onClick?: ?(SyntheticEvent) => mixed, onMouseEnter?: ?(SyntheticEvent) => mixed, onMouseLeave?: ?(SyntheticEvent) => mixed, }; export type MediumChipProps = { ...BaseChipProps, size?: 'medium', iconName?: string, iconType?: IconType, dismissable?: boolean, onDismiss?: ?(SyntheticEvent) => mixed, }; export type SmallChipProps = { ...BaseChipProps, size?: 'small', }; export type ChipProps = MediumChipProps | SmallChipProps; export const Chip: React$AbstractComponent = React.forwardRef( ( { classNames, semantic = 'primary', size = 'medium', children, iconName = '', iconType = 'regular', dismissable = false, onDismiss = () => null, onClick, disabled, ...rest }: ChipProps, ref, ): React.Node => (
{iconName && size !== 'small' && ( )} {children} {dismissable && size !== 'small' && ( { event.stopPropagation(); if (!disabled && onDismiss) { onDismiss(event); } }} /> )}
), );