1 | 'use client';
|
2 |
|
3 | import _extends from "@babel/runtime/helpers/esm/extends";
|
4 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
5 | const _excluded = ["children", "disabled", "label", "id", "slotProps", "slots"];
|
6 | import * as React from 'react';
|
7 | import PropTypes from 'prop-types';
|
8 | import { getMenuItemUtilityClass } from './menuItemClasses';
|
9 | import { useMenuItem, useMenuItemContextStabilizer } from '../useMenuItem';
|
10 | import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
11 | import { useSlotProps } from '../utils/useSlotProps';
|
12 | import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
13 | import { ListContext } from '../useList';
|
14 | import { jsx as _jsx } from "react/jsx-runtime";
|
15 | function useUtilityClasses(ownerState) {
|
16 | const {
|
17 | disabled,
|
18 | focusVisible
|
19 | } = ownerState;
|
20 | const slots = {
|
21 | root: ['root', disabled && 'disabled', focusVisible && 'focusVisible']
|
22 | };
|
23 | return composeClasses(slots, useClassNamesOverride(getMenuItemUtilityClass));
|
24 | }
|
25 | const InnerMenuItem = React.memo( React.forwardRef(function MenuItem(props, forwardedRef) {
|
26 | var _slots$root;
|
27 | const {
|
28 | children,
|
29 | disabled: disabledProp = false,
|
30 | label,
|
31 | id,
|
32 | slotProps = {},
|
33 | slots = {}
|
34 | } = props,
|
35 | other = _objectWithoutPropertiesLoose(props, _excluded);
|
36 | const {
|
37 | getRootProps,
|
38 | disabled,
|
39 | focusVisible,
|
40 | highlighted
|
41 | } = useMenuItem({
|
42 | id,
|
43 | disabled: disabledProp,
|
44 | rootRef: forwardedRef,
|
45 | label
|
46 | });
|
47 | const ownerState = _extends({}, props, {
|
48 | disabled,
|
49 | focusVisible,
|
50 | highlighted
|
51 | });
|
52 | const classes = useUtilityClasses(ownerState);
|
53 | const Root = (_slots$root = slots.root) != null ? _slots$root : 'li';
|
54 | const rootProps = useSlotProps({
|
55 | elementType: Root,
|
56 | getSlotProps: getRootProps,
|
57 | externalSlotProps: slotProps.root,
|
58 | externalForwardedProps: other,
|
59 | className: classes.root,
|
60 | ownerState
|
61 | });
|
62 | return _jsx(Root, _extends({}, rootProps, {
|
63 | children: children
|
64 | }));
|
65 | }));
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 | const MenuItem = React.forwardRef(function MenuItem(props, ref) {
|
79 | const {
|
80 | id: idProp
|
81 | } = props;
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | const {
|
88 | contextValue,
|
89 | id
|
90 | } = useMenuItemContextStabilizer(idProp);
|
91 | return _jsx(ListContext.Provider, {
|
92 | value: contextValue,
|
93 | children: _jsx(InnerMenuItem, _extends({}, props, {
|
94 | id: id,
|
95 | ref: ref
|
96 | }))
|
97 | });
|
98 | });
|
99 | process.env.NODE_ENV !== "production" ? MenuItem.propTypes = {
|
100 |
|
101 |
|
102 |
|
103 |
|
104 | |
105 |
|
106 |
|
107 | children: PropTypes.node,
|
108 | |
109 |
|
110 |
|
111 | className: PropTypes.string,
|
112 | |
113 |
|
114 |
|
115 |
|
116 | disabled: PropTypes.bool,
|
117 | |
118 |
|
119 |
|
120 |
|
121 |
|
122 | disableFocusOnHover: PropTypes.bool,
|
123 | |
124 |
|
125 |
|
126 |
|
127 | label: PropTypes.string,
|
128 | |
129 |
|
130 |
|
131 | onClick: PropTypes.func,
|
132 | |
133 |
|
134 |
|
135 |
|
136 | slotProps: PropTypes.shape({
|
137 | root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
138 | }),
|
139 | |
140 |
|
141 |
|
142 |
|
143 |
|
144 | slots: PropTypes.shape({
|
145 | root: PropTypes.elementType
|
146 | })
|
147 | } : void 0;
|
148 | export { MenuItem }; |
\ | No newline at end of file |