@material-ui/core
Version:
React components that implement Google's Material Design.
314 lines (259 loc) • 9.42 kB
JavaScript
"use strict";
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 = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _classnames = _interopRequireDefault(require("classnames"));
var _InputBase = _interopRequireDefault(require("../InputBase"));
var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
// @inheritedComponent InputBase
var styles = function styles(theme) {
var light = theme.palette.type === 'light';
var bottomLineColor = light ? 'rgba(0, 0, 0, 0.42)' : 'rgba(255, 255, 255, 0.7)';
return {
/* Styles applied to the root element. */
root: {
position: 'relative',
backgroundColor: light ? 'rgba(0, 0, 0, 0.09)' : 'rgba(255, 255, 255, 0.09)',
borderTopLeftRadius: theme.shape.borderRadius,
borderTopRightRadius: theme.shape.borderRadius,
transition: theme.transitions.create('background-color', {
duration: theme.transitions.duration.shorter,
easing: theme.transitions.easing.easeOut
}),
'&:hover': {
backgroundColor: light ? 'rgba(0, 0, 0, 0.13)' : 'rgba(255, 255, 255, 0.13)'
},
'&$focused': {
backgroundColor: light ? 'rgba(0, 0, 0, 0.09)' : 'rgba(255, 255, 255, 0.09)'
},
'&$disabled': {
backgroundColor: light ? 'rgba(0, 0, 0, 0.12)' : 'rgba(255, 255, 255, 0.12)'
}
},
/* Styles applied to the root element. */
underline: {
'&:after': {
borderBottom: "2px solid ".concat(theme.palette.primary[light ? 'dark' : 'light']),
left: 0,
bottom: 0,
// Doing the other way around crash on IE11 "''" https://github.com/cssinjs/jss/issues/242
content: '""',
position: 'absolute',
right: 0,
transform: 'scaleX(0)',
transition: theme.transitions.create('transform', {
duration: theme.transitions.duration.shorter,
easing: theme.transitions.easing.easeOut
}),
pointerEvents: 'none' // Transparent to the hover style.
},
'&$focused:after': {
transform: 'scaleX(1)'
},
'&$error:after': {
borderBottomColor: theme.palette.error.main,
transform: 'scaleX(1)' // error is always underlined in red
},
'&:before': {
borderBottom: "1px solid ".concat(bottomLineColor),
left: 0,
bottom: 0,
// Doing the other way around crash on IE11 "''" https://github.com/cssinjs/jss/issues/242
content: '"\\00a0"',
position: 'absolute',
right: 0,
transition: theme.transitions.create('border-bottom-color', {
duration: theme.transitions.duration.shorter
}),
pointerEvents: 'none' // Transparent to the hover style.
},
'&:hover:not($disabled):not($focused):not($error):before': {
borderBottom: "1px solid ".concat(theme.palette.text.primary)
},
'&$disabled:before': {
borderBottom: "1px dotted ".concat(bottomLineColor)
}
},
/* Styles applied to the root element if the component is focused. */
focused: {},
/* Styles applied to the root element if `disabled={true}`. */
disabled: {},
/* Styles applied to the root element if `startAdornment` is provided. */
adornedStart: {
paddingLeft: 12
},
/* Styles applied to the root element if `endAdornment` is provided. */
adornedEnd: {
paddingRight: 12
},
/* Styles applied to the root element if `error={true}`. */
error: {},
/* Styles applied to the root element if `multiline={true}`. */
multiline: {
padding: '27px 12px 10px',
boxSizing: 'border-box' // Prevent padding issue with fullWidth.
},
/* Styles applied to the `input` element. */
input: {
padding: '27px 12px 10px'
},
/* Styles applied to the `input` element if `margin="dense"`. */
inputMarginDense: {
paddingTop: 24,
paddingBottom: 6
},
/* Styles applied to the `input` element if `multiline={true}`. */
inputMultiline: {
padding: 0
},
/* Styles applied to the `input` element if `startAdornment` is provided. */
inputAdornedStart: {
paddingLeft: 0
},
/* Styles applied to the `input` element if `endAdornment` is provided. */
inputAdornedEnd: {
paddingRight: 0
}
};
};
exports.styles = styles;
function FilledInput(props) {
var classes = props.classes,
other = (0, _objectWithoutProperties2.default)(props, ["classes"]);
return _react.default.createElement(_InputBase.default, (0, _extends2.default)({
classes: (0, _extends2.default)({}, classes, {
root: (0, _classnames.default)(classes.root, classes.underline, {}),
underline: null
})
}, other));
}
FilledInput.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* This property 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 here:
* https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill
*/
autoComplete: _propTypes.default.string,
/**
* If `true`, the input will be focused during the first mount.
*/
autoFocus: _propTypes.default.bool,
/**
* Override or extend the styles applied to the component.
* See [CSS API](#css-api) below for more details.
*/
classes: _propTypes.default.object.isRequired,
/**
* The CSS class name of the wrapper element.
*/
className: _propTypes.default.string,
/**
* The default input value, useful when not controlling the component.
*/
defaultValue: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
/**
* If `true`, the input will be disabled.
*/
disabled: _propTypes.default.bool,
/**
* End `InputAdornment` for this component.
*/
endAdornment: _propTypes.default.node,
/**
* If `true`, the input will indicate an error. This is normally obtained via context from
* FormControl.
*/
error: _propTypes.default.bool,
/**
* If `true`, the input will take up the full width of its container.
*/
fullWidth: _propTypes.default.bool,
/**
* The id of the `input` element.
*/
id: _propTypes.default.string,
/**
* The component used for the native input.
* Either a string to use a DOM element or a component.
*/
inputComponent: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.func, _propTypes.default.object]),
/**
* Attributes applied to the `input` element.
*/
inputProps: _propTypes.default.object,
/**
* Use that property to pass a ref callback to the native input component.
*/
inputRef: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object]),
/**
* If `dense`, will adjust vertical spacing. This is normally obtained via context from
* FormControl.
*/
margin: _propTypes.default.oneOf(['dense', 'none']),
/**
* If `true`, a textarea element will be rendered.
*/
multiline: _propTypes.default.bool,
/**
* Name attribute of the `input` element.
*/
name: _propTypes.default.string,
/**
* 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`.
*/
onChange: _propTypes.default.func,
/**
* The short hint displayed in the input before the user enters a value.
*/
placeholder: _propTypes.default.string,
/**
* It prevents the user from changing the value of the field
* (not from interacting with the field).
*/
readOnly: _propTypes.default.bool,
/**
* If `true`, the input will be required.
*/
required: _propTypes.default.bool,
/**
* Number of rows to display when multiline option is set to true.
*/
rows: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
/**
* Maximum number of rows to display when multiline option is set to true.
*/
rowsMax: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
/**
* Start `InputAdornment` for this component.
*/
startAdornment: _propTypes.default.node,
/**
* Type of the input element. It should be a valid HTML5 input type.
*/
type: _propTypes.default.string,
/**
* The input value, required for a controlled component.
*/
value: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number, _propTypes.default.bool, _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number, _propTypes.default.bool]))])
} : {};
_InputBase.default.defaultProps = {
fullWidth: false,
inputComponent: 'input',
multiline: false,
type: 'text'
};
FilledInput.muiName = 'Input';
var _default = (0, _withStyles.default)(styles, {
name: 'MuiFilledInput'
})(FilledInput);
exports.default = _default;