1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
3 | const _excluded = ["children", "disabled", "label", "slotProps", "slots"];
|
4 | import * as React from 'react';
|
5 | import PropTypes from 'prop-types';
|
6 | import { getMenuItemUtilityClass } from './menuItemClasses';
|
7 | import useMenuItem from '../useMenuItem';
|
8 | import composeClasses from '../composeClasses';
|
9 | import useSlotProps from '../utils/useSlotProps';
|
10 | import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
11 | import { jsx as _jsx } from "react/jsx-runtime";
|
12 | function useUtilityClasses(ownerState) {
|
13 | const {
|
14 | disabled,
|
15 | focusVisible
|
16 | } = ownerState;
|
17 | const slots = {
|
18 | root: ['root', disabled && 'disabled', focusVisible && 'focusVisible']
|
19 | };
|
20 | return composeClasses(slots, useClassNamesOverride(getMenuItemUtilityClass));
|
21 | }
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | const MenuItem = React.forwardRef(function MenuItem(props, forwardedRef) {
|
34 | const {
|
35 | children,
|
36 | disabled: disabledProp = false,
|
37 | label,
|
38 | slotProps = {},
|
39 | slots = {}
|
40 | } = props,
|
41 | other = _objectWithoutPropertiesLoose(props, _excluded);
|
42 | const {
|
43 | getRootProps,
|
44 | disabled,
|
45 | focusVisible,
|
46 | highlighted
|
47 | } = useMenuItem({
|
48 | disabled: disabledProp,
|
49 | rootRef: forwardedRef,
|
50 | label
|
51 | });
|
52 | const ownerState = _extends({}, props, {
|
53 | disabled,
|
54 | focusVisible,
|
55 | highlighted
|
56 | });
|
57 | const classes = useUtilityClasses(ownerState);
|
58 | const Root = slots.root ?? 'li';
|
59 | const rootProps = useSlotProps({
|
60 | elementType: Root,
|
61 | getSlotProps: getRootProps,
|
62 | externalSlotProps: slotProps.root,
|
63 | externalForwardedProps: other,
|
64 | className: classes.root,
|
65 | ownerState
|
66 | });
|
67 | return _jsx(Root, _extends({}, rootProps, {
|
68 | children: children
|
69 | }));
|
70 | });
|
71 | process.env.NODE_ENV !== "production" ? MenuItem.propTypes = {
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | |
77 |
|
78 |
|
79 | children: PropTypes.node,
|
80 | |
81 |
|
82 |
|
83 | disabled: PropTypes.bool,
|
84 | |
85 |
|
86 |
|
87 |
|
88 | label: PropTypes.string,
|
89 | |
90 |
|
91 |
|
92 |
|
93 | slotProps: PropTypes.shape({
|
94 | root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
95 | }),
|
96 | |
97 |
|
98 |
|
99 |
|
100 |
|
101 | slots: PropTypes.shape({
|
102 | root: PropTypes.elementType
|
103 | })
|
104 | } : void 0;
|
105 | export default MenuItem; |
\ | No newline at end of file |