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