import { DefaultMantineColor, Menu, MenuItemProps, MenuProps } from '@mantine/core'; import { Icon } from '../icon/Icon'; import { ActionButton } from '../actionbutton/ActionButton'; export type WidgetMenuItem = { icon?: string; label: string; onClick: () => void; color?: DefaultMantineColor; closeMenuOnClick?: boolean; disabled?: boolean; } & MenuItemProps; export type WidgetMenuItems = (WidgetMenuItem | '-' | string)[]; export type WidgetMenuProps = { icon: string; ariaLabel?: string; disabled?: boolean; readOnly?: boolean; inline?: boolean; items?: WidgetMenuItems; } & MenuProps; export function WidgetMenu({ icon, disabled, inline = true, readOnly, items, ariaLabel, ...menuProps }: WidgetMenuProps) { if (items == null || items.length === 0 || readOnly) { return null; } const allItemsDisabled = items.find((item) => typeof item !== 'string' && item.disabled !== true) == null; return ( {items.map((item, index) => { if (item === '-') { return ; } if (typeof item === 'string') { return {item}; } const leftSection = item.icon ? {item.icon} : null; return ( {item.label} ); })} ); }