1 | "use strict";
|
2 |
|
3 | var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
4 |
|
5 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
6 |
|
7 | Object.defineProperty(exports, "__esModule", {
|
8 | value: true
|
9 | });
|
10 | exports.default = exports.styles = void 0;
|
11 |
|
12 | var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
13 |
|
14 | var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
15 |
|
16 | var React = _interopRequireWildcard(require("react"));
|
17 |
|
18 | var _reactIs = require("react-is");
|
19 |
|
20 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
21 |
|
22 | var _clsx = _interopRequireDefault(require("clsx"));
|
23 |
|
24 | var _utils = require("@material-ui/utils");
|
25 |
|
26 | var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
|
27 |
|
28 | var _Popover = _interopRequireDefault(require("../Popover"));
|
29 |
|
30 | var _MenuList = _interopRequireDefault(require("../MenuList"));
|
31 |
|
32 | var ReactDOM = _interopRequireWildcard(require("react-dom"));
|
33 |
|
34 | var _setRef = _interopRequireDefault(require("../utils/setRef"));
|
35 |
|
36 | var _useTheme = _interopRequireDefault(require("../styles/useTheme"));
|
37 |
|
38 | var _deprecatedPropType = _interopRequireDefault(require("../utils/deprecatedPropType"));
|
39 |
|
40 | var RTL_ORIGIN = {
|
41 | vertical: 'top',
|
42 | horizontal: 'right'
|
43 | };
|
44 | var LTR_ORIGIN = {
|
45 | vertical: 'top',
|
46 | horizontal: 'left'
|
47 | };
|
48 | var styles = {
|
49 |
|
50 | paper: {
|
51 |
|
52 |
|
53 |
|
54 | maxHeight: 'calc(100% - 96px)',
|
55 |
|
56 | WebkitOverflowScrolling: 'touch'
|
57 | },
|
58 |
|
59 |
|
60 | list: {
|
61 |
|
62 | outline: 0
|
63 | }
|
64 | };
|
65 | exports.styles = styles;
|
66 | var Menu = React.forwardRef(function Menu(props, ref) {
|
67 | var _props$autoFocus = props.autoFocus,
|
68 | autoFocus = _props$autoFocus === void 0 ? true : _props$autoFocus,
|
69 | children = props.children,
|
70 | classes = props.classes,
|
71 | _props$disableAutoFoc = props.disableAutoFocusItem,
|
72 | disableAutoFocusItem = _props$disableAutoFoc === void 0 ? false : _props$disableAutoFoc,
|
73 | _props$MenuListProps = props.MenuListProps,
|
74 | MenuListProps = _props$MenuListProps === void 0 ? {} : _props$MenuListProps,
|
75 | onClose = props.onClose,
|
76 | onEnteringProp = props.onEntering,
|
77 | open = props.open,
|
78 | _props$PaperProps = props.PaperProps,
|
79 | PaperProps = _props$PaperProps === void 0 ? {} : _props$PaperProps,
|
80 | PopoverClasses = props.PopoverClasses,
|
81 | _props$transitionDura = props.transitionDuration,
|
82 | transitionDuration = _props$transitionDura === void 0 ? 'auto' : _props$transitionDura,
|
83 | _props$TransitionProp = props.TransitionProps;
|
84 | _props$TransitionProp = _props$TransitionProp === void 0 ? {} : _props$TransitionProp;
|
85 | var onEntering = _props$TransitionProp.onEntering,
|
86 | TransitionProps = (0, _objectWithoutProperties2.default)(_props$TransitionProp, ["onEntering"]),
|
87 | _props$variant = props.variant,
|
88 | variant = _props$variant === void 0 ? 'selectedMenu' : _props$variant,
|
89 | other = (0, _objectWithoutProperties2.default)(props, ["autoFocus", "children", "classes", "disableAutoFocusItem", "MenuListProps", "onClose", "onEntering", "open", "PaperProps", "PopoverClasses", "transitionDuration", "TransitionProps", "variant"]);
|
90 | var theme = (0, _useTheme.default)();
|
91 | var autoFocusItem = autoFocus && !disableAutoFocusItem && open;
|
92 | var menuListActionsRef = React.useRef(null);
|
93 | var contentAnchorRef = React.useRef(null);
|
94 |
|
95 | var getContentAnchorEl = function getContentAnchorEl() {
|
96 | return contentAnchorRef.current;
|
97 | };
|
98 |
|
99 | var handleEntering = function handleEntering(element, isAppearing) {
|
100 | if (menuListActionsRef.current) {
|
101 | menuListActionsRef.current.adjustStyleForScrollbar(element, theme);
|
102 | }
|
103 |
|
104 | if (onEnteringProp) {
|
105 | onEnteringProp(element, isAppearing);
|
106 | }
|
107 |
|
108 | if (onEntering) {
|
109 | onEntering(element, isAppearing);
|
110 | }
|
111 | };
|
112 |
|
113 | var handleListKeyDown = function handleListKeyDown(event) {
|
114 | if (event.key === 'Tab') {
|
115 | event.preventDefault();
|
116 |
|
117 | if (onClose) {
|
118 | onClose(event, 'tabKeyDown');
|
119 | }
|
120 | }
|
121 | };
|
122 | |
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 | var activeItemIndex = -1;
|
130 |
|
131 |
|
132 |
|
133 | React.Children.map(children, function (child, index) {
|
134 | if (! React.isValidElement(child)) {
|
135 | return;
|
136 | }
|
137 |
|
138 | if (process.env.NODE_ENV !== 'production') {
|
139 | if ((0, _reactIs.isFragment)(child)) {
|
140 | console.error(["Material-UI: The Menu component doesn't accept a Fragment as a child.", 'Consider providing an array instead.'].join('\n'));
|
141 | }
|
142 | }
|
143 |
|
144 | if (!child.props.disabled) {
|
145 | if (variant !== "menu" && child.props.selected) {
|
146 | activeItemIndex = index;
|
147 | } else if (activeItemIndex === -1) {
|
148 | activeItemIndex = index;
|
149 | }
|
150 | }
|
151 | });
|
152 | var items = React.Children.map(children, function (child, index) {
|
153 | if (index === activeItemIndex) {
|
154 | return React.cloneElement(child, {
|
155 | ref: function ref(instance) {
|
156 |
|
157 | contentAnchorRef.current = ReactDOM.findDOMNode(instance);
|
158 | (0, _setRef.default)(child.ref, instance);
|
159 | }
|
160 | });
|
161 | }
|
162 |
|
163 | return child;
|
164 | });
|
165 | return React.createElement(_Popover.default, (0, _extends2.default)({
|
166 | getContentAnchorEl: getContentAnchorEl,
|
167 | classes: PopoverClasses,
|
168 | onClose: onClose,
|
169 | TransitionProps: (0, _extends2.default)({
|
170 | onEntering: handleEntering
|
171 | }, TransitionProps),
|
172 | anchorOrigin: theme.direction === 'rtl' ? RTL_ORIGIN : LTR_ORIGIN,
|
173 | transformOrigin: theme.direction === 'rtl' ? RTL_ORIGIN : LTR_ORIGIN,
|
174 | PaperProps: (0, _extends2.default)({}, PaperProps, {
|
175 | classes: (0, _extends2.default)({}, PaperProps.classes, {
|
176 | root: classes.paper
|
177 | })
|
178 | }),
|
179 | open: open,
|
180 | ref: ref,
|
181 | transitionDuration: transitionDuration
|
182 | }, other), React.createElement(_MenuList.default, (0, _extends2.default)({
|
183 | onKeyDown: handleListKeyDown,
|
184 | actions: menuListActionsRef,
|
185 | autoFocus: autoFocus && (activeItemIndex === -1 || disableAutoFocusItem),
|
186 | autoFocusItem: autoFocusItem,
|
187 | variant: variant
|
188 | }, MenuListProps, {
|
189 | className: (0, _clsx.default)(classes.list, MenuListProps.className)
|
190 | }), items));
|
191 | });
|
192 | process.env.NODE_ENV !== "production" ? Menu.propTypes = {
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 | |
199 |
|
200 |
|
201 |
|
202 | anchorEl: _propTypes.default
|
203 |
|
204 | .oneOfType([_utils.HTMLElementType, _propTypes.default.func]),
|
205 |
|
206 | |
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 | autoFocus: _propTypes.default.bool,
|
213 |
|
214 | |
215 |
|
216 |
|
217 | children: _propTypes.default.node,
|
218 |
|
219 | |
220 |
|
221 |
|
222 |
|
223 | classes: _propTypes.default.object,
|
224 |
|
225 | |
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 | disableAutoFocusItem: _propTypes.default.bool,
|
232 |
|
233 | |
234 |
|
235 |
|
236 | MenuListProps: _propTypes.default.object,
|
237 |
|
238 | |
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 | onClose: _propTypes.default.func,
|
245 |
|
246 | |
247 |
|
248 |
|
249 |
|
250 | onEnter: (0, _deprecatedPropType.default)(_propTypes.default.func, 'Use the `TransitionProps` prop instead.'),
|
251 |
|
252 | |
253 |
|
254 |
|
255 |
|
256 | onEntered: (0, _deprecatedPropType.default)(_propTypes.default.func, 'Use the `TransitionProps` prop instead.'),
|
257 |
|
258 | |
259 |
|
260 |
|
261 |
|
262 | onEntering: (0, _deprecatedPropType.default)(_propTypes.default.func, 'Use the `TransitionProps` prop instead.'),
|
263 |
|
264 | |
265 |
|
266 |
|
267 |
|
268 | onExit: (0, _deprecatedPropType.default)(_propTypes.default.func, 'Use the `TransitionProps` prop instead.'),
|
269 |
|
270 | |
271 |
|
272 |
|
273 |
|
274 | onExited: (0, _deprecatedPropType.default)(_propTypes.default.func, 'Use the `TransitionProps` prop instead.'),
|
275 |
|
276 | |
277 |
|
278 |
|
279 |
|
280 | onExiting: (0, _deprecatedPropType.default)(_propTypes.default.func, 'Use the `TransitionProps` prop instead.'),
|
281 |
|
282 | |
283 |
|
284 |
|
285 | open: _propTypes.default.bool.isRequired,
|
286 |
|
287 | |
288 |
|
289 |
|
290 | PaperProps: _propTypes.default.object,
|
291 |
|
292 | |
293 |
|
294 |
|
295 | PopoverClasses: _propTypes.default.object,
|
296 |
|
297 | |
298 |
|
299 |
|
300 | transitionDuration: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.number, _propTypes.default.shape({
|
301 | appear: _propTypes.default.number,
|
302 | enter: _propTypes.default.number,
|
303 | exit: _propTypes.default.number
|
304 | })]),
|
305 |
|
306 | |
307 |
|
308 |
|
309 |
|
310 | TransitionProps: _propTypes.default.object,
|
311 |
|
312 | |
313 |
|
314 |
|
315 |
|
316 | variant: _propTypes.default.oneOf(['menu', 'selectedMenu'])
|
317 | } : void 0;
|
318 |
|
319 | var _default = (0, _withStyles.default)(styles, {
|
320 | name: 'MuiMenu'
|
321 | })(Menu);
|
322 |
|
323 | exports.default = _default; |
\ | No newline at end of file |