1 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
2 | import _extends from "@babel/runtime/helpers/esm/extends";
|
3 | const _excluded = ["autoFocus", "component", "dense", "divider", "disableGutters", "focusVisibleClassName", "role", "tabIndex"];
|
4 | import * as React from 'react';
|
5 | import PropTypes from 'prop-types';
|
6 | import clsx from 'clsx';
|
7 | import { unstable_composeClasses as composeClasses } from '@mui/base';
|
8 | import { alpha } from '@mui/system';
|
9 | import styled, { rootShouldForwardProp } from '../styles/styled';
|
10 | import useThemeProps from '../styles/useThemeProps';
|
11 | import ListContext from '../List/ListContext';
|
12 | import ButtonBase from '../ButtonBase';
|
13 | import useEnhancedEffect from '../utils/useEnhancedEffect';
|
14 | import useForkRef from '../utils/useForkRef';
|
15 | import { dividerClasses } from '../Divider';
|
16 | import { listItemIconClasses } from '../ListItemIcon';
|
17 | import { listItemTextClasses } from '../ListItemText';
|
18 | import menuItemClasses, { getMenuItemUtilityClass } from './menuItemClasses';
|
19 | import { jsx as _jsx } from "react/jsx-runtime";
|
20 | export const overridesResolver = (props, styles) => {
|
21 | const {
|
22 | ownerState
|
23 | } = props;
|
24 | return [styles.root, ownerState.dense && styles.dense, ownerState.divider && styles.divider, !ownerState.disableGutters && styles.gutters];
|
25 | };
|
26 |
|
27 | const useUtilityClasses = ownerState => {
|
28 | const {
|
29 | disabled,
|
30 | dense,
|
31 | divider,
|
32 | disableGutters,
|
33 | selected,
|
34 | classes
|
35 | } = ownerState;
|
36 | const slots = {
|
37 | root: ['root', dense && 'dense', disabled && 'disabled', !disableGutters && 'gutters', divider && 'divider', selected && 'selected']
|
38 | };
|
39 | const composedClasses = composeClasses(slots, getMenuItemUtilityClass, classes);
|
40 | return _extends({}, classes, composedClasses);
|
41 | };
|
42 |
|
43 | const MenuItemRoot = styled(ButtonBase, {
|
44 | shouldForwardProp: prop => rootShouldForwardProp(prop) || prop === 'classes',
|
45 | name: 'MuiMenuItem',
|
46 | slot: 'Root',
|
47 | overridesResolver
|
48 | })(({
|
49 | theme,
|
50 | ownerState
|
51 | }) => _extends({}, theme.typography.body1, {
|
52 | display: 'flex',
|
53 | justifyContent: 'flex-start',
|
54 | alignItems: 'center',
|
55 | position: 'relative',
|
56 | textDecoration: 'none',
|
57 | minHeight: 48,
|
58 | paddingTop: 6,
|
59 | paddingBottom: 6,
|
60 | boxSizing: 'border-box',
|
61 | whiteSpace: 'nowrap'
|
62 | }, !ownerState.disableGutters && {
|
63 | paddingLeft: 16,
|
64 | paddingRight: 16
|
65 | }, ownerState.divider && {
|
66 | borderBottom: `1px solid ${(theme.vars || theme).palette.divider}`,
|
67 | backgroundClip: 'padding-box'
|
68 | }, {
|
69 | '&:hover': {
|
70 | textDecoration: 'none',
|
71 | backgroundColor: (theme.vars || theme).palette.action.hover,
|
72 |
|
73 | '@media (hover: none)': {
|
74 | backgroundColor: 'transparent'
|
75 | }
|
76 | },
|
77 | [`&.${menuItemClasses.selected}`]: {
|
78 | backgroundColor: theme.vars ? `rgba(${theme.vars.palette.primary.mainChannel} / ${theme.vars.palette.action.selectedOpacity})` : alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity),
|
79 | [`&.${menuItemClasses.focusVisible}`]: {
|
80 | backgroundColor: theme.vars ? `rgba(${theme.vars.palette.primary.mainChannel} / calc(${theme.vars.palette.action.selectedOpacity} + ${theme.vars.palette.action.focusOpacity}))` : alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity + theme.palette.action.focusOpacity)
|
81 | }
|
82 | },
|
83 | [`&.${menuItemClasses.selected}:hover`]: {
|
84 | backgroundColor: theme.vars ? `rgba(${theme.vars.palette.primary.mainChannel} / calc(${theme.vars.palette.action.selectedOpacity} + ${theme.vars.palette.action.hoverOpacity}))` : alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity + theme.palette.action.hoverOpacity),
|
85 |
|
86 | '@media (hover: none)': {
|
87 | backgroundColor: theme.vars ? `rgba(${theme.vars.palette.primary.mainChannel} / ${theme.vars.palette.action.selectedOpacity})` : alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity)
|
88 | }
|
89 | },
|
90 | [`&.${menuItemClasses.focusVisible}`]: {
|
91 | backgroundColor: (theme.vars || theme).palette.action.focus
|
92 | },
|
93 | [`&.${menuItemClasses.disabled}`]: {
|
94 | opacity: (theme.vars || theme).palette.action.disabledOpacity
|
95 | },
|
96 | [`& + .${dividerClasses.root}`]: {
|
97 | marginTop: theme.spacing(1),
|
98 | marginBottom: theme.spacing(1)
|
99 | },
|
100 | [`& + .${dividerClasses.inset}`]: {
|
101 | marginLeft: 52
|
102 | },
|
103 | [`& .${listItemTextClasses.root}`]: {
|
104 | marginTop: 0,
|
105 | marginBottom: 0
|
106 | },
|
107 | [`& .${listItemTextClasses.inset}`]: {
|
108 | paddingLeft: 36
|
109 | },
|
110 | [`& .${listItemIconClasses.root}`]: {
|
111 | minWidth: 36
|
112 | }
|
113 | }, !ownerState.dense && {
|
114 | [theme.breakpoints.up('sm')]: {
|
115 | minHeight: 'auto'
|
116 | }
|
117 | }, ownerState.dense && _extends({
|
118 | minHeight: 32,
|
119 |
|
120 | paddingTop: 4,
|
121 | paddingBottom: 4
|
122 | }, theme.typography.body2, {
|
123 | [`& .${listItemIconClasses.root} svg`]: {
|
124 | fontSize: '1.25rem'
|
125 | }
|
126 | })));
|
127 | const MenuItem = React.forwardRef(function MenuItem(inProps, ref) {
|
128 | const props = useThemeProps({
|
129 | props: inProps,
|
130 | name: 'MuiMenuItem'
|
131 | });
|
132 |
|
133 | const {
|
134 | autoFocus = false,
|
135 | component = 'li',
|
136 | dense = false,
|
137 | divider = false,
|
138 | disableGutters = false,
|
139 | focusVisibleClassName,
|
140 | role = 'menuitem',
|
141 | tabIndex: tabIndexProp
|
142 | } = props,
|
143 | other = _objectWithoutPropertiesLoose(props, _excluded);
|
144 |
|
145 | const context = React.useContext(ListContext);
|
146 | const childContext = {
|
147 | dense: dense || context.dense || false,
|
148 | disableGutters
|
149 | };
|
150 | const menuItemRef = React.useRef(null);
|
151 | useEnhancedEffect(() => {
|
152 | if (autoFocus) {
|
153 | if (menuItemRef.current) {
|
154 | menuItemRef.current.focus();
|
155 | } else if (process.env.NODE_ENV !== 'production') {
|
156 | console.error('MUI: Unable to set focus to a MenuItem whose component has not been rendered.');
|
157 | }
|
158 | }
|
159 | }, [autoFocus]);
|
160 |
|
161 | const ownerState = _extends({}, props, {
|
162 | dense: childContext.dense,
|
163 | divider,
|
164 | disableGutters
|
165 | });
|
166 |
|
167 | const classes = useUtilityClasses(props);
|
168 | const handleRef = useForkRef(menuItemRef, ref);
|
169 | let tabIndex;
|
170 |
|
171 | if (!props.disabled) {
|
172 | tabIndex = tabIndexProp !== undefined ? tabIndexProp : -1;
|
173 | }
|
174 |
|
175 | return _jsx(ListContext.Provider, {
|
176 | value: childContext,
|
177 | children: _jsx(MenuItemRoot, _extends({
|
178 | ref: handleRef,
|
179 | role: role,
|
180 | tabIndex: tabIndex,
|
181 | component: component,
|
182 | focusVisibleClassName: clsx(classes.focusVisible, focusVisibleClassName)
|
183 | }, other, {
|
184 | ownerState: ownerState,
|
185 | classes: classes
|
186 | }))
|
187 | });
|
188 | });
|
189 | process.env.NODE_ENV !== "production" ? MenuItem.propTypes
|
190 |
|
191 | = {
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 | |
198 |
|
199 |
|
200 |
|
201 |
|
202 | autoFocus: PropTypes.bool,
|
203 |
|
204 | |
205 |
|
206 |
|
207 | children: PropTypes.node,
|
208 |
|
209 | |
210 |
|
211 |
|
212 | classes: PropTypes.object,
|
213 |
|
214 | |
215 |
|
216 |
|
217 |
|
218 | component: PropTypes.elementType,
|
219 |
|
220 | |
221 |
|
222 |
|
223 |
|
224 |
|
225 | dense: PropTypes.bool,
|
226 |
|
227 | |
228 |
|
229 |
|
230 | disabled: PropTypes.bool,
|
231 |
|
232 | |
233 |
|
234 |
|
235 |
|
236 | disableGutters: PropTypes.bool,
|
237 |
|
238 | |
239 |
|
240 |
|
241 |
|
242 | divider: PropTypes.bool,
|
243 |
|
244 | |
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 | focusVisibleClassName: PropTypes.string,
|
253 |
|
254 | |
255 |
|
256 |
|
257 | role: PropTypes
|
258 |
|
259 | .string,
|
260 |
|
261 | |
262 |
|
263 |
|
264 | selected: PropTypes.bool,
|
265 |
|
266 | |
267 |
|
268 |
|
269 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
270 |
|
271 | |
272 |
|
273 |
|
274 | tabIndex: PropTypes.number
|
275 | } : void 0;
|
276 | export default MenuItem; |
\ | No newline at end of file |