13.6 kBJavaScriptView Raw
1'use client';
2
3import _extends from "@babel/runtime/helpers/esm/extends";
4import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5import * as React from 'react';
6import PropTypes from 'prop-types';
7import clsx from 'clsx';
8import composeClasses from '@mui/utils/composeClasses';
9import useId from '@mui/utils/useId';
10import refType from '@mui/utils/refType';
11import styled from '../styles/styled';
12import { useDefaultProps } from '../DefaultPropsProvider';
13import Input from '../Input';
14import FilledInput from '../FilledInput';
15import OutlinedInput from '../OutlinedInput';
16import InputLabel from '../InputLabel';
17import FormControl from '../FormControl';
18import FormHelperText from '../FormHelperText';
19import Select from '../Select';
20import { getTextFieldUtilityClass } from './textFieldClasses';
21import { jsx as _jsx } from "react/jsx-runtime";
22import { jsxs as _jsxs } from "react/jsx-runtime";
23var variantComponent = {
24 standard: Input,
25 filled: FilledInput,
26 outlined: OutlinedInput
27};
28var useUtilityClasses = function useUtilityClasses(ownerState) {
29 var classes = ownerState.classes;
30 var slots = {
31 root: ['root']
32 };
33 return composeClasses(slots, getTextFieldUtilityClass, classes);
34};
35var TextFieldRoot = styled(FormControl, {
36 name: 'MuiTextField',
37 slot: 'Root',
38 overridesResolver: function overridesResolver(props, styles) {
39 return styles.root;
40 }
41})({});
42
43/**
44 * The `TextField` is a convenience wrapper for the most common cases (80%).
45 * It cannot be all things to all people, otherwise the API would grow out of control.
46 *
47 * ## Advanced Configuration
48 *
49 * It's important to understand that the text field is a simple abstraction
50 * on top of the following components:
51 *
52 * - [FormControl](/material-ui/api/form-control/)
53 * - [InputLabel](/material-ui/api/input-label/)
54 * - [FilledInput](/material-ui/api/filled-input/)
55 * - [OutlinedInput](/material-ui/api/outlined-input/)
56 * - [Input](/material-ui/api/input/)
57 * - [FormHelperText](/material-ui/api/form-helper-text/)
58 *
59 * If you wish to alter the props applied to the `input` element, you can do so as follows:
60 *
61 * ```jsx
62 * const inputProps = {
63 * step: 300,
64 * };
65 *
66 * return <TextField id="time" type="time" inputProps={inputProps} />;
67 * ```
68 *
69 * For advanced cases, please look at the source of TextField by clicking on the
70 * "Edit this page" button above. Consider either:
71 *
72 * - using the upper case props for passing values directly to the components
73 * - using the underlying components directly as shown in the demos
74 */
75var TextField = /*#__PURE__*/React.forwardRef(function TextField(inProps, ref) {
76 var props = useDefaultProps({
77 props: inProps,
78 name: 'MuiTextField'
79 });
80 var autoComplete = props.autoComplete,
81 _props$autoFocus = props.autoFocus,
82 autoFocus = _props$autoFocus === void 0 ? false : _props$autoFocus,
83 children = props.children,
84 className = props.className,
85 _props$color = props.color,
86 color = _props$color === void 0 ? 'primary' : _props$color,
87 defaultValue = props.defaultValue,
88 _props$disabled = props.disabled,
89 disabled = _props$disabled === void 0 ? false : _props$disabled,
90 _props$error = props.error,
91 error = _props$error === void 0 ? false : _props$error,
92 FormHelperTextProps = props.FormHelperTextProps,
93 _props$fullWidth = props.fullWidth,
94 fullWidth = _props$fullWidth === void 0 ? false : _props$fullWidth,
95 helperText = props.helperText,
96 idOverride = props.id,
97 InputLabelProps = props.InputLabelProps,
98 inputProps = props.inputProps,
99 InputProps = props.InputProps,
100 inputRef = props.inputRef,
101 label = props.label,
102 maxRows = props.maxRows,
103 minRows = props.minRows,
104 _props$multiline = props.multiline,
105 multiline = _props$multiline === void 0 ? false : _props$multiline,
106 name = props.name,
107 onBlur = props.onBlur,
108 onChange = props.onChange,
109 onFocus = props.onFocus,
110 placeholder = props.placeholder,
111 _props$required = props.required,
112 required = _props$required === void 0 ? false : _props$required,
113 rows = props.rows,
114 _props$select = props.select,
115 select = _props$select === void 0 ? false : _props$select,
116 SelectProps = props.SelectProps,
117 type = props.type,
118 value = props.value,
119 _props$variant = props.variant,
120 variant = _props$variant === void 0 ? 'outlined' : _props$variant,
121 other = _objectWithoutProperties(props, ["autoComplete", "autoFocus", "children", "className", "color", "defaultValue", "disabled", "error", "FormHelperTextProps", "fullWidth", "helperText", "id", "InputLabelProps", "inputProps", "InputProps", "inputRef", "label", "maxRows", "minRows", "multiline", "name", "onBlur", "onChange", "onFocus", "placeholder", "required", "rows", "select", "SelectProps", "type", "value", "variant"]);
122 var ownerState = _extends({}, props, {
123 autoFocus: autoFocus,
124 color: color,
125 disabled: disabled,
126 error: error,
127 fullWidth: fullWidth,
128 multiline: multiline,
129 required: required,
130 select: select,
131 variant: variant
132 });
133 var classes = useUtilityClasses(ownerState);
134 if (process.env.NODE_ENV !== 'production') {
135 if (select && !children) {
136 console.error('MUI: `children` must be passed when using the `TextField` component with `select`.');
137 }
138 }
139 var InputMore = {};
140 if (variant === 'outlined') {
141 if (InputLabelProps && typeof InputLabelProps.shrink !== 'undefined') {
142 InputMore.notched = InputLabelProps.shrink;
143 }
144 InputMore.label = label;
145 }
146 if (select) {
147 // unset defaults from textbox inputs
148 if (!SelectProps || !SelectProps.native) {
149 InputMore.id = undefined;
150 }
151 InputMore['aria-describedby'] = undefined;
152 }
153 var id = useId(idOverride);
154 var helperTextId = helperText && id ? "".concat(id, "-helper-text") : undefined;
155 var inputLabelId = label && id ? "".concat(id, "-label") : undefined;
156 var InputComponent = variantComponent[variant];
157 var InputElement = /*#__PURE__*/_jsx(InputComponent, _extends({
158 "aria-describedby": helperTextId,
159 autoComplete: autoComplete,
160 autoFocus: autoFocus,
161 defaultValue: defaultValue,
162 fullWidth: fullWidth,
163 multiline: multiline,
164 name: name,
165 rows: rows,
166 maxRows: maxRows,
167 minRows: minRows,
168 type: type,
169 value: value,
170 id: id,
171 inputRef: inputRef,
172 onBlur: onBlur,
173 onChange: onChange,
174 onFocus: onFocus,
175 placeholder: placeholder,
176 inputProps: inputProps
177 }, InputMore, InputProps));
178 return /*#__PURE__*/_jsxs(TextFieldRoot, _extends({
179 className: clsx(classes.root, className),
180 disabled: disabled,
181 error: error,
182 fullWidth: fullWidth,
183 ref: ref,
184 required: required,
185 color: color,
186 variant: variant,
187 ownerState: ownerState
188 }, other, {
189 children: [label != null && label !== '' && /*#__PURE__*/_jsx(InputLabel, _extends({
190 htmlFor: id,
191 id: inputLabelId
192 }, InputLabelProps, {
193 children: label
194 })), select ? /*#__PURE__*/_jsx(Select, _extends({
195 "aria-describedby": helperTextId,
196 id: id,
197 labelId: inputLabelId,
198 value: value,
199 input: InputElement
200 }, SelectProps, {
201 children: children
202 })) : InputElement, helperText && /*#__PURE__*/_jsx(FormHelperText, _extends({
203 id: helperTextId
204 }, FormHelperTextProps, {
205 children: helperText
206 }))]
207 }));
208});
209process.env.NODE_ENV !== "production" ? TextField.propTypes /* remove-proptypes */ = {
210 // ┌────────────────────────────── Warning ──────────────────────────────┐
211 // │ These PropTypes are generated from the TypeScript type definitions. │
212 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
213 // └─────────────────────────────────────────────────────────────────────┘
214 /**
215 * This prop helps users to fill forms faster, especially on mobile devices.
216 * The name can be confusing, as it's more like an autofill.
217 * You can learn more about it [following the specification](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill).
218 */
219 autoComplete: PropTypes.string,
220 /**
221 * If `true`, the `input` element is focused during the first mount.
222 * @default false
223 */
224 autoFocus: PropTypes.bool,
225 /**
226 * @ignore
227 */
228 children: PropTypes.node,
229 /**
230 * Override or extend the styles applied to the component.
231 */
232 classes: PropTypes.object,
233 /**
234 * @ignore
235 */
236 className: PropTypes.string,
237 /**
238 * The color of the component.
239 * It supports both default and custom theme colors, which can be added as shown in the
240 * [palette customization guide](https://mui.com/material-ui/customization/palette/#custom-colors).
241 * @default 'primary'
242 */
243 color: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['primary', 'secondary', 'error', 'info', 'success', 'warning']), PropTypes.string]),
244 /**
245 * The default value. Use when the component is not controlled.
246 */
247 defaultValue: PropTypes.any,
248 /**
249 * If `true`, the component is disabled.
250 * @default false
251 */
252 disabled: PropTypes.bool,
253 /**
254 * If `true`, the label is displayed in an error state.
255 * @default false
256 */
257 error: PropTypes.bool,
258 /**
259 * Props applied to the [`FormHelperText`](/material-ui/api/form-helper-text/) element.
260 */
261 FormHelperTextProps: PropTypes.object,
262 /**
263 * If `true`, the input will take up the full width of its container.
264 * @default false
265 */
266 fullWidth: PropTypes.bool,
267 /**
268 * The helper text content.
269 */
270 helperText: PropTypes.node,
271 /**
272 * The id of the `input` element.
273 * Use this prop to make `label` and `helperText` accessible for screen readers.
274 */
275 id: PropTypes.string,
276 /**
277 * Props applied to the [`InputLabel`](/material-ui/api/input-label/) element.
278 * Pointer events like `onClick` are enabled if and only if `shrink` is `true`.
279 */
280 InputLabelProps: PropTypes.object,
281 /**
282 * [Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Attributes) applied to the `input` element.
283 */
284 inputProps: PropTypes.object,
285 /**
286 * Props applied to the Input element.
287 * It will be a [`FilledInput`](/material-ui/api/filled-input/),
288 * [`OutlinedInput`](/material-ui/api/outlined-input/) or [`Input`](/material-ui/api/input/)
289 * component depending on the `variant` prop value.
290 */
291 InputProps: PropTypes.object,
292 /**
293 * Pass a ref to the `input` element.
294 */
295 inputRef: refType,
296 /**
297 * The label content.
298 */
299 label: PropTypes.node,
300 /**
301 * If `dense` or `normal`, will adjust vertical spacing of this and contained components.
302 * @default 'none'
303 */
304 margin: PropTypes.oneOf(['dense', 'none', 'normal']),
305 /**
306 * Maximum number of rows to display when multiline option is set to true.
307 */
308 maxRows: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
309 /**
310 * Minimum number of rows to display when multiline option is set to true.
311 */
312 minRows: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
313 /**
314 * If `true`, a `textarea` element is rendered instead of an input.
315 * @default false
316 */
317 multiline: PropTypes.bool,
318 /**
319 * Name attribute of the `input` element.
320 */
321 name: PropTypes.string,
322 /**
323 * @ignore
324 */
325 onBlur: PropTypes.func,
326 /**
327 * Callback fired when the value is changed.
328 *
329 * @param {object} event The event source of the callback.
330 * You can pull out the new value by accessing `event.target.value` (string).
331 */
332 onChange: PropTypes.func,
333 /**
334 * @ignore
335 */
336 onFocus: PropTypes.func,
337 /**
338 * The short hint displayed in the `input` before the user enters a value.
339 */
340 placeholder: PropTypes.string,
341 /**
342 * If `true`, the label is displayed as required and the `input` element is required.
343 * @default false
344 */
345 required: PropTypes.bool,
346 /**
347 * Number of rows to display when multiline option is set to true.
348 */
349 rows: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
350 /**
351 * Render a [`Select`](/material-ui/api/select/) element while passing the Input element to `Select` as `input` parameter.
352 * If this option is set you must pass the options of the select as children.
353 * @default false
354 */
355 select: PropTypes.bool,
356 /**
357 * Props applied to the [`Select`](/material-ui/api/select/) element.
358 */
359 SelectProps: PropTypes.object,
360 /**
361 * The size of the component.
362 */
363 size: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['medium', 'small']), PropTypes.string]),
364 /**
365 * The system prop that allows defining system overrides as well as additional CSS styles.
366 */
367 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
368 /**
369 * Type of the `input` element. It should be [a valid HTML5 input type](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Form_%3Cinput%3E_types).
370 */
371 type: PropTypes /* @typescript-to-proptypes-ignore */.string,
372 /**
373 * The value of the `input` element, required for a controlled component.
374 */
375 value: PropTypes.any,
376 /**
377 * The variant to use.
378 * @default 'outlined'
379 */
380 variant: PropTypes.oneOf(['filled', 'outlined', 'standard'])
381} : void 0;
382export default TextField;
\No newline at end of file