UNPKG

2.6 kBTypeScriptView Raw
1import * as React from 'react';
2import { Simplify } from '@mui/types';
3import { PolymorphicProps, SlotComponentProps } from '../utils';
4import { UseMenuListboxSlotProps } from '../useMenu';
5import { ListAction } from '../useList';
6import { PopupProps } from '../Unstable_Popup';
7export interface MenuRootSlotPropsOverrides {
8}
9export interface MenuListboxSlotPropsOverrides {
10}
11export interface MenuActions {
12 /**
13 * Dispatches an action that can cause a change to the menu's internal state.
14 */
15 dispatch: (action: ListAction<string>) => void;
16 /**
17 * Resets the highlighted item.
18 */
19 resetHighlight: () => void;
20}
21export interface MenuOwnProps {
22 /**
23 * A ref with imperative actions that can be performed on the menu.
24 */
25 actions?: React.Ref<MenuActions>;
26 /**
27 * The element based on which the menu is positioned.
28 */
29 anchor?: PopupProps['anchor'];
30 children?: React.ReactNode;
31 className?: string;
32 /**
33 * Function called when the items displayed in the menu change.
34 */
35 onItemsChange?: (items: string[]) => void;
36 /**
37 * The props used for each slot inside the Menu.
38 * @default {}
39 */
40 slotProps?: {
41 root?: SlotComponentProps<'div', MenuRootSlotPropsOverrides & PopupProps, MenuOwnerState>;
42 listbox?: SlotComponentProps<'ul', MenuListboxSlotPropsOverrides, MenuOwnerState>;
43 };
44 /**
45 * The components used for each slot inside the Menu.
46 * Either a string to use a HTML element or a component.
47 * @default {}
48 */
49 slots?: MenuSlots;
50}
51export interface MenuSlots {
52 /**
53 * The component that renders the popup element.
54 * @default 'div'
55 */
56 root?: React.ElementType;
57 /**
58 * The component that renders the listbox.
59 * @default 'ul'
60 */
61 listbox?: React.ElementType;
62}
63export interface MenuTypeMap<AdditionalProps = {}, RootComponentType extends React.ElementType = 'div'> {
64 props: MenuOwnProps & AdditionalProps;
65 defaultComponent: RootComponentType;
66}
67export type MenuProps<RootComponentType extends React.ElementType = MenuTypeMap['defaultComponent']> = PolymorphicProps<MenuTypeMap<{}, RootComponentType>, RootComponentType>;
68export type MenuOwnerState = Simplify<MenuOwnProps & {
69 open: boolean;
70}>;
71export type MenuRootSlotProps = {
72 children?: React.ReactNode;
73 className?: string;
74 ownerState: MenuOwnerState;
75 ref: React.Ref<any>;
76};
77export type MenuListboxSlotProps = UseMenuListboxSlotProps & {
78 children?: React.ReactNode;
79 className?: string;
80 ownerState: MenuOwnerState;
81};