@material-ui/core
Version:
React components that implement Google's Material Design.
138 lines (121 loc) • 3.69 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { componentPropType } from '@material-ui/utils';
import formControlState from '../FormControl/formControlState';
import withFormControlContext from '../FormControl/withFormControlContext';
import withStyles from '../styles/withStyles';
export const styles = theme => ({
/* Styles applied to the root element. */
root: {
fontFamily: theme.typography.fontFamily,
color: theme.palette.text.secondary,
fontSize: theme.typography.pxToRem(16),
lineHeight: 1,
padding: 0,
'&$focused': {
color: theme.palette.primary[theme.palette.type === 'light' ? 'dark' : 'light']
},
'&$disabled': {
color: theme.palette.text.disabled
},
'&$error': {
color: theme.palette.error.main
}
},
/* 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 `filled={true}`. */
filled: {},
/* Styles applied to the root element if `required={true}`. */
required: {},
asterisk: {
'&$error': {
color: theme.palette.error.main
}
}
});
function FormLabel(props) {
const {
children,
classes,
className: classNameProp,
component: Component,
muiFormControl
} = props,
other = _objectWithoutPropertiesLoose(props, ["children", "classes", "className", "component", "disabled", "error", "filled", "focused", "muiFormControl", "required"]);
const fcs = formControlState({
props,
muiFormControl,
states: ['required', 'focused', 'disabled', 'error', 'filled']
});
return React.createElement(Component, _extends({
className: classNames(classes.root, {
[ ]: fcs.disabled,
[ ]: fcs.error,
[ ]: fcs.filled,
[ ]: fcs.focused,
[ ]: fcs.required
}, classNameProp)
}, other), children, fcs.required && React.createElement("span", {
className: classNames(classes.asterisk, {
[ ]: fcs.error
})
}, '\u2009*'));
}
process.env.NODE_ENV !== "production" ? FormLabel.propTypes = {
/**
* The content of the component.
*/
children: PropTypes.node,
/**
* Override or extend the styles applied to the component.
* See [CSS API](#css-api) below for more details.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: componentPropType,
/**
* If `true`, the label should be displayed in a disabled state.
*/
disabled: PropTypes.bool,
/**
* If `true`, the label should be displayed in an error state.
*/
error: PropTypes.bool,
/**
* If `true`, the label should use filled classes key.
*/
filled: PropTypes.bool,
/**
* If `true`, the input of this label is focused (used by `FormGroup` components).
*/
focused: PropTypes.bool,
/**
* @ignore
*/
muiFormControl: PropTypes.object,
/**
* If `true`, the label will indicate that the input is required.
*/
required: PropTypes.bool
} : void 0;
FormLabel.defaultProps = {
component: 'label'
};
export default withStyles(styles, {
name: 'MuiFormLabel'
})(withFormControlContext(FormLabel));