import type { FC } from 'react' import { useMemo, useState } from 'react' import { RiArrowDownSLine, RiCheckLine, RiCloseCircleFill, RiFilter3Line } from '@remixicon/react' import cn from '@/utils/classnames' import { PortalToFollowElem, PortalToFollowElemContent, PortalToFollowElemTrigger, } from '@/app/components/base/portal-to-follow-elem' export type Item = { value: number | string name: string } & Record type Props = { className?: string panelClassName?: string showLeftIcon?: boolean leftIcon?: any value: number | string items: Item[] onSelect: (item: any) => void onClear: () => void } const Chip: FC = ({ className, panelClassName, showLeftIcon = true, leftIcon, value, items, onSelect, onClear, }) => { const [open, setOpen] = useState(false) const triggerContent = useMemo(() => { return items.find(item => item.value === value)?.name || '' }, [items, value]) return (
setOpen(v => !v)} className='block' >
{showLeftIcon && (
{leftIcon || ( )}
)}
{triggerContent}
{!value && } {!!value && (
{ e.stopPropagation() onClear() }}>
)}
{items.map(item => (
{ onSelect(item) setOpen(false) }} >
{item.name}
{value === item.value && }
))}
) } export default Chip