@material-ui/core
Version:
React components that implement Google's Material Design.
230 lines (187 loc) • 7.29 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 _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
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 _formControlState = _interopRequireDefault(require("../FormControl/formControlState"));
var _withFormControlContext = _interopRequireDefault(require("../FormControl/withFormControlContext"));
var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
var _FormLabel = _interopRequireDefault(require("../FormLabel"));
// @inheritedComponent FormLabel
var styles = function styles(theme) {
return {
/* Styles applied to the root element. */
root: {
transformOrigin: 'top left'
},
/* Styles applied to the root element if `focused={true}`. */
focused: {},
/* Styles applied to the root element if `disabled={true}`. */
disabled: {},
/* Styles applied to the root element if `error={true}`. */
error: {},
/* Styles applied to the root element if `required={true}`. */
required: {},
/* Styles applied to the root element if the component is a descendant of `FormControl`. */
formControl: {
position: 'absolute',
left: 0,
top: 0,
// slight alteration to spec spacing to match visual spec result
transform: 'translate(0, 24px) scale(1)'
},
/* Styles applied to the root element if `margin="dense"`. */
marginDense: {
// Compensation for the `Input.inputDense` style.
transform: 'translate(0, 21px) scale(1)'
},
/* Styles applied to the `input` element if `shrink={true}`. */
shrink: {
transform: 'translate(0, 1.5px) scale(0.75)',
transformOrigin: 'top left'
},
/* Styles applied to the `input` element if `disableAnimation={false}`. */
animated: {
transition: theme.transitions.create(['color', 'transform'], {
duration: theme.transitions.duration.shorter,
easing: theme.transitions.easing.easeOut
})
},
/* Styles applied to the root element if `variant="filled"`. */
filled: {
// Chrome's autofill feature gives the input field a yellow background.
// Since the input field is behind the label in the HTML tree,
// the input field is drawn last and hides the label with an opaque background color.
// zIndex: 1 will raise the label above opaque background-colors of input.
zIndex: 1,
pointerEvents: 'none',
transform: 'translate(12px, 20px) scale(1)',
'&$marginDense': {
transform: 'translate(12px, 17px) scale(1)'
},
'&$shrink': {
transform: 'translate(12px, 10px) scale(0.75)',
'&$marginDense': {
transform: 'translate(12px, 7px) scale(0.75)'
}
}
},
/* Styles applied to the root element if `variant="outlined"`. */
outlined: {
// see comment above on filled.zIndex
zIndex: 1,
pointerEvents: 'none',
transform: 'translate(14px, 20px) scale(1)',
'&$marginDense': {
transform: 'translate(14px, 17px) scale(1)'
},
'&$shrink': {
transform: 'translate(14px, -6px) scale(0.75)'
}
}
};
};
exports.styles = styles;
function InputLabel(props) {
var _classNames;
var children = props.children,
classes = props.classes,
classNameProp = props.className,
disableAnimation = props.disableAnimation,
FormLabelClasses = props.FormLabelClasses,
margin = props.margin,
muiFormControl = props.muiFormControl,
shrinkProp = props.shrink,
variant = props.variant,
other = (0, _objectWithoutProperties2.default)(props, ["children", "classes", "className", "disableAnimation", "FormLabelClasses", "margin", "muiFormControl", "shrink", "variant"]);
var shrink = shrinkProp;
if (typeof shrink === 'undefined' && muiFormControl) {
shrink = muiFormControl.filled || muiFormControl.focused || muiFormControl.adornedStart;
}
var fcs = (0, _formControlState.default)({
props: props,
muiFormControl: muiFormControl,
states: ['margin', 'variant']
});
var className = (0, _classnames.default)(classes.root, (_classNames = {}, (0, _defineProperty2.default)(_classNames, classes.formControl, muiFormControl), (0, _defineProperty2.default)(_classNames, classes.animated, !disableAnimation), (0, _defineProperty2.default)(_classNames, classes.shrink, shrink), (0, _defineProperty2.default)(_classNames, classes.marginDense, fcs.margin === 'dense'), (0, _defineProperty2.default)(_classNames, classes.filled, fcs.variant === 'filled'), (0, _defineProperty2.default)(_classNames, classes.outlined, fcs.variant === 'outlined'), _classNames), classNameProp);
return _react.default.createElement(_FormLabel.default, (0, _extends2.default)({
"data-shrink": shrink,
className: className,
classes: (0, _extends2.default)({
focused: classes.focused,
disabled: classes.disabled,
error: classes.error,
required: classes.required
}, FormLabelClasses)
}, other), children);
}
process.env.NODE_ENV !== "production" ? InputLabel.propTypes = {
/**
* The contents of the `InputLabel`.
*/
children: _propTypes.default.node,
/**
* Override or extend the styles applied to the component.
* See [CSS API](#css-api) below for more details.
*/
classes: _propTypes.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes.default.string,
/**
* If `true`, the transition animation is disabled.
*/
disableAnimation: _propTypes.default.bool,
/**
* If `true`, apply disabled class.
*/
disabled: _propTypes.default.bool,
/**
* If `true`, the label will be displayed in an error state.
*/
error: _propTypes.default.bool,
/**
* If `true`, the input of this label is focused.
*/
focused: _propTypes.default.bool,
/**
* `classes` property applied to the [`FormLabel`](/api/form-label/) element.
*/
FormLabelClasses: _propTypes.default.object,
/**
* If `dense`, will adjust vertical spacing. This is normally obtained via context from
* FormControl.
*/
margin: _propTypes.default.oneOf(['dense']),
/**
* @ignore
*/
muiFormControl: _propTypes.default.object,
/**
* if `true`, the label will indicate that the input is required.
*/
required: _propTypes.default.bool,
/**
* If `true`, the label is shrunk.
*/
shrink: _propTypes.default.bool,
/**
* The variant to use.
*/
variant: _propTypes.default.oneOf(['standard', 'outlined', 'filled'])
} : void 0;
InputLabel.defaultProps = {
disableAnimation: false
};
var _default = (0, _withStyles.default)(styles, {
name: 'MuiInputLabel'
})((0, _withFormControlContext.default)(InputLabel));
exports.default = _default;