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 | const {
|
27 | children,
|
28 | disabled: disabledProp = false,
|
29 | label,
|
30 | id,
|
31 | slotProps = {},
|
32 | slots = {}
|
33 | } = props,
|
34 | other = _objectWithoutPropertiesLoose(props, _excluded);
|
35 | const {
|
36 | getRootProps,
|
37 | disabled,
|
38 | focusVisible,
|
39 | highlighted
|
40 | } = useMenuItem({
|
41 | id,
|
42 | disabled: disabledProp,
|
43 | rootRef: forwardedRef,
|
44 | label
|
45 | });
|
46 | const ownerState = _extends({}, props, {
|
47 | disabled,
|
48 | focusVisible,
|
49 | highlighted
|
50 | });
|
51 | const classes = useUtilityClasses(ownerState);
|
52 | const Root = slots.root ?? 'li';
|
53 | const rootProps = useSlotProps({
|
54 | elementType: Root,
|
55 | getSlotProps: getRootProps,
|
56 | externalSlotProps: slotProps.root,
|
57 | externalForwardedProps: other,
|
58 | className: classes.root,
|
59 | ownerState
|
60 | });
|
61 | return _jsx(Root, _extends({}, rootProps, {
|
62 | children: children
|
63 | }));
|
64 | }));
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | const MenuItem = React.forwardRef(function MenuItem(props, ref) {
|
78 | const {
|
79 | id: idProp
|
80 | } = props;
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | const {
|
87 | contextValue,
|
88 | id
|
89 | } = useMenuItemContextStabilizer(idProp);
|
90 | return _jsx(ListContext.Provider, {
|
91 | value: contextValue,
|
92 | children: _jsx(InnerMenuItem, _extends({}, props, {
|
93 | id: id,
|
94 | ref: ref
|
95 | }))
|
96 | });
|
97 | });
|
98 | process.env.NODE_ENV !== "production" ? MenuItem.propTypes = {
|
99 |
|
100 |
|
101 |
|
102 |
|
103 | |
104 |
|
105 |
|
106 | children: PropTypes.node,
|
107 | |
108 |
|
109 |
|
110 | className: PropTypes.string,
|
111 | |
112 |
|
113 |
|
114 |
|
115 | disabled: PropTypes.bool,
|
116 | |
117 |
|
118 |
|
119 |
|
120 |
|
121 | disableFocusOnHover: PropTypes.bool,
|
122 | |
123 |
|
124 |
|
125 |
|
126 | label: PropTypes.string,
|
127 | |
128 |
|
129 |
|
130 | onClick: PropTypes.func,
|
131 | |
132 |
|
133 |
|
134 |
|
135 | slotProps: PropTypes.shape({
|
136 | root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
137 | }),
|
138 | |
139 |
|
140 |
|
141 |
|
142 |
|
143 | slots: PropTypes.shape({
|
144 | root: PropTypes.elementType
|
145 | })
|
146 | } : void 0;
|
147 | export { MenuItem }; |
\ | No newline at end of file |