UNPKG

3.18 kBJavaScriptView Raw
1import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2import _extends from "@babel/runtime/helpers/esm/extends";
3import * as React from 'react';
4import PropTypes from 'prop-types';
5import clsx from 'clsx';
6import withStyles from '../styles/withStyles';
7import ListItem from '../ListItem';
8export const styles = theme => ({
9 /* Styles applied to the root element. */
10 root: _extends({}, theme.typography.body1, {
11 minHeight: 48,
12 paddingTop: 6,
13 paddingBottom: 6,
14 boxSizing: 'border-box',
15 width: 'auto',
16 overflow: 'hidden',
17 whiteSpace: 'nowrap',
18 [theme.breakpoints.up('sm')]: {
19 minHeight: 'auto'
20 }
21 }),
22 // TODO v5: remove
23
24 /* Styles applied to the root element if `disableGutters={false}`. */
25 gutters: {},
26
27 /* Styles applied to the root element if `selected={true}`. */
28 selected: {},
29
30 /* Styles applied to the root element if dense. */
31 dense: _extends({}, theme.typography.body2, {
32 minHeight: 'auto'
33 })
34});
35const MenuItem = /*#__PURE__*/React.forwardRef(function MenuItem(props, ref) {
36 const {
37 classes,
38 className,
39 component = 'li',
40 disableGutters = false,
41 ListItemClasses,
42 role = 'menuitem',
43 selected,
44 tabIndex: tabIndexProp
45 } = props,
46 other = _objectWithoutPropertiesLoose(props, ["classes", "className", "component", "disableGutters", "ListItemClasses", "role", "selected", "tabIndex"]);
47
48 let tabIndex;
49
50 if (!props.disabled) {
51 tabIndex = tabIndexProp !== undefined ? tabIndexProp : -1;
52 }
53
54 return /*#__PURE__*/React.createElement(ListItem, _extends({
55 button: true,
56 role: role,
57 tabIndex: tabIndex,
58 component: component,
59 selected: selected,
60 disableGutters: disableGutters,
61 classes: _extends({
62 dense: classes.dense
63 }, ListItemClasses),
64 className: clsx(classes.root, className, selected && classes.selected, !disableGutters && classes.gutters),
65 ref: ref
66 }, other));
67});
68process.env.NODE_ENV !== "production" ? MenuItem.propTypes = {
69 /**
70 * Menu item contents.
71 */
72 children: PropTypes.node,
73
74 /**
75 * Override or extend the styles applied to the component.
76 * See [CSS API](#css) below for more details.
77 */
78 classes: PropTypes.object.isRequired,
79
80 /**
81 * @ignore
82 */
83 className: PropTypes.string,
84
85 /**
86 * The component used for the root node.
87 * Either a string to use a HTML element or a component.
88 */
89 component: PropTypes
90 /* @typescript-to-proptypes-ignore */
91 .elementType,
92
93 /**
94 * If `true`, compact vertical padding designed for keyboard and mouse input will be used.
95 */
96 dense: PropTypes.bool,
97
98 /**
99 * @ignore
100 */
101 disabled: PropTypes.bool,
102
103 /**
104 * If `true`, the left and right padding is removed.
105 */
106 disableGutters: PropTypes.bool,
107
108 /**
109 * `classes` prop applied to the [`ListItem`](/api/list-item/) element.
110 */
111 ListItemClasses: PropTypes.object,
112
113 /**
114 * @ignore
115 */
116 role: PropTypes.string,
117
118 /**
119 * @ignore
120 */
121 selected: PropTypes.bool,
122
123 /**
124 * @ignore
125 */
126 tabIndex: PropTypes.number
127} : void 0;
128export default withStyles(styles, {
129 name: 'MuiMenuItem'
130})(MenuItem);
\No newline at end of file