1 | 'use client';
|
2 |
|
3 | import _extends from "@babel/runtime/helpers/esm/extends";
|
4 | import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
5 | import * as React from 'react';
|
6 | import PropTypes from 'prop-types';
|
7 | import clsx from 'clsx';
|
8 | import deepmerge from '@mui/utils/deepmerge';
|
9 | import SelectInput from './SelectInput';
|
10 | import formControlState from '../FormControl/formControlState';
|
11 | import useFormControl from '../FormControl/useFormControl';
|
12 | import ArrowDropDownIcon from '../internal/svg-icons/ArrowDropDown';
|
13 | import Input from '../Input';
|
14 | import NativeSelectInput from '../NativeSelect/NativeSelectInput';
|
15 | import FilledInput from '../FilledInput';
|
16 | import OutlinedInput from '../OutlinedInput';
|
17 | import { useDefaultProps } from '../DefaultPropsProvider';
|
18 | import useForkRef from '../utils/useForkRef';
|
19 | import styled, { rootShouldForwardProp } from '../styles/styled';
|
20 | import { jsx as _jsx } from "react/jsx-runtime";
|
21 | var useUtilityClasses = function useUtilityClasses(ownerState) {
|
22 | var classes = ownerState.classes;
|
23 | return classes;
|
24 | };
|
25 | var styledRootConfig = {
|
26 | name: 'MuiSelect',
|
27 | overridesResolver: function overridesResolver(props, styles) {
|
28 | return styles.root;
|
29 | },
|
30 | shouldForwardProp: function shouldForwardProp(prop) {
|
31 | return rootShouldForwardProp(prop) && prop !== 'variant';
|
32 | },
|
33 | slot: 'Root'
|
34 | };
|
35 | var StyledInput = styled(Input, styledRootConfig)('');
|
36 | var StyledOutlinedInput = styled(OutlinedInput, styledRootConfig)('');
|
37 | var StyledFilledInput = styled(FilledInput, styledRootConfig)('');
|
38 | var Select = React.forwardRef(function Select(inProps, ref) {
|
39 | var props = useDefaultProps({
|
40 | name: 'MuiSelect',
|
41 | props: inProps
|
42 | });
|
43 | var _props$autoWidth = props.autoWidth,
|
44 | autoWidth = _props$autoWidth === void 0 ? false : _props$autoWidth,
|
45 | children = props.children,
|
46 | _props$classes = props.classes,
|
47 | classesProp = _props$classes === void 0 ? {} : _props$classes,
|
48 | className = props.className,
|
49 | _props$defaultOpen = props.defaultOpen,
|
50 | defaultOpen = _props$defaultOpen === void 0 ? false : _props$defaultOpen,
|
51 | _props$displayEmpty = props.displayEmpty,
|
52 | displayEmpty = _props$displayEmpty === void 0 ? false : _props$displayEmpty,
|
53 | _props$IconComponent = props.IconComponent,
|
54 | IconComponent = _props$IconComponent === void 0 ? ArrowDropDownIcon : _props$IconComponent,
|
55 | id = props.id,
|
56 | input = props.input,
|
57 | inputProps = props.inputProps,
|
58 | label = props.label,
|
59 | labelId = props.labelId,
|
60 | MenuProps = props.MenuProps,
|
61 | _props$multiple = props.multiple,
|
62 | multiple = _props$multiple === void 0 ? false : _props$multiple,
|
63 | _props$native = props.native,
|
64 | native = _props$native === void 0 ? false : _props$native,
|
65 | onClose = props.onClose,
|
66 | onOpen = props.onOpen,
|
67 | open = props.open,
|
68 | renderValue = props.renderValue,
|
69 | SelectDisplayProps = props.SelectDisplayProps,
|
70 | _props$variant = props.variant,
|
71 | variantProp = _props$variant === void 0 ? 'outlined' : _props$variant,
|
72 | other = _objectWithoutProperties(props, ["autoWidth", "children", "classes", "className", "defaultOpen", "displayEmpty", "IconComponent", "id", "input", "inputProps", "label", "labelId", "MenuProps", "multiple", "native", "onClose", "onOpen", "open", "renderValue", "SelectDisplayProps", "variant"]);
|
73 | var inputComponent = native ? NativeSelectInput : SelectInput;
|
74 | var muiFormControl = useFormControl();
|
75 | var fcs = formControlState({
|
76 | props: props,
|
77 | muiFormControl: muiFormControl,
|
78 | states: ['variant', 'error']
|
79 | });
|
80 | var variant = fcs.variant || variantProp;
|
81 | var ownerState = _extends({}, props, {
|
82 | variant: variant,
|
83 | classes: classesProp
|
84 | });
|
85 | var classes = useUtilityClasses(ownerState);
|
86 | var root = classes.root,
|
87 | restOfClasses = _objectWithoutProperties(classes, ["root"]);
|
88 | var InputComponent = input || {
|
89 | standard: _jsx(StyledInput, {
|
90 | ownerState: ownerState
|
91 | }),
|
92 | outlined: _jsx(StyledOutlinedInput, {
|
93 | label: label,
|
94 | ownerState: ownerState
|
95 | }),
|
96 | filled: _jsx(StyledFilledInput, {
|
97 | ownerState: ownerState
|
98 | })
|
99 | }[variant];
|
100 | var inputComponentRef = useForkRef(ref, InputComponent.ref);
|
101 | return _jsx(React.Fragment, {
|
102 | children: React.cloneElement(InputComponent, _extends({
|
103 |
|
104 |
|
105 | inputComponent: inputComponent,
|
106 | inputProps: _extends({
|
107 | children: children,
|
108 | error: fcs.error,
|
109 | IconComponent: IconComponent,
|
110 | variant: variant,
|
111 | type: undefined,
|
112 |
|
113 | multiple: multiple
|
114 | }, native ? {
|
115 | id: id
|
116 | } : {
|
117 | autoWidth: autoWidth,
|
118 | defaultOpen: defaultOpen,
|
119 | displayEmpty: displayEmpty,
|
120 | labelId: labelId,
|
121 | MenuProps: MenuProps,
|
122 | onClose: onClose,
|
123 | onOpen: onOpen,
|
124 | open: open,
|
125 | renderValue: renderValue,
|
126 | SelectDisplayProps: _extends({
|
127 | id: id
|
128 | }, SelectDisplayProps)
|
129 | }, inputProps, {
|
130 | classes: inputProps ? deepmerge(restOfClasses, inputProps.classes) : restOfClasses
|
131 | }, input ? input.props.inputProps : {})
|
132 | }, (multiple && native || displayEmpty) && variant === 'outlined' ? {
|
133 | notched: true
|
134 | } : {}, {
|
135 | ref: inputComponentRef,
|
136 | className: clsx(InputComponent.props.className, className, classes.root)
|
137 | }, !input && {
|
138 | variant: variant
|
139 | }, other))
|
140 | });
|
141 | });
|
142 | process.env.NODE_ENV !== "production" ? Select.propTypes = {
|
143 |
|
144 |
|
145 |
|
146 |
|
147 | |
148 |
|
149 |
|
150 |
|
151 |
|
152 | autoWidth: PropTypes.bool,
|
153 | |
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 | children: PropTypes.node,
|
160 | |
161 |
|
162 |
|
163 |
|
164 | classes: PropTypes.object,
|
165 | |
166 |
|
167 |
|
168 | className: PropTypes.string,
|
169 | |
170 |
|
171 |
|
172 |
|
173 |
|
174 | defaultOpen: PropTypes.bool,
|
175 | |
176 |
|
177 |
|
178 | defaultValue: PropTypes.any,
|
179 | |
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 | displayEmpty: PropTypes.bool,
|
190 | |
191 |
|
192 |
|
193 |
|
194 | IconComponent: PropTypes.elementType,
|
195 | |
196 |
|
197 |
|
198 | id: PropTypes.string,
|
199 | |
200 |
|
201 |
|
202 | input: PropTypes.element,
|
203 | |
204 |
|
205 |
|
206 |
|
207 | inputProps: PropTypes.object,
|
208 | |
209 |
|
210 |
|
211 | label: PropTypes.node,
|
212 | |
213 |
|
214 |
|
215 |
|
216 | labelId: PropTypes.string,
|
217 | |
218 |
|
219 |
|
220 | MenuProps: PropTypes.object,
|
221 | |
222 |
|
223 |
|
224 |
|
225 | multiple: PropTypes.bool,
|
226 | |
227 |
|
228 |
|
229 |
|
230 | native: PropTypes.bool,
|
231 | |
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 | onChange: PropTypes.func,
|
240 | |
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 | onClose: PropTypes.func,
|
247 | |
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 | onOpen: PropTypes.func,
|
254 | |
255 |
|
256 |
|
257 |
|
258 | open: PropTypes.bool,
|
259 | |
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 | renderValue: PropTypes.func,
|
267 | |
268 |
|
269 |
|
270 | SelectDisplayProps: PropTypes.object,
|
271 | |
272 |
|
273 |
|
274 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
275 | |
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 | value: PropTypes.oneOfType([PropTypes.oneOf(['']), PropTypes.any]),
|
283 | |
284 |
|
285 |
|
286 |
|
287 | variant: PropTypes.oneOf(['filled', 'outlined', 'standard'])
|
288 | } : void 0;
|
289 | Select.muiName = 'Select';
|
290 | export default Select; |
\ | No newline at end of file |