1 | 'use client';
|
2 |
|
3 | import _extends from "@babel/runtime/helpers/esm/extends";
|
4 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
5 | const _excluded = ["actions", "anchor", "children", "onItemsChange", "slotProps", "slots"];
|
6 | import * as React from 'react';
|
7 | import PropTypes from 'prop-types';
|
8 | import { HTMLElementType, refType } from '@mui/utils';
|
9 | import { getMenuUtilityClass } from './menuClasses';
|
10 | import { useMenu } from '../useMenu';
|
11 | import { MenuProvider } from '../useMenu/MenuProvider';
|
12 | import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
13 | import { Unstable_Popup as Popup } from '../Unstable_Popup';
|
14 | import { useSlotProps } from '../utils/useSlotProps';
|
15 | import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
16 | import { ListActionTypes } from '../useList';
|
17 | import { jsx as _jsx } from "react/jsx-runtime";
|
18 | function useUtilityClasses(ownerState) {
|
19 | const {
|
20 | open
|
21 | } = ownerState;
|
22 | const slots = {
|
23 | root: ['root', open && 'expanded'],
|
24 | listbox: ['listbox', open && 'expanded']
|
25 | };
|
26 | return composeClasses(slots, useClassNamesOverride(getMenuUtilityClass));
|
27 | }
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | const Menu = React.forwardRef(function Menu(props, forwardedRef) {
|
40 | var _slots$root, _slots$listbox;
|
41 | const {
|
42 | actions,
|
43 | anchor: anchorProp,
|
44 | children,
|
45 | onItemsChange,
|
46 | slotProps = {},
|
47 | slots = {}
|
48 | } = props,
|
49 | other = _objectWithoutPropertiesLoose(props, _excluded);
|
50 | const {
|
51 | contextValue,
|
52 | getListboxProps,
|
53 | dispatch,
|
54 | open,
|
55 | triggerElement
|
56 | } = useMenu({
|
57 | onItemsChange,
|
58 | componentName: 'Menu'
|
59 | });
|
60 | const anchor = anchorProp != null ? anchorProp : triggerElement;
|
61 | React.useImperativeHandle(actions, () => ({
|
62 | dispatch,
|
63 | resetHighlight: () => dispatch({
|
64 | type: ListActionTypes.resetHighlight,
|
65 | event: null
|
66 | })
|
67 | }), [dispatch]);
|
68 | const ownerState = _extends({}, props, {
|
69 | open
|
70 | });
|
71 | const classes = useUtilityClasses(ownerState);
|
72 | const Root = (_slots$root = slots.root) != null ? _slots$root : 'div';
|
73 | const rootProps = useSlotProps({
|
74 | elementType: Root,
|
75 | externalSlotProps: slotProps.root,
|
76 | externalForwardedProps: other,
|
77 | additionalProps: {
|
78 | ref: forwardedRef,
|
79 | role: undefined
|
80 | },
|
81 | className: classes.root,
|
82 | ownerState
|
83 | });
|
84 | const Listbox = (_slots$listbox = slots.listbox) != null ? _slots$listbox : 'ul';
|
85 | const listboxProps = useSlotProps({
|
86 | elementType: Listbox,
|
87 | getSlotProps: getListboxProps,
|
88 | externalSlotProps: slotProps.listbox,
|
89 | className: classes.listbox,
|
90 | ownerState
|
91 | });
|
92 | if (open === true && anchor == null) {
|
93 | return _jsx(Root, _extends({}, rootProps, {
|
94 | children: _jsx(Listbox, _extends({}, listboxProps, {
|
95 | children: _jsx(MenuProvider, {
|
96 | value: contextValue,
|
97 | children: children
|
98 | })
|
99 | }))
|
100 | }));
|
101 | }
|
102 | return _jsx(Popup, _extends({
|
103 | keepMounted: true
|
104 | }, rootProps, {
|
105 | open: open,
|
106 | anchor: anchor,
|
107 | slots: {
|
108 | root: Root
|
109 | },
|
110 | children: _jsx(Listbox, _extends({}, listboxProps, {
|
111 | children: _jsx(MenuProvider, {
|
112 | value: contextValue,
|
113 | children: children
|
114 | })
|
115 | }))
|
116 | }));
|
117 | });
|
118 | process.env.NODE_ENV !== "production" ? Menu.propTypes = {
|
119 |
|
120 |
|
121 |
|
122 |
|
123 | |
124 |
|
125 |
|
126 | actions: refType,
|
127 | |
128 |
|
129 |
|
130 | anchor: PropTypes .oneOfType([HTMLElementType, PropTypes.object, PropTypes.func]),
|
131 | |
132 |
|
133 |
|
134 | children: PropTypes.node,
|
135 | |
136 |
|
137 |
|
138 | className: PropTypes.string,
|
139 | |
140 |
|
141 |
|
142 | onItemsChange: PropTypes.func,
|
143 | |
144 |
|
145 |
|
146 |
|
147 | slotProps: PropTypes.shape({
|
148 | listbox: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
149 | root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
150 | }),
|
151 | |
152 |
|
153 |
|
154 |
|
155 |
|
156 | slots: PropTypes.shape({
|
157 | listbox: PropTypes.elementType,
|
158 | root: PropTypes.elementType
|
159 | })
|
160 | } : void 0;
|
161 | export { Menu }; |
\ | No newline at end of file |