import { CSSProperties, ReactNode } from 'react'; import { SlotClassNames, SlotStyles, HtmlProps } from '../types/slots.types.js'; import { IconContent } from '../types/icon.types.js'; import { PopoverAlign, PopoverPlacement } from '../popover/popover.types.js'; import { Presentation } from '../configProvider/presentation.types.js'; /** One thing the menu can do. */ export interface MenuAction { /** Stable id, also what `onAction` reports. */ id: string; label: ReactNode; icon?: IconContent; /** * A keyboard shortcut for this action, in `useHotkeys` spelling: `'mod+k'`, * `'shift+f2'`, `'delete'`. Shown on the trailing edge written for the * platform: `⌘K` on an Apple one, `Ctrl+K` elsewhere. * * The menu draws it and nothing more. Binding is yours, because only the app * knows what else is listening and whether the shortcut should work at all * times or only while the menu is open. `menuHotkeys` turns these entries * into a `useHotkeys` map, so the one spelling covers both ends. */ shortcut?: string; /** Extra search terms for `CommandPalette`, which also matches a string `label`. `Menu` ignores them. */ keywords?: string[]; disabled?: boolean; /** Renders in the destructive colour. For deleting, discarding, revoking. */ danger?: boolean; /** * Followed after `onClick` and `onAction`, through `ConfigProvider`'s `navigate` when it is set. * In `Menu` a real ``, so Ctrl/⌘-click opens a new tab. */ href?: string; onClick?: () => void; } /** A line between groups of actions. */ export interface MenuSeparator { separator: true; } /** A label over the actions that follow it. */ export interface MenuHeading { heading: ReactNode; } export type MenuEntry = MenuAction | MenuSeparator | MenuHeading; export declare function isMenuSeparator(entry: MenuEntry): entry is MenuSeparator; export declare function isMenuHeading(entry: MenuEntry): entry is MenuHeading; export declare function isMenuAction(entry: MenuEntry): entry is MenuAction; export type MenuSlots = 'root' | 'trigger' | 'menu' | 'item' | 'itemIcon' | 'itemLabel' | 'itemShortcut' | 'separator' | 'heading'; export interface MenuProps extends Omit { /** What the menu offers, in the order it is read. */ items: MenuEntry[]; /** The element that opens the menu. */ children?: ReactNode; /** Called with the id of the action that was picked, after its own `onClick`. */ onAction?: (id: string) => void; /** Controlled open state. Leave it out to let the menu manage its own. */ isOpen?: boolean; onOpenChange?: (isOpen: boolean) => void; /** Which side of the trigger the menu opens on (default `Bottom`). */ placement?: PopoverPlacement; /** Which edge it lines up with on the cross axis (default `Start`). */ align?: PopoverAlign; /** Anchored to the trigger, pinned to the bottom of the screen, or the latter only on touch. */ presentation?: Presentation; className?: string; style?: CSSProperties; classNames?: SlotClassNames; styles?: SlotStyles; }