@material-ui/core
Version:
React components that implement Google's Material Design.
419 lines (352 loc) • 13.6 kB
JavaScript
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.styles = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var React = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _clsx = _interopRequireDefault(require("clsx"));
var _utils = require("@material-ui/utils");
var _deprecatedPropType = _interopRequireDefault(require("../utils/deprecatedPropType"));
var _Input = _interopRequireDefault(require("../Input"));
var _FilledInput = _interopRequireDefault(require("../FilledInput"));
var _OutlinedInput = _interopRequireDefault(require("../OutlinedInput"));
var _InputLabel = _interopRequireDefault(require("../InputLabel"));
var _FormControl = _interopRequireDefault(require("../FormControl"));
var _FormHelperText = _interopRequireDefault(require("../FormHelperText"));
var _Select = _interopRequireDefault(require("../Select"));
var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
var variantComponent = {
standard: _Input.default,
filled: _FilledInput.default,
outlined: _OutlinedInput.default
};
var styles = {
/* Styles applied to the root element. */
root: {}
};
/**
* The `TextField` is a convenience wrapper for the most common cases (80%).
* It cannot be all things to all people, otherwise the API would grow out of control.
*
* ## Advanced Configuration
*
* It's important to understand that the text field is a simple abstraction
* on top of the following components:
*
* - [FormControl](/api/form-control/)
* - [InputLabel](/api/input-label/)
* - [FilledInput](/api/filled-input/)
* - [OutlinedInput](/api/outlined-input/)
* - [Input](/api/input/)
* - [FormHelperText](/api/form-helper-text/)
*
* If you wish to alter the props applied to the `input` element, you can do so as follows:
*
* ```jsx
* const inputProps = {
* step: 300,
* };
*
* return <TextField id="time" type="time" inputProps={inputProps} />;
* ```
*
* For advanced cases, please look at the source of TextField by clicking on the
* "Edit this page" button above. Consider either:
*
* - using the upper case props for passing values directly to the components
* - using the underlying components directly as shown in the demos
*/
exports.styles = styles;
var TextField = /*#__PURE__*/React.forwardRef(function TextField(props, ref) {
var autoComplete = props.autoComplete,
_props$autoFocus = props.autoFocus,
autoFocus = _props$autoFocus === void 0 ? false : _props$autoFocus,
children = props.children,
classes = props.classes,
className = props.className,
_props$color = props.color,
color = _props$color === void 0 ? 'primary' : _props$color,
defaultValue = props.defaultValue,
_props$disabled = props.disabled,
disabled = _props$disabled === void 0 ? false : _props$disabled,
_props$error = props.error,
error = _props$error === void 0 ? false : _props$error,
FormHelperTextProps = props.FormHelperTextProps,
_props$fullWidth = props.fullWidth,
fullWidth = _props$fullWidth === void 0 ? false : _props$fullWidth,
helperText = props.helperText,
hiddenLabel = props.hiddenLabel,
id = props.id,
InputLabelProps = props.InputLabelProps,
inputProps = props.inputProps,
InputProps = props.InputProps,
inputRef = props.inputRef,
label = props.label,
_props$multiline = props.multiline,
multiline = _props$multiline === void 0 ? false : _props$multiline,
name = props.name,
onBlur = props.onBlur,
onChange = props.onChange,
onFocus = props.onFocus,
placeholder = props.placeholder,
_props$required = props.required,
required = _props$required === void 0 ? false : _props$required,
rows = props.rows,
rowsMax = props.rowsMax,
maxRows = props.maxRows,
minRows = props.minRows,
_props$select = props.select,
select = _props$select === void 0 ? false : _props$select,
SelectProps = props.SelectProps,
type = props.type,
value = props.value,
_props$variant = props.variant,
variant = _props$variant === void 0 ? 'standard' : _props$variant,
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"]);
if (process.env.NODE_ENV !== 'production') {
if (select && !children) {
console.error('Material-UI: `children` must be passed when using the `TextField` component with `select`.');
}
}
var InputMore = {};
if (variant === 'outlined') {
if (InputLabelProps && typeof InputLabelProps.shrink !== 'undefined') {
InputMore.notched = InputLabelProps.shrink;
}
if (label) {
var _InputLabelProps$requ;
var displayRequired = (_InputLabelProps$requ = InputLabelProps === null || InputLabelProps === void 0 ? void 0 : InputLabelProps.required) !== null && _InputLabelProps$requ !== void 0 ? _InputLabelProps$requ : required;
InputMore.label = /*#__PURE__*/React.createElement(React.Fragment, null, label, displayRequired && "\xA0*");
}
}
if (select) {
// unset defaults from textbox inputs
if (!SelectProps || !SelectProps.native) {
InputMore.id = undefined;
}
InputMore['aria-describedby'] = undefined;
}
var helperTextId = helperText && id ? "".concat(id, "-helper-text") : undefined;
var inputLabelId = label && id ? "".concat(id, "-label") : undefined;
var InputComponent = variantComponent[variant];
var InputElement = /*#__PURE__*/React.createElement(InputComponent, (0, _extends2.default)({
"aria-describedby": helperTextId,
autoComplete: autoComplete,
autoFocus: autoFocus,
defaultValue: defaultValue,
fullWidth: fullWidth,
multiline: multiline,
name: name,
rows: rows,
rowsMax: rowsMax,
maxRows: maxRows,
minRows: minRows,
type: type,
value: value,
id: id,
inputRef: inputRef,
onBlur: onBlur,
onChange: onChange,
onFocus: onFocus,
placeholder: placeholder,
inputProps: inputProps
}, InputMore, InputProps));
return /*#__PURE__*/React.createElement(_FormControl.default, (0, _extends2.default)({
className: (0, _clsx.default)(classes.root, className),
disabled: disabled,
error: error,
fullWidth: fullWidth,
hiddenLabel: hiddenLabel,
ref: ref,
required: required,
color: color,
variant: variant
}, other), label && /*#__PURE__*/React.createElement(_InputLabel.default, (0, _extends2.default)({
htmlFor: id,
id: inputLabelId
}, InputLabelProps), label), select ? /*#__PURE__*/React.createElement(_Select.default, (0, _extends2.default)({
"aria-describedby": helperTextId,
id: id,
labelId: inputLabelId,
value: value,
input: InputElement
}, SelectProps), children) : InputElement, helperText && /*#__PURE__*/React.createElement(_FormHelperText.default, (0, _extends2.default)({
id: helperTextId
}, FormHelperTextProps), helperText));
});
process.env.NODE_ENV !== "production" ? TextField.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the d.ts file and run "yarn proptypes" |
// ----------------------------------------------------------------------
/**
* This prop helps users to fill forms faster, especially on mobile devices.
* The name can be confusing, as it's more like an autofill.
* You can learn more about it [following the specification](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill).
*/
autoComplete: _propTypes.default.string,
/**
* If `true`, the `input` element will be focused during the first mount.
*/
autoFocus: _propTypes.default.bool,
/**
* @ignore
*/
children: _propTypes.default.node,
/**
* Override or extend the styles applied to the component.
* See [CSS API](#css) below for more details.
*/
classes: _propTypes.default.object,
/**
* @ignore
*/
className: _propTypes.default.string,
/**
* The color of the component. It supports those theme colors that make sense for this component.
*/
color: _propTypes.default.oneOf(['primary', 'secondary']),
/**
* The default value of the `input` element.
*/
defaultValue: _propTypes.default.any,
/**
* If `true`, the `input` element will be disabled.
*/
disabled: _propTypes.default.bool,
/**
* If `true`, the label will be displayed in an error state.
*/
error: _propTypes.default.bool,
/**
* Props applied to the [`FormHelperText`](/api/form-helper-text/) element.
*/
FormHelperTextProps: _propTypes.default.object,
/**
* If `true`, the input will take up the full width of its container.
*/
fullWidth: _propTypes.default.bool,
/**
* The helper text content.
*/
helperText: _propTypes.default.node,
/**
* @ignore
*/
hiddenLabel: _propTypes.default.bool,
/**
* The id of the `input` element.
* Use this prop to make `label` and `helperText` accessible for screen readers.
*/
id: _propTypes.default.string,
/**
* Props applied to the [`InputLabel`](/api/input-label/) element.
*/
InputLabelProps: _propTypes.default.object,
/**
* [Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Attributes) applied to the `input` element.
*/
inputProps: _propTypes.default.object,
/**
* Props applied to the Input element.
* It will be a [`FilledInput`](/api/filled-input/),
* [`OutlinedInput`](/api/outlined-input/) or [`Input`](/api/input/)
* component depending on the `variant` prop value.
*/
InputProps: _propTypes.default.object,
/**
* Pass a ref to the `input` element.
*/
inputRef: _utils.refType,
/**
* The label content.
*/
label: _propTypes.default.node,
/**
* If `dense` or `normal`, will adjust vertical spacing of this and contained components.
*/
margin: _propTypes.default.oneOf(['dense', 'none', 'normal']),
/**
* Maximum number of rows to display when multiline option is set to true.
*/
maxRows: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
/**
* Minimum number of rows to display.
*/
minRows: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
/**
* If `true`, a textarea element will be rendered instead of an input.
*/
multiline: _propTypes.default.bool,
/**
* Name attribute of the `input` element.
*/
name: _propTypes.default.string,
/**
* @ignore
*/
onBlur: _propTypes.default.func,
/**
* Callback fired when the value is changed.
*
* @param {object} event The event source of the callback.
* You can pull out the new value by accessing `event.target.value` (string).
*/
onChange: _propTypes.default.func,
/**
* @ignore
*/
onFocus: _propTypes.default.func,
/**
* The short hint displayed in the input before the user enters a value.
*/
placeholder: _propTypes.default.string,
/**
* If `true`, the label is displayed as required and the `input` element` will be required.
*/
required: _propTypes.default.bool,
/**
* Number of rows to display when multiline option is set to true.
* @deprecated Use `minRows` instead.
*/
rows: (0, _deprecatedPropType.default)(_propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]), 'Use `minRows` instead'),
/**
* Maximum number of rows to display.
* @deprecated Use `maxRows` instead.
*/
rowsMax: (0, _deprecatedPropType.default)(_propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]), 'Use `maxRows` instead'),
/**
* Render a [`Select`](/api/select/) element while passing the Input element to `Select` as `input` parameter.
* If this option is set you must pass the options of the select as children.
*/
select: _propTypes.default.bool,
/**
* Props applied to the [`Select`](/api/select/) element.
*/
SelectProps: _propTypes.default.object,
/**
* The size of the text field.
*/
size: _propTypes.default.oneOf(['medium', 'small']),
/**
* 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).
*/
type: _propTypes.default.string,
/**
* The value of the `input` element, required for a controlled component.
*/
value: _propTypes.default.any,
/**
* The variant to use.
*/
variant: _propTypes.default.oneOf(['filled', 'outlined', 'standard'])
} : void 0;
var _default = (0, _withStyles.default)(styles, {
name: 'MuiTextField'
})(TextField);
exports.default = _default;