// @flow strict import * as React from 'react'; import type {ColorTypes} from '../../types/typography'; import {TEXT_COLORS} from '../../types/typography'; import {classify} from '../../utils/classify'; import {ConditionalWrapper} from '../ConditionalWrapper'; import type {IconType} from '../Icon'; import {CloseIcon, Icon, ICON_SIZE, ICON_TYPE} from '../Icon'; import type {BaseTooltipProps} from '../Tooltip'; import {Tooltip} from '../Tooltip'; import css from './PromptChip.module.css'; type ClassNames = $ReadOnly<{ icon?: string, wrapper?: string, children?: string, container?: string, }>; export const PROMPT_CHIP_TYPE = Object.freeze({ primary: 'primary', secondary: 'secondary', }); export type PromptChipType = $Values; export type PromptChipProps = { classNames?: ClassNames, ... | { onDismiss?: ?(SyntheticEvent) => mixed, dismissable: true, selfDismiss?: boolean, } | {dismissable?: false}, type?: PromptChipType, onClick?: ?(SyntheticEvent) => mixed, iconName?: string, iconType?: IconType, children?: React.Node, iconColor?: ColorTypes, rightSlot?: React.Node, showInfoIcon?: boolean, infoIconTooltip?: BaseTooltipProps, }; export const PromptChip: React$AbstractComponent< PromptChipProps, HTMLDivElement, > = React.forwardRef( (props: PromptChipProps, ref): React.Node => { const { type = PROMPT_CHIP_TYPE.primary, onClick, iconType = ICON_TYPE.solid, iconName = 'lightbulb', children, iconColor, rightSlot, onDismiss, classNames, dismissable, selfDismiss, showInfoIcon, infoIconTooltip, } = props; const [dismissed, setDismissed] = React.useState(false); const closeClickHandler = (e) => { e.stopPropagation(); onDismiss?.(e); selfDismiss && setDismissed(true); }; return ( <> {!dismissed && (
{ onClick?.(event); }} tabIndex={onClick ? 0 : undefined} role="button" >
{!!children && (
{children}
)}
{rightSlot ? rightSlot : null} {!!showInfoIcon && ( 0 } wrapper={(children) => ( {children} )} > )} {!!dismissable && ( )}
)} ); }, );