UNPKG

13.4 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
5var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
7Object.defineProperty(exports, "__esModule", {
8 value: true
9});
10exports.default = exports.styles = void 0;
11
12var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
14var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
15
16var React = _interopRequireWildcard(require("react"));
17
18var _propTypes = _interopRequireDefault(require("prop-types"));
19
20var _clsx = _interopRequireDefault(require("clsx"));
21
22var _utils = require("@material-ui/utils");
23
24var _Input = _interopRequireDefault(require("../Input"));
25
26var _FilledInput = _interopRequireDefault(require("../FilledInput"));
27
28var _OutlinedInput = _interopRequireDefault(require("../OutlinedInput"));
29
30var _InputLabel = _interopRequireDefault(require("../InputLabel"));
31
32var _FormControl = _interopRequireDefault(require("../FormControl"));
33
34var _FormHelperText = _interopRequireDefault(require("../FormHelperText"));
35
36var _Select = _interopRequireDefault(require("../Select"));
37
38var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
39
40var variantComponent = {
41 standard: _Input.default,
42 filled: _FilledInput.default,
43 outlined: _OutlinedInput.default
44};
45var styles = {
46 /* Styles applied to the root element. */
47 root: {}
48};
49/**
50 * The `TextField` is a convenience wrapper for the most common cases (80%).
51 * It cannot be all things to all people, otherwise the API would grow out of control.
52 *
53 * ## Advanced Configuration
54 *
55 * It's important to understand that the text field is a simple abstraction
56 * on top of the following components:
57 *
58 * - [FormControl](/api/form-control/)
59 * - [InputLabel](/api/input-label/)
60 * - [FilledInput](/api/filled-input/)
61 * - [OutlinedInput](/api/outlined-input/)
62 * - [Input](/api/input/)
63 * - [FormHelperText](/api/form-helper-text/)
64 *
65 * If you wish to alter the props applied to the `input` element, you can do so as follows:
66 *
67 * ```jsx
68 * const inputProps = {
69 * step: 300,
70 * };
71 *
72 * return <TextField id="time" type="time" inputProps={inputProps} />;
73 * ```
74 *
75 * For advanced cases, please look at the source of TextField by clicking on the
76 * "Edit this page" button above. Consider either:
77 *
78 * - using the upper case props for passing values directly to the components
79 * - using the underlying components directly as shown in the demos
80 */
81
82exports.styles = styles;
83var TextField = /*#__PURE__*/React.forwardRef(function TextField(props, ref) {
84 var autoComplete = props.autoComplete,
85 _props$autoFocus = props.autoFocus,
86 autoFocus = _props$autoFocus === void 0 ? false : _props$autoFocus,
87 children = props.children,
88 classes = props.classes,
89 className = props.className,
90 _props$color = props.color,
91 color = _props$color === void 0 ? 'primary' : _props$color,
92 defaultValue = props.defaultValue,
93 _props$disabled = props.disabled,
94 disabled = _props$disabled === void 0 ? false : _props$disabled,
95 _props$error = props.error,
96 error = _props$error === void 0 ? false : _props$error,
97 FormHelperTextProps = props.FormHelperTextProps,
98 _props$fullWidth = props.fullWidth,
99 fullWidth = _props$fullWidth === void 0 ? false : _props$fullWidth,
100 helperText = props.helperText,
101 hiddenLabel = props.hiddenLabel,
102 id = props.id,
103 InputLabelProps = props.InputLabelProps,
104 inputProps = props.inputProps,
105 InputProps = props.InputProps,
106 inputRef = props.inputRef,
107 label = props.label,
108 _props$multiline = props.multiline,
109 multiline = _props$multiline === void 0 ? false : _props$multiline,
110 name = props.name,
111 onBlur = props.onBlur,
112 onChange = props.onChange,
113 onFocus = props.onFocus,
114 placeholder = props.placeholder,
115 _props$required = props.required,
116 required = _props$required === void 0 ? false : _props$required,
117 rows = props.rows,
118 rowsMax = props.rowsMax,
119 maxRows = props.maxRows,
120 minRows = props.minRows,
121 _props$select = props.select,
122 select = _props$select === void 0 ? false : _props$select,
123 SelectProps = props.SelectProps,
124 type = props.type,
125 value = props.value,
126 _props$variant = props.variant,
127 variant = _props$variant === void 0 ? 'standard' : _props$variant,
128 other = (0, _objectWithoutProperties2.default)(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"]);
129
130 if (process.env.NODE_ENV !== 'production') {
131 if (select && !children) {
132 console.error('Material-UI: `children` must be passed when using the `TextField` component with `select`.');
133 }
134 }
135
136 var InputMore = {};
137
138 if (variant === 'outlined') {
139 if (InputLabelProps && typeof InputLabelProps.shrink !== 'undefined') {
140 InputMore.notched = InputLabelProps.shrink;
141 }
142
143 if (label) {
144 var _InputLabelProps$requ;
145
146 var displayRequired = (_InputLabelProps$requ = InputLabelProps === null || InputLabelProps === void 0 ? void 0 : InputLabelProps.required) !== null && _InputLabelProps$requ !== void 0 ? _InputLabelProps$requ : required;
147 InputMore.label = /*#__PURE__*/React.createElement(React.Fragment, null, label, displayRequired && "\xA0*");
148 }
149 }
150
151 if (select) {
152 // unset defaults from textbox inputs
153 if (!SelectProps || !SelectProps.native) {
154 InputMore.id = undefined;
155 }
156
157 InputMore['aria-describedby'] = undefined;
158 }
159
160 var helperTextId = helperText && id ? "".concat(id, "-helper-text") : undefined;
161 var inputLabelId = label && id ? "".concat(id, "-label") : undefined;
162 var InputComponent = variantComponent[variant];
163 var InputElement = /*#__PURE__*/React.createElement(InputComponent, (0, _extends2.default)({
164 "aria-describedby": helperTextId,
165 autoComplete: autoComplete,
166 autoFocus: autoFocus,
167 defaultValue: defaultValue,
168 fullWidth: fullWidth,
169 multiline: multiline,
170 name: name,
171 rows: rows,
172 rowsMax: rowsMax,
173 maxRows: maxRows,
174 minRows: minRows,
175 type: type,
176 value: value,
177 id: id,
178 inputRef: inputRef,
179 onBlur: onBlur,
180 onChange: onChange,
181 onFocus: onFocus,
182 placeholder: placeholder,
183 inputProps: inputProps
184 }, InputMore, InputProps));
185 return /*#__PURE__*/React.createElement(_FormControl.default, (0, _extends2.default)({
186 className: (0, _clsx.default)(classes.root, className),
187 disabled: disabled,
188 error: error,
189 fullWidth: fullWidth,
190 hiddenLabel: hiddenLabel,
191 ref: ref,
192 required: required,
193 color: color,
194 variant: variant
195 }, other), label && /*#__PURE__*/React.createElement(_InputLabel.default, (0, _extends2.default)({
196 htmlFor: id,
197 id: inputLabelId
198 }, InputLabelProps), label), select ? /*#__PURE__*/React.createElement(_Select.default, (0, _extends2.default)({
199 "aria-describedby": helperTextId,
200 id: id,
201 labelId: inputLabelId,
202 value: value,
203 input: InputElement
204 }, SelectProps), children) : InputElement, helperText && /*#__PURE__*/React.createElement(_FormHelperText.default, (0, _extends2.default)({
205 id: helperTextId
206 }, FormHelperTextProps), helperText));
207});
208process.env.NODE_ENV !== "production" ? TextField.propTypes = {
209 // ----------------------------- Warning --------------------------------
210 // | These PropTypes are generated from the TypeScript type definitions |
211 // | To update them edit the d.ts file and run "yarn proptypes" |
212 // ----------------------------------------------------------------------
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.default.string,
220
221 /**
222 * If `true`, the `input` element will be focused during the first mount.
223 */
224 autoFocus: _propTypes.default.bool,
225
226 /**
227 * @ignore
228 */
229 children: _propTypes.default.node,
230
231 /**
232 * Override or extend the styles applied to the component.
233 * See [CSS API](#css) below for more details.
234 */
235 classes: _propTypes.default.object,
236
237 /**
238 * @ignore
239 */
240 className: _propTypes.default.string,
241
242 /**
243 * The color of the component. It supports those theme colors that make sense for this component.
244 */
245 color: _propTypes.default.oneOf(['primary', 'secondary']),
246
247 /**
248 * The default value of the `input` element.
249 */
250 defaultValue: _propTypes.default.any,
251
252 /**
253 * If `true`, the `input` element will be disabled.
254 */
255 disabled: _propTypes.default.bool,
256
257 /**
258 * If `true`, the label will be displayed in an error state.
259 */
260 error: _propTypes.default.bool,
261
262 /**
263 * Props applied to the [`FormHelperText`](/api/form-helper-text/) element.
264 */
265 FormHelperTextProps: _propTypes.default.object,
266
267 /**
268 * If `true`, the input will take up the full width of its container.
269 */
270 fullWidth: _propTypes.default.bool,
271
272 /**
273 * The helper text content.
274 */
275 helperText: _propTypes.default.node,
276
277 /**
278 * @ignore
279 */
280 hiddenLabel: _propTypes.default.bool,
281
282 /**
283 * The id of the `input` element.
284 * Use this prop to make `label` and `helperText` accessible for screen readers.
285 */
286 id: _propTypes.default.string,
287
288 /**
289 * Props applied to the [`InputLabel`](/api/input-label/) element.
290 */
291 InputLabelProps: _propTypes.default.object,
292
293 /**
294 * [Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Attributes) applied to the `input` element.
295 */
296 inputProps: _propTypes.default.object,
297
298 /**
299 * Props applied to the Input element.
300 * It will be a [`FilledInput`](/api/filled-input/),
301 * [`OutlinedInput`](/api/outlined-input/) or [`Input`](/api/input/)
302 * component depending on the `variant` prop value.
303 */
304 InputProps: _propTypes.default.object,
305
306 /**
307 * Pass a ref to the `input` element.
308 */
309 inputRef: _utils.refType,
310
311 /**
312 * The label content.
313 */
314 label: _propTypes.default.node,
315
316 /**
317 * If `dense` or `normal`, will adjust vertical spacing of this and contained components.
318 */
319 margin: _propTypes.default.oneOf(['dense', 'none', 'normal']),
320
321 /**
322 * Maximum number of rows to display when multiline option is set to true.
323 */
324 maxRows: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
325
326 /**
327 * Minimum number of rows to display.
328 */
329 minRows: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
330
331 /**
332 * If `true`, a textarea element will be rendered instead of an input.
333 */
334 multiline: _propTypes.default.bool,
335
336 /**
337 * Name attribute of the `input` element.
338 */
339 name: _propTypes.default.string,
340
341 /**
342 * @ignore
343 */
344 onBlur: _propTypes.default.func,
345
346 /**
347 * Callback fired when the value is changed.
348 *
349 * @param {object} event The event source of the callback.
350 * You can pull out the new value by accessing `event.target.value` (string).
351 */
352 onChange: _propTypes.default.func,
353
354 /**
355 * @ignore
356 */
357 onFocus: _propTypes.default.func,
358
359 /**
360 * The short hint displayed in the input before the user enters a value.
361 */
362 placeholder: _propTypes.default.string,
363
364 /**
365 * If `true`, the label is displayed as required and the `input` element` will be required.
366 */
367 required: _propTypes.default.bool,
368
369 /**
370 * Number of rows to display when multiline option is set to true.
371 * @deprecated Use `minRows` instead.
372 */
373 rows: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
374
375 /**
376 * Maximum number of rows to display.
377 * @deprecated Use `maxRows` instead.
378 */
379 rowsMax: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
380
381 /**
382 * Render a [`Select`](/api/select/) element while passing the Input element to `Select` as `input` parameter.
383 * If this option is set you must pass the options of the select as children.
384 */
385 select: _propTypes.default.bool,
386
387 /**
388 * Props applied to the [`Select`](/api/select/) element.
389 */
390 SelectProps: _propTypes.default.object,
391
392 /**
393 * The size of the text field.
394 */
395 size: _propTypes.default.oneOf(['medium', 'small']),
396
397 /**
398 * 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).
399 */
400 type: _propTypes.default.string,
401
402 /**
403 * The value of the `input` element, required for a controlled component.
404 */
405 value: _propTypes.default.any,
406
407 /**
408 * The variant to use.
409 */
410 variant: _propTypes.default.oneOf(['filled', 'outlined', 'standard'])
411} : void 0;
412
413var _default = (0, _withStyles.default)(styles, {
414 name: 'MuiTextField'
415})(TextField);
416
417exports.default = _default;
\No newline at end of file