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