Files
goTorrent/goTorrentWebUI/node_modules/material-ui/Form/FormHelperText.js.flow

113 lines
2.5 KiB
Plaintext

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,
},
dense: {
marginTop: theme.spacing.unit / 2,
},
error: {
color: theme.palette.error.main,
},
disabled: {
color: theme.palette.text.disabled,
},
});
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.dense]: margin === 'dense',
},
classNameProp,
);
return <Component className={className} {...other} />;
}
FormHelperText.propTypes = {
/**
* The content of the component.
*/
children: PropTypes.node,
/**
* Useful to extend the style applied to components.
*/
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);