UNPKG

@activelylearn/material-ui

Version:

Material-UI's workspace package

116 lines (103 loc) 2.66 kB
import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import withStyles from '../styles/withStyles'; export const styles = theme => ({ root: { color: theme.palette.text.secondary, fontFamily: theme.typography.fontFamily, fontSize: theme.typography.pxToRem(12), textAlign: 'left', marginTop: theme.spacing.unit, lineHeight: '1em', minHeight: '1em', margin: 0, '&$error': { color: theme.palette.error.main, }, '&$disabled': { color: theme.palette.text.disabled, }, }, error: {}, disabled: {}, marginDense: { marginTop: theme.spacing.unit / 2, }, }); function FormHelperText(props, context) { const { classes, className: classNameProp, disabled: disabledProp, error: errorProp, margin: marginProp, component: Component, ...other } = props; const { muiFormControl } = context; let disabled = disabledProp; let error = errorProp; let margin = marginProp; if (muiFormControl) { if (typeof disabled === 'undefined') { disabled = muiFormControl.disabled; } if (typeof error === 'undefined') { error = muiFormControl.error; } if (typeof margin === 'undefined') { margin = muiFormControl.margin; } } const className = classNames( classes.root, { [classes.disabled]: disabled, [classes.error]: error, [classes.marginDense]: margin === 'dense', }, classNameProp, ); return <Component className={className} {...other} />; } FormHelperText.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: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), /** * If `true`, the helper text should be displayed in a disabled state. */ disabled: PropTypes.bool, /** * If `true`, helper text should be displayed in an error state. */ error: PropTypes.bool, /** * If `dense`, will adjust vertical spacing. This is normally obtained via context from * FormControl. */ margin: PropTypes.oneOf(['dense']), }; FormHelperText.defaultProps = { component: 'p', }; FormHelperText.contextTypes = { muiFormControl: PropTypes.object, }; export default withStyles(styles, { name: 'MuiFormHelperText' })(FormHelperText);