UNPKG

13.3 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 _props$select = props.select,
121 select = _props$select === void 0 ? false : _props$select,
122 SelectProps = props.SelectProps,
123 type = props.type,
124 value = props.value,
125 _props$variant = props.variant,
126 variant = _props$variant === void 0 ? 'standard' : _props$variant,
127 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", "select", "SelectProps", "type", "value", "variant"]);
128
129 if (process.env.NODE_ENV !== 'production') {
130 if (select && !children) {
131 console.error('Material-UI: `children` must be passed when using the `TextField` component with `select`.');
132 }
133 }
134
135 var InputMore = {};
136
137 if (variant === 'outlined') {
138 if (InputLabelProps && typeof InputLabelProps.shrink !== 'undefined') {
139 InputMore.notched = InputLabelProps.shrink;
140 }
141
142 if (label) {
143 var _InputLabelProps$requ;
144
145 var displayRequired = (_InputLabelProps$requ = InputLabelProps === null || InputLabelProps === void 0 ? void 0 : InputLabelProps.required) !== null && _InputLabelProps$requ !== void 0 ? _InputLabelProps$requ : required;
146 InputMore.label = /*#__PURE__*/React.createElement(React.Fragment, null, label, displayRequired && "\xA0*");
147 }
148 }
149
150 if (select) {
151 // unset defaults from textbox inputs
152 if (!SelectProps || !SelectProps.native) {
153 InputMore.id = undefined;
154 }
155
156 InputMore['aria-describedby'] = undefined;
157 }
158
159 var helperTextId = helperText && id ? "".concat(id, "-helper-text") : undefined;
160 var inputLabelId = label && id ? "".concat(id, "-label") : undefined;
161 var InputComponent = variantComponent[variant];
162 var InputElement = /*#__PURE__*/React.createElement(InputComponent, (0, _extends2.default)({
163 "aria-describedby": helperTextId,
164 autoComplete: autoComplete,
165 autoFocus: autoFocus,
166 defaultValue: defaultValue,
167 fullWidth: fullWidth,
168 multiline: multiline,
169 name: name,
170 rows: rows,
171 rowsMax: rowsMax,
172 maxRows: maxRows,
173 type: type,
174 value: value,
175 id: id,
176 inputRef: inputRef,
177 onBlur: onBlur,
178 onChange: onChange,
179 onFocus: onFocus,
180 placeholder: placeholder,
181 inputProps: inputProps
182 }, InputMore, InputProps));
183 return /*#__PURE__*/React.createElement(_FormControl.default, (0, _extends2.default)({
184 className: (0, _clsx.default)(classes.root, className),
185 disabled: disabled,
186 error: error,
187 fullWidth: fullWidth,
188 hiddenLabel: hiddenLabel,
189 ref: ref,
190 required: required,
191 color: color,
192 variant: variant
193 }, other), label && /*#__PURE__*/React.createElement(_InputLabel.default, (0, _extends2.default)({
194 htmlFor: id,
195 id: inputLabelId
196 }, InputLabelProps), label), select ? /*#__PURE__*/React.createElement(_Select.default, (0, _extends2.default)({
197 "aria-describedby": helperTextId,
198 id: id,
199 labelId: inputLabelId,
200 value: value,
201 input: InputElement
202 }, SelectProps), children) : InputElement, helperText && /*#__PURE__*/React.createElement(_FormHelperText.default, (0, _extends2.default)({
203 id: helperTextId
204 }, FormHelperTextProps), helperText));
205});
206process.env.NODE_ENV !== "production" ? TextField.propTypes = {
207 // ----------------------------- Warning --------------------------------
208 // | These PropTypes are generated from the TypeScript type definitions |
209 // | To update them edit the d.ts file and run "yarn proptypes" |
210 // ----------------------------------------------------------------------
211
212 /**
213 * This prop helps users to fill forms faster, especially on mobile devices.
214 * The name can be confusing, as it's more like an autofill.
215 * You can learn more about it [following the specification](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill).
216 */
217 autoComplete: _propTypes.default.string,
218
219 /**
220 * If `true`, the `input` element will be focused during the first mount.
221 */
222 autoFocus: _propTypes.default.bool,
223
224 /**
225 * @ignore
226 */
227 children: _propTypes.default.node,
228
229 /**
230 * Override or extend the styles applied to the component.
231 * See [CSS API](#css) below for more details.
232 */
233 classes: _propTypes.default.object,
234
235 /**
236 * @ignore
237 */
238 className: _propTypes.default.string,
239
240 /**
241 * The color of the component. It supports those theme colors that make sense for this component.
242 */
243 color: _propTypes.default.oneOf(['primary', 'secondary']),
244
245 /**
246 * The default value of the `input` element.
247 */
248 defaultValue: _propTypes.default.any,
249
250 /**
251 * If `true`, the `input` element will be disabled.
252 */
253 disabled: _propTypes.default.bool,
254
255 /**
256 * If `true`, the label will be displayed in an error state.
257 */
258 error: _propTypes.default.bool,
259
260 /**
261 * Props applied to the [`FormHelperText`](/api/form-helper-text/) element.
262 */
263 FormHelperTextProps: _propTypes.default.object,
264
265 /**
266 * If `true`, the input will take up the full width of its container.
267 */
268 fullWidth: _propTypes.default.bool,
269
270 /**
271 * The helper text content.
272 */
273 helperText: _propTypes.default.node,
274
275 /**
276 * @ignore
277 */
278 hiddenLabel: _propTypes.default.bool,
279
280 /**
281 * The id of the `input` element.
282 * Use this prop to make `label` and `helperText` accessible for screen readers.
283 */
284 id: _propTypes.default.string,
285
286 /**
287 * Props applied to the [`InputLabel`](/api/input-label/) element.
288 */
289 InputLabelProps: _propTypes.default.object,
290
291 /**
292 * [Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Attributes) applied to the `input` element.
293 */
294 inputProps: _propTypes.default.object,
295
296 /**
297 * Props applied to the Input element.
298 * It will be a [`FilledInput`](/api/filled-input/),
299 * [`OutlinedInput`](/api/outlined-input/) or [`Input`](/api/input/)
300 * component depending on the `variant` prop value.
301 */
302 InputProps: _propTypes.default.object,
303
304 /**
305 * Pass a ref to the `input` element.
306 */
307 inputRef: _utils.refType,
308
309 /**
310 * The label content.
311 */
312 label: _propTypes.default.node,
313
314 /**
315 * If `dense` or `normal`, will adjust vertical spacing of this and contained components.
316 */
317 margin: _propTypes.default.oneOf(['dense', 'none', 'normal']),
318
319 /**
320 * Maximum number of rows to display when multiline option is set to true.
321 */
322 maxRows: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
323
324 /**
325 * If `true`, a textarea element will be rendered instead of an input.
326 */
327 multiline: _propTypes.default.bool,
328
329 /**
330 * Name attribute of the `input` element.
331 */
332 name: _propTypes.default.string,
333
334 /**
335 * @ignore
336 */
337 onBlur: _propTypes.default.func,
338
339 /**
340 * Callback fired when the value is changed.
341 *
342 * @param {object} event The event source of the callback.
343 * You can pull out the new value by accessing `event.target.value` (string).
344 */
345 onChange: _propTypes.default.func,
346
347 /**
348 * @ignore
349 */
350 onFocus: _propTypes.default.func,
351
352 /**
353 * The short hint displayed in the input before the user enters a value.
354 */
355 placeholder: _propTypes.default.string,
356
357 /**
358 * If `true`, the label is displayed as required and the `input` element` will be required.
359 */
360 required: _propTypes.default.bool,
361
362 /**
363 * Number of rows to display when multiline option is set to true.
364 */
365 rows: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
366
367 /**
368 * Maximum number of rows to display.
369 * @deprecated Use `maxRows` instead.
370 */
371 rowsMax: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
372
373 /**
374 * Render a [`Select`](/api/select/) element while passing the Input element to `Select` as `input` parameter.
375 * If this option is set you must pass the options of the select as children.
376 */
377 select: _propTypes.default.bool,
378
379 /**
380 * Props applied to the [`Select`](/api/select/) element.
381 */
382 SelectProps: _propTypes.default.object,
383
384 /**
385 * The size of the text field.
386 */
387 size: _propTypes.default.oneOf(['medium', 'small']),
388
389 /**
390 * 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).
391 */
392 type: _propTypes.default.string,
393
394 /**
395 * The value of the `input` element, required for a controlled component.
396 */
397 value: _propTypes.default.any,
398
399 /**
400 * The variant to use.
401 */
402 variant: _propTypes.default.oneOf(['filled', 'outlined', 'standard'])
403} : void 0;
404
405var _default = (0, _withStyles.default)(styles, {
406 name: 'MuiTextField'
407})(TextField);
408
409exports.default = _default;
\No newline at end of file