1 | 'use client';
|
2 |
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import clsx from 'clsx';
|
6 | import composeClasses from '@mui/utils/composeClasses';
|
7 | import useId from '@mui/utils/useId';
|
8 | import refType from '@mui/utils/refType';
|
9 | import { styled } from "../zero-styled/index.js";
|
10 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
11 | import Input from "../Input/index.js";
|
12 | import FilledInput from "../FilledInput/index.js";
|
13 | import OutlinedInput from "../OutlinedInput/index.js";
|
14 | import InputLabel from "../InputLabel/index.js";
|
15 | import FormControl from "../FormControl/index.js";
|
16 | import FormHelperText from "../FormHelperText/index.js";
|
17 | import Select from "../Select/index.js";
|
18 | import { getTextFieldUtilityClass } from "./textFieldClasses.js";
|
19 | import useSlot from "../utils/useSlot.js";
|
20 | import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
21 | const variantComponent = {
|
22 | standard: Input,
|
23 | filled: FilledInput,
|
24 | outlined: OutlinedInput
|
25 | };
|
26 | const useUtilityClasses = ownerState => {
|
27 | const {
|
28 | classes
|
29 | } = ownerState;
|
30 | const slots = {
|
31 | root: ['root']
|
32 | };
|
33 | return composeClasses(slots, getTextFieldUtilityClass, classes);
|
34 | };
|
35 | const TextFieldRoot = styled(FormControl, {
|
36 | name: 'MuiTextField',
|
37 | slot: 'Root',
|
38 | overridesResolver: (props, styles) => styles.root
|
39 | })({});
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | const TextField = React.forwardRef(function TextField(inProps, ref) {
|
74 | const props = useDefaultProps({
|
75 | props: inProps,
|
76 | name: 'MuiTextField'
|
77 | });
|
78 | const {
|
79 | autoComplete,
|
80 | autoFocus = false,
|
81 | children,
|
82 | className,
|
83 | color = 'primary',
|
84 | defaultValue,
|
85 | disabled = false,
|
86 | error = false,
|
87 | FormHelperTextProps: FormHelperTextPropsProp,
|
88 | fullWidth = false,
|
89 | helperText,
|
90 | id: idOverride,
|
91 | InputLabelProps: InputLabelPropsProp,
|
92 | inputProps: inputPropsProp,
|
93 | InputProps: InputPropsProp,
|
94 | inputRef,
|
95 | label,
|
96 | maxRows,
|
97 | minRows,
|
98 | multiline = false,
|
99 | name,
|
100 | onBlur,
|
101 | onChange,
|
102 | onFocus,
|
103 | placeholder,
|
104 | required = false,
|
105 | rows,
|
106 | select = false,
|
107 | SelectProps: SelectPropsProp,
|
108 | slots = {},
|
109 | slotProps = {},
|
110 | type,
|
111 | value,
|
112 | variant = 'outlined',
|
113 | ...other
|
114 | } = props;
|
115 | const ownerState = {
|
116 | ...props,
|
117 | autoFocus,
|
118 | color,
|
119 | disabled,
|
120 | error,
|
121 | fullWidth,
|
122 | multiline,
|
123 | required,
|
124 | select,
|
125 | variant
|
126 | };
|
127 | const classes = useUtilityClasses(ownerState);
|
128 | if (process.env.NODE_ENV !== 'production') {
|
129 | if (select && !children) {
|
130 | console.error('MUI: `children` must be passed when using the `TextField` component with `select`.');
|
131 | }
|
132 | }
|
133 | const id = useId(idOverride);
|
134 | const helperTextId = helperText && id ? `${id}-helper-text` : undefined;
|
135 | const inputLabelId = label && id ? `${id}-label` : undefined;
|
136 | const InputComponent = variantComponent[variant];
|
137 | const externalForwardedProps = {
|
138 | slots,
|
139 | slotProps: {
|
140 | input: InputPropsProp,
|
141 | inputLabel: InputLabelPropsProp,
|
142 | htmlInput: inputPropsProp,
|
143 | formHelperText: FormHelperTextPropsProp,
|
144 | select: SelectPropsProp,
|
145 | ...slotProps
|
146 | }
|
147 | };
|
148 | const inputAdditionalProps = {};
|
149 | const inputLabelSlotProps = externalForwardedProps.slotProps.inputLabel;
|
150 | if (variant === 'outlined') {
|
151 | if (inputLabelSlotProps && typeof inputLabelSlotProps.shrink !== 'undefined') {
|
152 | inputAdditionalProps.notched = inputLabelSlotProps.shrink;
|
153 | }
|
154 | inputAdditionalProps.label = label;
|
155 | }
|
156 | if (select) {
|
157 |
|
158 | if (!SelectPropsProp || !SelectPropsProp.native) {
|
159 | inputAdditionalProps.id = undefined;
|
160 | }
|
161 | inputAdditionalProps['aria-describedby'] = undefined;
|
162 | }
|
163 | const [InputSlot, inputProps] = useSlot('input', {
|
164 | elementType: InputComponent,
|
165 | externalForwardedProps,
|
166 | additionalProps: inputAdditionalProps,
|
167 | ownerState
|
168 | });
|
169 | const [InputLabelSlot, inputLabelProps] = useSlot('inputLabel', {
|
170 | elementType: InputLabel,
|
171 | externalForwardedProps,
|
172 | ownerState
|
173 | });
|
174 | const [HtmlInputSlot, htmlInputProps] = useSlot('htmlInput', {
|
175 | elementType: 'input',
|
176 | externalForwardedProps,
|
177 | ownerState
|
178 | });
|
179 | const [FormHelperTextSlot, formHelperTextProps] = useSlot('formHelperText', {
|
180 | elementType: FormHelperText,
|
181 | externalForwardedProps,
|
182 | ownerState
|
183 | });
|
184 | const [SelectSlot, selectProps] = useSlot('select', {
|
185 | elementType: Select,
|
186 | externalForwardedProps,
|
187 | ownerState
|
188 | });
|
189 | const InputElement = _jsx(InputSlot, {
|
190 | "aria-describedby": helperTextId,
|
191 | autoComplete: autoComplete,
|
192 | autoFocus: autoFocus,
|
193 | defaultValue: defaultValue,
|
194 | fullWidth: fullWidth,
|
195 | multiline: multiline,
|
196 | name: name,
|
197 | rows: rows,
|
198 | maxRows: maxRows,
|
199 | minRows: minRows,
|
200 | type: type,
|
201 | value: value,
|
202 | id: id,
|
203 | inputRef: inputRef,
|
204 | onBlur: onBlur,
|
205 | onChange: onChange,
|
206 | onFocus: onFocus,
|
207 | placeholder: placeholder,
|
208 | inputProps: htmlInputProps,
|
209 | slots: {
|
210 | input: slots.htmlInput ? HtmlInputSlot : undefined
|
211 | },
|
212 | ...inputProps
|
213 | });
|
214 | return _jsxs(TextFieldRoot, {
|
215 | className: clsx(classes.root, className),
|
216 | disabled: disabled,
|
217 | error: error,
|
218 | fullWidth: fullWidth,
|
219 | ref: ref,
|
220 | required: required,
|
221 | color: color,
|
222 | variant: variant,
|
223 | ownerState: ownerState,
|
224 | ...other,
|
225 | children: [label != null && label !== '' && _jsx(InputLabelSlot, {
|
226 | htmlFor: id,
|
227 | id: inputLabelId,
|
228 | ...inputLabelProps,
|
229 | children: label
|
230 | }), select ? _jsx(SelectSlot, {
|
231 | "aria-describedby": helperTextId,
|
232 | id: id,
|
233 | labelId: inputLabelId,
|
234 | value: value,
|
235 | input: InputElement,
|
236 | ...selectProps,
|
237 | children: children
|
238 | }) : InputElement, helperText && _jsx(FormHelperTextSlot, {
|
239 | id: helperTextId,
|
240 | ...formHelperTextProps,
|
241 | children: helperText
|
242 | })]
|
243 | });
|
244 | });
|
245 | process.env.NODE_ENV !== "production" ? TextField.propTypes = {
|
246 |
|
247 |
|
248 |
|
249 |
|
250 | |
251 |
|
252 |
|
253 |
|
254 |
|
255 | autoComplete: PropTypes.string,
|
256 | |
257 |
|
258 |
|
259 |
|
260 | autoFocus: PropTypes.bool,
|
261 | |
262 |
|
263 |
|
264 | children: PropTypes.node,
|
265 | |
266 |
|
267 |
|
268 | classes: PropTypes.object,
|
269 | |
270 |
|
271 |
|
272 | className: PropTypes.string,
|
273 | |
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 | color: PropTypes .oneOfType([PropTypes.oneOf(['primary', 'secondary', 'error', 'info', 'success', 'warning']), PropTypes.string]),
|
280 | |
281 |
|
282 |
|
283 | defaultValue: PropTypes.any,
|
284 | |
285 |
|
286 |
|
287 |
|
288 | disabled: PropTypes.bool,
|
289 | |
290 |
|
291 |
|
292 |
|
293 | error: PropTypes.bool,
|
294 | |
295 |
|
296 |
|
297 |
|
298 | FormHelperTextProps: PropTypes.object,
|
299 | |
300 |
|
301 |
|
302 |
|
303 | fullWidth: PropTypes.bool,
|
304 | |
305 |
|
306 |
|
307 | helperText: PropTypes.node,
|
308 | |
309 |
|
310 |
|
311 |
|
312 | id: PropTypes.string,
|
313 | |
314 |
|
315 |
|
316 |
|
317 |
|
318 | InputLabelProps: PropTypes.object,
|
319 | |
320 |
|
321 |
|
322 |
|
323 | inputProps: PropTypes.object,
|
324 | |
325 |
|
326 |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 | InputProps: PropTypes.object,
|
332 | |
333 |
|
334 |
|
335 | inputRef: refType,
|
336 | |
337 |
|
338 |
|
339 | label: PropTypes.node,
|
340 | |
341 |
|
342 |
|
343 |
|
344 | margin: PropTypes.oneOf(['dense', 'none', 'normal']),
|
345 | |
346 |
|
347 |
|
348 | maxRows: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
349 | |
350 |
|
351 |
|
352 | minRows: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
353 | |
354 |
|
355 |
|
356 |
|
357 | multiline: PropTypes.bool,
|
358 | |
359 |
|
360 |
|
361 | name: PropTypes.string,
|
362 | |
363 |
|
364 |
|
365 | onBlur: PropTypes.func,
|
366 | |
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 | onChange: PropTypes.func,
|
373 | |
374 |
|
375 |
|
376 | onFocus: PropTypes.func,
|
377 | |
378 |
|
379 |
|
380 | placeholder: PropTypes.string,
|
381 | |
382 |
|
383 |
|
384 |
|
385 | required: PropTypes.bool,
|
386 | |
387 |
|
388 |
|
389 | rows: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
390 | |
391 |
|
392 |
|
393 |
|
394 |
|
395 | select: PropTypes.bool,
|
396 | |
397 |
|
398 |
|
399 |
|
400 | SelectProps: PropTypes.object,
|
401 | |
402 |
|
403 |
|
404 | size: PropTypes .oneOfType([PropTypes.oneOf(['medium', 'small']), PropTypes.string]),
|
405 | |
406 |
|
407 |
|
408 |
|
409 | slotProps: PropTypes .shape({
|
410 | formHelperText: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
411 | htmlInput: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
412 | input: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
413 | inputLabel: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
414 | select: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
415 | }),
|
416 | |
417 |
|
418 |
|
419 |
|
420 | slots: PropTypes.shape({
|
421 | formHelperText: PropTypes.elementType,
|
422 | htmlInput: PropTypes.elementType,
|
423 | input: PropTypes.elementType,
|
424 | inputLabel: PropTypes.elementType,
|
425 | select: PropTypes.elementType
|
426 | }),
|
427 | |
428 |
|
429 |
|
430 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
431 | |
432 |
|
433 |
|
434 | type: PropTypes .string,
|
435 | |
436 |
|
437 |
|
438 | value: PropTypes.any,
|
439 | |
440 |
|
441 |
|
442 |
|
443 | variant: PropTypes.oneOf(['filled', 'outlined', 'standard'])
|
444 | } : void 0;
|
445 | export default TextField; |
\ | No newline at end of file |