import { PropsWithChildren } from 'react'; import { IconType } from 'react-icons'; import { Menu as BaseMenu } from '@base-ui/react/menu'; import style from './DropdownMenu.module.scss'; type DropdownMenuItemDivider = { type: 'divider' }; type DropdownMenuItem = { type: 'item' | 'destructive'; label: string; icon?: IconType; disabled?: boolean; onClick: () => void; shortcut?: string; }; export type DropdownMenuOption = DropdownMenuItemDivider | DropdownMenuItem; interface DropdownMenuProps extends BaseMenu.Trigger.Props { items: DropdownMenuOption[]; } export function DropdownMenu({ items, children, ...triggerProps }: PropsWithChildren) { return ( {children} {items.map((item, index) => { if (item.type === 'divider') { return ; } return ( {item.icon && } {item.label} {item.shortcut && {item.shortcut}} ); })} ); } interface PositionedDropdownMenuProps { items: Array; isOpen: boolean; onClose: () => void; position: { x: number; y: number }; } export function PositionedDropdownMenu({ items, isOpen, position, onClose }: PositionedDropdownMenuProps) { return ( { if (!open) onClose(); }} > {items.map((item, index) => { if (item.type === 'divider') { return ; } return ( {item.icon && } {item.label} {item.shortcut && {item.shortcut}} ); })} ); }