1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import clsx from 'clsx';
|
6 | import { refType } from '@material-ui/utils';
|
7 | import Input from '../Input';
|
8 | import FilledInput from '../FilledInput';
|
9 | import OutlinedInput from '../OutlinedInput';
|
10 | import InputLabel from '../InputLabel';
|
11 | import FormControl from '../FormControl';
|
12 | import FormHelperText from '../FormHelperText';
|
13 | import Select from '../Select';
|
14 | import withStyles from '../styles/withStyles';
|
15 | const variantComponent = {
|
16 | standard: Input,
|
17 | filled: FilledInput,
|
18 | outlined: OutlinedInput
|
19 | };
|
20 | export const styles = {
|
21 |
|
22 | root: {}
|
23 | };
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | const TextField = React.forwardRef(function TextField(props, ref) {
|
58 | const {
|
59 | autoComplete,
|
60 | autoFocus = false,
|
61 | children,
|
62 | classes,
|
63 | className,
|
64 | color = 'primary',
|
65 | defaultValue,
|
66 | disabled = false,
|
67 | error = false,
|
68 | FormHelperTextProps,
|
69 | fullWidth = false,
|
70 | helperText,
|
71 | hiddenLabel,
|
72 | id,
|
73 | InputLabelProps,
|
74 | inputProps,
|
75 | InputProps,
|
76 | inputRef,
|
77 | label,
|
78 | multiline = false,
|
79 | name,
|
80 | onBlur,
|
81 | onChange,
|
82 | onFocus,
|
83 | placeholder,
|
84 | required = false,
|
85 | rows,
|
86 | rowsMax,
|
87 | maxRows,
|
88 | minRows,
|
89 | select = false,
|
90 | SelectProps,
|
91 | type,
|
92 | value,
|
93 | variant = 'standard'
|
94 | } = props,
|
95 | other = _objectWithoutPropertiesLoose(props, ["autoComplete", "autoFocus", "children", "classes", "className", "color", "defaultValue", "disabled", "error", "FormHelperTextProps", "fullWidth", "helperText", "hiddenLabel", "id", "InputLabelProps", "inputProps", "InputProps", "inputRef", "label", "multiline", "name", "onBlur", "onChange", "onFocus", "placeholder", "required", "rows", "rowsMax", "maxRows", "minRows", "select", "SelectProps", "type", "value", "variant"]);
|
96 |
|
97 | if (process.env.NODE_ENV !== 'production') {
|
98 | if (select && !children) {
|
99 | console.error('Material-UI: `children` must be passed when using the `TextField` component with `select`.');
|
100 | }
|
101 | }
|
102 |
|
103 | const InputMore = {};
|
104 |
|
105 | if (variant === 'outlined') {
|
106 | if (InputLabelProps && typeof InputLabelProps.shrink !== 'undefined') {
|
107 | InputMore.notched = InputLabelProps.shrink;
|
108 | }
|
109 |
|
110 | if (label) {
|
111 | const displayRequired = InputLabelProps?.required ?? required;
|
112 | InputMore.label = React.createElement(React.Fragment, null, label, displayRequired && '\u00a0*');
|
113 | }
|
114 | }
|
115 |
|
116 | if (select) {
|
117 |
|
118 | if (!SelectProps || !SelectProps.native) {
|
119 | InputMore.id = undefined;
|
120 | }
|
121 |
|
122 | InputMore['aria-describedby'] = undefined;
|
123 | }
|
124 |
|
125 | const helperTextId = helperText && id ? `${id}-helper-text` : undefined;
|
126 | const inputLabelId = label && id ? `${id}-label` : undefined;
|
127 | const InputComponent = variantComponent[variant];
|
128 | const InputElement = React.createElement(InputComponent, _extends({
|
129 | "aria-describedby": helperTextId,
|
130 | autoComplete: autoComplete,
|
131 | autoFocus: autoFocus,
|
132 | defaultValue: defaultValue,
|
133 | fullWidth: fullWidth,
|
134 | multiline: multiline,
|
135 | name: name,
|
136 | rows: rows,
|
137 | rowsMax: rowsMax,
|
138 | maxRows: maxRows,
|
139 | minRows: minRows,
|
140 | type: type,
|
141 | value: value,
|
142 | id: id,
|
143 | inputRef: inputRef,
|
144 | onBlur: onBlur,
|
145 | onChange: onChange,
|
146 | onFocus: onFocus,
|
147 | placeholder: placeholder,
|
148 | inputProps: inputProps
|
149 | }, InputMore, InputProps));
|
150 | return React.createElement(FormControl, _extends({
|
151 | className: clsx(classes.root, className),
|
152 | disabled: disabled,
|
153 | error: error,
|
154 | fullWidth: fullWidth,
|
155 | hiddenLabel: hiddenLabel,
|
156 | ref: ref,
|
157 | required: required,
|
158 | color: color,
|
159 | variant: variant
|
160 | }, other), label && React.createElement(InputLabel, _extends({
|
161 | htmlFor: id,
|
162 | id: inputLabelId
|
163 | }, InputLabelProps), label), select ? React.createElement(Select, _extends({
|
164 | "aria-describedby": helperTextId,
|
165 | id: id,
|
166 | labelId: inputLabelId,
|
167 | value: value,
|
168 | input: InputElement
|
169 | }, SelectProps), children) : InputElement, helperText && React.createElement(FormHelperText, _extends({
|
170 | id: helperTextId
|
171 | }, FormHelperTextProps), helperText));
|
172 | });
|
173 | process.env.NODE_ENV !== "production" ? TextField.propTypes = {
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 | |
180 |
|
181 |
|
182 |
|
183 |
|
184 | autoComplete: PropTypes.string,
|
185 |
|
186 | |
187 |
|
188 |
|
189 | autoFocus: PropTypes.bool,
|
190 |
|
191 | |
192 |
|
193 |
|
194 | children: PropTypes.node,
|
195 |
|
196 | |
197 |
|
198 |
|
199 |
|
200 | classes: PropTypes.object,
|
201 |
|
202 | |
203 |
|
204 |
|
205 | className: PropTypes.string,
|
206 |
|
207 | |
208 |
|
209 |
|
210 | color: PropTypes.oneOf(['primary', 'secondary']),
|
211 |
|
212 | |
213 |
|
214 |
|
215 | defaultValue: PropTypes.any,
|
216 |
|
217 | |
218 |
|
219 |
|
220 | disabled: PropTypes.bool,
|
221 |
|
222 | |
223 |
|
224 |
|
225 | error: PropTypes.bool,
|
226 |
|
227 | |
228 |
|
229 |
|
230 | FormHelperTextProps: PropTypes.object,
|
231 |
|
232 | |
233 |
|
234 |
|
235 | fullWidth: PropTypes.bool,
|
236 |
|
237 | |
238 |
|
239 |
|
240 | helperText: PropTypes.node,
|
241 |
|
242 | |
243 |
|
244 |
|
245 | hiddenLabel: PropTypes.bool,
|
246 |
|
247 | |
248 |
|
249 |
|
250 |
|
251 | id: PropTypes.string,
|
252 |
|
253 | |
254 |
|
255 |
|
256 | InputLabelProps: PropTypes.object,
|
257 |
|
258 | |
259 |
|
260 |
|
261 | inputProps: PropTypes.object,
|
262 |
|
263 | |
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 | InputProps: PropTypes.object,
|
270 |
|
271 | |
272 |
|
273 |
|
274 | inputRef: refType,
|
275 |
|
276 | |
277 |
|
278 |
|
279 | label: PropTypes.node,
|
280 |
|
281 | |
282 |
|
283 |
|
284 | margin: PropTypes.oneOf(['dense', 'none', 'normal']),
|
285 |
|
286 | |
287 |
|
288 |
|
289 | maxRows: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
290 |
|
291 | |
292 |
|
293 |
|
294 | minRows: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
295 |
|
296 | |
297 |
|
298 |
|
299 | multiline: PropTypes.bool,
|
300 |
|
301 | |
302 |
|
303 |
|
304 | name: PropTypes.string,
|
305 |
|
306 | |
307 |
|
308 |
|
309 | onBlur: PropTypes.func,
|
310 |
|
311 | |
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 | onChange: PropTypes.func,
|
318 |
|
319 | |
320 |
|
321 |
|
322 | onFocus: PropTypes.func,
|
323 |
|
324 | |
325 |
|
326 |
|
327 | placeholder: PropTypes.string,
|
328 |
|
329 | |
330 |
|
331 |
|
332 | required: PropTypes.bool,
|
333 |
|
334 | |
335 |
|
336 |
|
337 |
|
338 | rows: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
339 |
|
340 | |
341 |
|
342 |
|
343 |
|
344 | rowsMax: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
345 |
|
346 | |
347 |
|
348 |
|
349 |
|
350 | select: PropTypes.bool,
|
351 |
|
352 | |
353 |
|
354 |
|
355 | SelectProps: PropTypes.object,
|
356 |
|
357 | |
358 |
|
359 |
|
360 | size: PropTypes.oneOf(['medium', 'small']),
|
361 |
|
362 | |
363 |
|
364 |
|
365 | type: PropTypes.string,
|
366 |
|
367 | |
368 |
|
369 |
|
370 | value: PropTypes.any,
|
371 |
|
372 | |
373 |
|
374 |
|
375 | variant: PropTypes.oneOf(['filled', 'outlined', 'standard'])
|
376 | } : void 0;
|
377 | export default withStyles(styles, {
|
378 | name: 'MuiTextField'
|
379 | })(TextField); |
\ | No newline at end of file |