1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 | Object.defineProperty(exports, "__esModule", {
|
5 | value: true
|
6 | });
|
7 | exports.default = void 0;
|
8 | var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
9 | var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
10 | var React = _interopRequireWildcard(require("react"));
|
11 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
12 | var _utils = require("@mui/utils");
|
13 | var _menuClasses = require("./menuClasses");
|
14 | var _useMenu = _interopRequireDefault(require("../useMenu"));
|
15 | var _composeClasses = _interopRequireDefault(require("../composeClasses"));
|
16 | var _Popper = _interopRequireDefault(require("../Popper"));
|
17 | var _useSlotProps = _interopRequireDefault(require("../utils/useSlotProps"));
|
18 | var _ClassNameConfigurator = require("../utils/ClassNameConfigurator");
|
19 | var _MenuProvider = _interopRequireDefault(require("../useMenu/MenuProvider"));
|
20 | var _jsxRuntime = require("react/jsx-runtime");
|
21 | const _excluded = ["actions", "anchorEl", "children", "defaultOpen", "listboxId", "onOpenChange", "open", "slotProps", "slots"];
|
22 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
23 | function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
24 | function useUtilityClasses(ownerState) {
|
25 | const {
|
26 | open
|
27 | } = ownerState;
|
28 | const slots = {
|
29 | root: ['root', open && 'expanded'],
|
30 | listbox: ['listbox', open && 'expanded']
|
31 | };
|
32 | return (0, _composeClasses.default)(slots, (0, _ClassNameConfigurator.useClassNamesOverride)(_menuClasses.getMenuUtilityClass));
|
33 | }
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | const Menu = React.forwardRef(function Menu(props, forwardedRef) {
|
45 | var _slots$root, _slots$listbox;
|
46 | const {
|
47 | actions,
|
48 | anchorEl,
|
49 | children,
|
50 | defaultOpen,
|
51 | listboxId,
|
52 | onOpenChange,
|
53 | open: openProp,
|
54 | slotProps = {},
|
55 | slots = {}
|
56 | } = props,
|
57 | other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
58 | const {
|
59 | contextValue,
|
60 | getListboxProps,
|
61 | dispatch,
|
62 | open
|
63 | } = (0, _useMenu.default)({
|
64 | defaultOpen,
|
65 | open: openProp,
|
66 | onOpenChange,
|
67 | listboxId
|
68 | });
|
69 | React.useImperativeHandle(actions, () => ({
|
70 | dispatch
|
71 | }), [dispatch]);
|
72 | const ownerState = (0, _extends2.default)({}, props, {
|
73 | open
|
74 | });
|
75 | const classes = useUtilityClasses(ownerState);
|
76 | const Root = (_slots$root = slots.root) != null ? _slots$root : _Popper.default;
|
77 | const rootProps = (0, _useSlotProps.default)({
|
78 | elementType: Root,
|
79 | externalForwardedProps: other,
|
80 | externalSlotProps: slotProps.root,
|
81 | additionalProps: {
|
82 | anchorEl,
|
83 | open,
|
84 | keepMounted: true,
|
85 | role: undefined,
|
86 | ref: forwardedRef
|
87 | },
|
88 | className: classes.root,
|
89 | ownerState
|
90 | });
|
91 | const Listbox = (_slots$listbox = slots.listbox) != null ? _slots$listbox : 'ul';
|
92 | const listboxProps = (0, _useSlotProps.default)({
|
93 | elementType: Listbox,
|
94 | getSlotProps: getListboxProps,
|
95 | externalSlotProps: slotProps.listbox,
|
96 | ownerState,
|
97 | className: classes.listbox
|
98 | });
|
99 | return (0, _jsxRuntime.jsx)(Root, (0, _extends2.default)({}, rootProps, {
|
100 | children: (0, _jsxRuntime.jsx)(Listbox, (0, _extends2.default)({}, listboxProps, {
|
101 | children: (0, _jsxRuntime.jsx)(_MenuProvider.default, {
|
102 | value: contextValue,
|
103 | children: children
|
104 | })
|
105 | }))
|
106 | }));
|
107 | });
|
108 | process.env.NODE_ENV !== "production" ? Menu.propTypes = {
|
109 |
|
110 |
|
111 |
|
112 |
|
113 | |
114 |
|
115 |
|
116 |
|
117 | actions: _utils.refType,
|
118 | |
119 |
|
120 |
|
121 |
|
122 |
|
123 | anchorEl: _propTypes.default .oneOfType([_utils.HTMLElementType, _propTypes.default.object, _propTypes.default.func]),
|
124 | |
125 |
|
126 |
|
127 | children: _propTypes.default.node,
|
128 | |
129 |
|
130 |
|
131 | defaultOpen: _propTypes.default.bool,
|
132 | |
133 |
|
134 |
|
135 | listboxId: _propTypes.default.string,
|
136 | |
137 |
|
138 |
|
139 | onOpenChange: _propTypes.default.func,
|
140 | |
141 |
|
142 |
|
143 |
|
144 | open: _propTypes.default.bool,
|
145 | |
146 |
|
147 |
|
148 |
|
149 | slotProps: _propTypes.default .shape({
|
150 | listbox: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object]),
|
151 | root: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object])
|
152 | }),
|
153 | |
154 |
|
155 |
|
156 |
|
157 |
|
158 | slots: _propTypes.default.shape({
|
159 | listbox: _propTypes.default.elementType,
|
160 | root: _propTypes.default.elementType
|
161 | })
|
162 | } : void 0;
|
163 | var _default = Menu;
|
164 | exports.default = _default; |
\ | No newline at end of file |