import type { FC } from 'react' import { useState } from 'react' import { RiMoreFill, } from '@remixicon/react' import { PortalToFollowElem, PortalToFollowElemContent, PortalToFollowElemTrigger, } from '@/app/components/base/portal-to-follow-elem' export type Item = { value: string | number text: string | JSX.Element } type DropdownProps = { items: Item[] secondItems?: Item[] onSelect: (item: Item) => void renderTrigger?: (open: boolean) => React.ReactNode popupClassName?: string } const Dropdown: FC = ({ items, onSelect, secondItems, renderTrigger, popupClassName, }) => { const [open, setOpen] = useState(false) const handleSelect = (item: Item) => { setOpen(false) onSelect(item) } return ( setOpen(v => !v)}> { renderTrigger ? renderTrigger(open) : (
) }
{ !!items.length && (
{ items.map(item => (
handleSelect(item)} > {item.text}
)) }
) } { (!!items.length && !!secondItems?.length) && (
) } { !!secondItems?.length && (
{ secondItems.map(item => (
handleSelect(item)} > {item.text}
)) }
) }
) } export default Dropdown