UNPKG

2.8 kBTypeScriptView Raw
1import * as React from 'react';
2import { Simplify } from '@mui/types';
3import Popper, { PopperProps } from '../Popper';
4import { PolymorphicProps, SlotComponentProps } from '../utils';
5import { UseMenuListboxSlotProps } from '../useMenu';
6import { ListAction } from '../useList';
7export interface MenuRootSlotPropsOverrides {
8}
9export interface MenuListboxSlotPropsOverrides {
10}
11export interface MenuActions {
12 dispatch: (action: ListAction<string>) => void;
13}
14export interface MenuOwnProps {
15 /**
16 * A ref with imperative actions.
17 * It allows to select the first or last menu item.
18 */
19 actions?: React.Ref<MenuActions>;
20 /**
21 * An HTML element, [virtualElement](https://popper.js.org/docs/v2/virtual-elements/),
22 * or a function that returns either.
23 * It's used to set the position of the popper.
24 */
25 anchorEl?: PopperProps['anchorEl'];
26 children?: React.ReactNode;
27 className?: string;
28 defaultOpen?: boolean;
29 listboxId?: string;
30 /**
31 * Triggered when focus leaves the menu and the menu should close.
32 */
33 onOpenChange?: (open: boolean) => void;
34 /**
35 * Controls whether the menu is displayed.
36 * @default false
37 */
38 open?: boolean;
39 /**
40 * The props used for each slot inside the Menu.
41 * @default {}
42 */
43 slotProps?: {
44 root?: SlotComponentProps<typeof Popper, MenuRootSlotPropsOverrides, MenuOwnerState>;
45 listbox?: SlotComponentProps<'ul', MenuListboxSlotPropsOverrides, MenuOwnerState>;
46 };
47 /**
48 * The components used for each slot inside the Menu.
49 * Either a string to use a HTML element or a component.
50 * @default {}
51 */
52 slots?: MenuSlots;
53}
54export interface MenuSlots {
55 /**
56 * The component that renders the root.
57 * @default Popper
58 */
59 root?: React.ElementType;
60 /**
61 * The component that renders the listbox.
62 * @default 'ul'
63 */
64 listbox?: React.ElementType;
65}
66export interface MenuTypeMap<AdditionalProps = {}, RootComponentType extends React.ElementType = 'ul'> {
67 props: MenuOwnProps & AdditionalProps;
68 defaultComponent: RootComponentType;
69}
70export type MenuProps<RootComponentType extends React.ElementType = MenuTypeMap['defaultComponent']> = PolymorphicProps<MenuTypeMap<{}, RootComponentType>, RootComponentType>;
71export type MenuOwnerState = Simplify<MenuOwnProps & {
72 open: boolean;
73}>;
74export type MenuRootSlotProps = {
75 anchorEl: PopperProps['anchorEl'];
76 children?: React.ReactNode;
77 className?: string;
78 keepMounted: PopperProps['keepMounted'];
79 open: boolean;
80 ownerState: MenuOwnerState;
81 ref: React.Ref<any>;
82};
83export type MenuListboxSlotProps = UseMenuListboxSlotProps & {
84 className: string | undefined;
85 ownerState: MenuOwnerState;
86};