import { type ComponentProps, type KeyboardEvent, type MouseEvent, type ReactElement, type ReactNode, type RefObject } from 'react'; import type { Placement } from '../core/position.js'; /** * Unstyled Carbon `Menu` (APG menu and menu button), the behaviour of the styled Menu without a * single class, in Base UI's parts. A `Trigger` opens a `Popup` (`role="menu"`) in the top layer * beside it: a click or Enter / Space on the first item, ↓ on the first, ↑ on the last. In the menu * ↑ / ↓ wrap past disabled items, Home / End jump, letters jump (typeahead); Esc or Tab close and * give focus back, so do picking an item, a press outside and focus leaving. A `SubmenuTrigger` * (inside a `SubmenuRoot`, its `Popup` inside it) opens a submenu beside it on hover (no focus * moves), a click, Enter, Space or → (← right-to-left); ← or Esc close just that level. * * State shows as data attributes to style on: `data-popup-open` on `Trigger` and `SubmenuTrigger`, * `data-open` and `data-side` on `Popup`, `data-disabled` on items, `data-checked` on checked * `CheckboxItem`s and `RadioItem`s. The focused item is the highlighted one (style it with `:focus`). * * ```tsx * * Actions * * Edit * Bold * * * ShareEmail * * * * ``` */ export type MenuFocus = 'first' | 'last' | 'none'; /** Why the menu opened or closed (Base UI's reasons). */ export type OpenChangeReason = 'trigger-press' | 'trigger-hover' | 'item-press' | 'escape-key' | 'list-navigation' | 'focus-out' | 'outside-press'; export interface RootProps { open?: boolean; defaultOpen?: boolean; /** After the menu opened or closed (only on a change), with why. */ onOpenChange?: (open: boolean, reason: OpenChangeReason) => void; /** Which item takes focus on open (`none`: none, as a submenu opened by hover); left out, the trigger decides (↑: the last, else the first). */ initialFocus?: MenuFocus; /** Base of the parts' ids (`-trigger`, `-menu`); generated when left out. */ id?: string; children?: ReactNode; } interface MenuContextValue { id: string; /** The popup's id (a `Trigger`'s `aria-controls`). */ popupId: string; open: boolean; initialFocus: MenuFocus; /** A submenu: placed beside its trigger; ← and Esc close only it. */ submenu: boolean; trigger: RefObject; popup: RefObject; /** The mounted trigger's id (it names the popup), undefined without one. */ triggerId: string | undefined; registerTrigger: (id: string) => () => void; setOpen: (open: boolean, reason: OpenChangeReason, focus?: MenuFocus) => void; /** Close every level (an item was picked). */ closeAll: () => void; } /** The state of the nearest `Menu.Root` or `Menu.SubmenuRoot` (open …), e.g. to turn a chevron. */ export declare function useMenuContext(part?: string): MenuContextValue; /** Holds the open state; renders only its children. */ export declare function Root({ children, ...props }: Readonly): import("react").JSX.Element; /** A submenu's state, inside the parent's `Popup`: holds a `SubmenuTrigger`, which holds the submenu's `Popup`. */ export declare function SubmenuRoot({ children, ...props }: Readonly): import("react").JSX.Element; /** The menu's own items (not those of its submenus), in order. */ export declare const ownItems: (popup: Element) => HTMLElement[]; export type TriggerRenderProps = ComponentProps<'button'> & { 'data-popup-open'?: string; }; export interface TriggerProps extends ComponentProps<'button'> { /** Render your own button with these props (and the open state), e.g. a styled one. */ render?: (props: TriggerRenderProps, state: { open: boolean; }) => ReactElement; } /** The button that opens the menu (`aria-haspopup="menu"` unless you give another). */ export declare function Trigger({ render, ref, ...rest }: Readonly): import("react").JSX.Element; export interface PopupProps extends Omit, 'role'> { /** What the menu sits beside (default: the trigger); a submenu sits beside its `SubmenuTrigger`. */ anchor?: RefObject; /** Where it opens beside the anchor (not a submenu: that opens to the inline end). */ placement?: Placement; /** As wide as the anchor (not a submenu). */ matchWidth?: boolean; } /** * The menu (`role="menu"`) in the top layer beside its anchor; its items are always rendered (hidden * while closed). Opening focuses the first item (or the last, or none); closing gives focus back. */ export declare function Popup({ anchor, placement, matchWidth, ref, ...rest }: Readonly): import("react").JSX.Element; /** The state of the enclosing item (`checked` of a `CheckboxItem` or `RadioItem`), e.g. to draw a check mark. */ export declare const useMenuItemContext: () => { checked: boolean; }; export interface ItemProps extends Omit, 'onClick' | 'role'> { /** The text typeahead matches (default: the item's text), as `data-label`. */ label?: string; /** Stays visible and announced; the keys skip it, activating it does nothing. */ disabled?: boolean; /** Runs on a click and on Enter / Space (not on a disabled item), before the menu closes. */ onClick?: (event: MouseEvent | KeyboardEvent) => void; /** Activating it closes every level of the menu (default, as Carbon). */ closeOnClick?: boolean; } /** An action (`role="menuitem"`). */ export declare function Item(props: Readonly): import("react").JSX.Element; export interface CheckboxItemProps extends ItemProps { checked?: boolean; defaultChecked?: boolean; onCheckedChange?: (checked: boolean) => void; } /** An on / off item (`role="menuitemcheckbox"`, `data-checked`). */ export declare function CheckboxItem({ checked, defaultChecked, onCheckedChange, ...rest }: Readonly): import("react").JSX.Element; /** Items under a caption (`role="group"`, named by its `GroupLabel` unless you give it a name). */ export declare function Group({ children, ...rest }: Readonly, 'role'>>): import("react").JSX.Element; /** The caption of a `Group` or `RadioGroup`. */ export declare function GroupLabel({ id, ...rest }: Readonly>): import("react").JSX.Element; export interface RadioGroupProps extends Omit, 'role' | 'defaultValue' | 'onChange'> { value?: string; defaultValue?: string; /** After another `RadioItem` was picked. */ onValueChange?: (value: string) => void; } /** A `Group` of `RadioItem`s, exactly one of them checked. */ export declare function RadioGroup({ value, defaultValue, onValueChange, ...rest }: Readonly): import("react").JSX.Element; export interface RadioItemProps extends ItemProps { /** What it stands for in its `RadioGroup`. */ value: string; } /** One choice of a `RadioGroup` (`role="menuitemradio"`, `data-checked`). */ export declare function RadioItem({ value, ...rest }: Readonly): import("react").JSX.Element; /** A line between items (`
`, a separator in the menu). */ export declare function Separator(props: Readonly>): import("react").JSX.Element; export interface SubmenuTriggerProps extends Omit, 'role'> { /** The text typeahead matches (default: the item's text), as `data-label`. */ label?: string; disabled?: boolean; /** Hover intent in ms before the submenu opens or closes (Carbon 150). */ delay?: number; } /** * The item of the parent menu that opens a submenu (`aria-haspopup="menu"`, `data-popup-open`); * the submenu's `Popup` goes inside it. Hover opens it without moving focus; leaving closes it * unless focus is in it. */ export declare function SubmenuTrigger({ label, disabled, delay, ref, ...rest }: Readonly): import("react").JSX.Element; export {};