1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 | Object.defineProperty(exports, "__esModule", {
|
5 | value: true
|
6 | });
|
7 | exports.default = void 0;
|
8 | var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
9 | var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
10 | var React = _interopRequireWildcard(require("react"));
|
11 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
12 | var _utils = require("@mui/utils");
|
13 | var _composeClasses = _interopRequireDefault(require("../composeClasses"));
|
14 | var _optionClasses = require("./optionClasses");
|
15 | var _utils2 = require("../utils");
|
16 | var _useOption = _interopRequireDefault(require("../useOption"));
|
17 | var _ClassNameConfigurator = require("../utils/ClassNameConfigurator");
|
18 | var _jsxRuntime = require("react/jsx-runtime");
|
19 | const _excluded = ["children", "disabled", "label", "slotProps", "slots", "value"];
|
20 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
21 | function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
22 | function useUtilityClasses(ownerState) {
|
23 | const {
|
24 | disabled,
|
25 | highlighted,
|
26 | selected
|
27 | } = ownerState;
|
28 | const slots = {
|
29 | root: ['root', disabled && 'disabled', highlighted && 'highlighted', selected && 'selected']
|
30 | };
|
31 | return (0, _composeClasses.default)(slots, (0, _ClassNameConfigurator.useClassNamesOverride)(_optionClasses.getOptionUtilityClass));
|
32 | }
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | const Option = React.forwardRef(function Option(props, forwardedRef) {
|
38 | var _slots$root, _optionRef$current;
|
39 | const {
|
40 | children,
|
41 | disabled = false,
|
42 | label,
|
43 | slotProps = {},
|
44 | slots = {},
|
45 | value
|
46 | } = props,
|
47 | other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
48 | const Root = (_slots$root = slots.root) != null ? _slots$root : 'li';
|
49 | const optionRef = React.useRef(null);
|
50 | const combinedRef = (0, _utils.unstable_useForkRef)(optionRef, forwardedRef);
|
51 |
|
52 |
|
53 |
|
54 | const computedLabel = label != null ? label : typeof children === 'string' ? children : (_optionRef$current = optionRef.current) == null ? void 0 : _optionRef$current.innerText;
|
55 | const {
|
56 | getRootProps,
|
57 | selected,
|
58 | highlighted,
|
59 | index
|
60 | } = (0, _useOption.default)({
|
61 | disabled,
|
62 | label: computedLabel,
|
63 | rootRef: combinedRef,
|
64 | value
|
65 | });
|
66 | const ownerState = (0, _extends2.default)({}, props, {
|
67 | disabled,
|
68 | highlighted,
|
69 | index,
|
70 | selected
|
71 | });
|
72 | const classes = useUtilityClasses(ownerState);
|
73 | const rootProps = (0, _utils2.useSlotProps)({
|
74 | getSlotProps: getRootProps,
|
75 | elementType: Root,
|
76 | externalSlotProps: slotProps.root,
|
77 | externalForwardedProps: other,
|
78 | className: classes.root,
|
79 | ownerState
|
80 | });
|
81 | return (0, _jsxRuntime.jsx)(Root, (0, _extends2.default)({}, rootProps, {
|
82 | children: children
|
83 | }));
|
84 | });
|
85 | process.env.NODE_ENV !== "production" ? Option.propTypes = {
|
86 |
|
87 |
|
88 |
|
89 |
|
90 | |
91 |
|
92 |
|
93 | children: _propTypes.default.node,
|
94 | |
95 |
|
96 |
|
97 |
|
98 | disabled: _propTypes.default.bool,
|
99 | |
100 |
|
101 |
|
102 |
|
103 | label: _propTypes.default.string,
|
104 | |
105 |
|
106 |
|
107 |
|
108 | slotProps: _propTypes.default.shape({
|
109 | root: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object])
|
110 | }),
|
111 | |
112 |
|
113 |
|
114 |
|
115 |
|
116 | slots: _propTypes.default.shape({
|
117 | root: _propTypes.default.elementType
|
118 | }),
|
119 | |
120 |
|
121 |
|
122 | value: _propTypes.default.any.isRequired
|
123 | } : void 0;
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 | var _default = React.memo(Option);
|
137 | exports.default = _default; |
\ | No newline at end of file |