Completely updated React, fixed #11, (hopefully)

This commit is contained in:
2018-03-04 19:11:49 -05:00
parent 6e0afd6e2a
commit 34e5f5139a
13674 changed files with 333464 additions and 473223 deletions

View File

@@ -1,10 +1,9 @@
import * as React from 'react';
import { StandardProps, PropTypes } from '..';
export interface FormControlProps extends StandardProps<
React.HtmlHTMLAttributes<HTMLDivElement>,
FormControlClassKey
> {
export interface FormControlProps
extends StandardProps<React.HtmlHTMLAttributes<HTMLDivElement>, FormControlClassKey> {
component?: React.ReactType<FormControlProps>;
disabled?: boolean;
error?: boolean;
fullWidth?: boolean;
@@ -12,15 +11,9 @@ export interface FormControlProps extends StandardProps<
onBlur?: React.EventHandler<any>;
onFocus?: React.EventHandler<any>;
required?: boolean;
component?: React.ReactType;
}
export type FormControlClassKey =
| 'root'
| 'marginNormal'
| 'marginDense'
| 'fullWidth'
;
export type FormControlClassKey = 'root' | 'marginNormal' | 'marginDense' | 'fullWidth';
declare const FormControl: React.ComponentType<FormControlProps>;

View File

@@ -55,14 +55,12 @@ var _withStyles2 = _interopRequireDefault(_withStyles);
var _Input = require('../Input/Input');
var _helpers = require('../utils/helpers');
var _reactHelpers = require('../utils/reactHelpers');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
var babelPluginFlowReactPropTypes_proptype_ElementType = require('react').babelPluginFlowReactPropTypes_proptype_ElementType || require('prop-types').any;
var styles = exports.styles = function styles(theme) {
return {
root: {
@@ -89,67 +87,6 @@ var styles = exports.styles = function styles(theme) {
};
};
var babelPluginFlowReactPropTypes_proptype_Margin = require('prop-types').oneOf(['none', 'dense', 'normal']);
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* The contents of the form control.
*/
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: typeof babelPluginFlowReactPropTypes_proptype_ElementType === 'function' ? babelPluginFlowReactPropTypes_proptype_ElementType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ElementType),
/**
* If `true`, the label, input and helper text should be displayed in a disabled state.
*/
disabled: require('prop-types').bool,
/**
* If `true`, the label should be displayed in an error state.
*/
error: require('prop-types').bool,
/**
* If `true`, the component, as well as its children,
* will take up the full width of its container.
*/
fullWidth: require('prop-types').bool,
/**
* @ignore
*/
onBlur: require('prop-types').func,
/**
* @ignore
*/
onFocus: require('prop-types').func,
/**
* If `true`, the label will indicate that the input is required.
*/
required: require('prop-types').bool,
/**
* If `dense` or `normal`, will adjust vertical spacing of this and contained components.
*/
margin: require('prop-types').oneOf(['none', 'dense', 'normal'])
};
/**
* Provides context such as dirty/focused/error/required for form inputs.
* Relying on the context provides high flexibilty and ensures that the state always stay
@@ -160,6 +97,7 @@ var babelPluginFlowReactPropTypes_proptype_Props = {
* - Input
* - InputLabel
*/
var FormControl = function (_React$Component) {
(0, _inherits3.default)(FormControl, _React$Component);
@@ -180,18 +118,21 @@ var FormControl = function (_React$Component) {
if (_this.props.onFocus) {
_this.props.onFocus(event);
}
if (!_this.state.focused) {
_this.setState({ focused: true });
}
_this.setState(function (state) {
return !state.focused ? { focused: true } : null;
});
};
_this.handleBlur = function (event) {
if (_this.props.onBlur) {
// The event might be undefined.
// For instance, a child component might call this hook
// when an input is disabled but still having the focus.
if (_this.props.onBlur && event) {
_this.props.onBlur(event);
}
if (_this.state.focused) {
_this.setState({ focused: false });
}
_this.setState(function (state) {
return state.focused ? { focused: false } : null;
});
};
_this.handleDirty = function () {
@@ -257,32 +198,76 @@ var FormControl = function (_React$Component) {
var _classNames;
var _props2 = this.props,
children = _props2.children,
classes = _props2.classes,
className = _props2.className,
ComponentProp = _props2.component,
Component = _props2.component,
disabled = _props2.disabled,
error = _props2.error,
fullWidth = _props2.fullWidth,
margin = _props2.margin,
other = (0, _objectWithoutProperties3.default)(_props2, ['children', 'classes', 'className', 'component', 'disabled', 'error', 'fullWidth', 'margin']);
required = _props2.required,
other = (0, _objectWithoutProperties3.default)(_props2, ['classes', 'className', 'component', 'disabled', 'error', 'fullWidth', 'margin', 'required']);
return _react2.default.createElement(
ComponentProp,
(0, _extends3.default)({
className: (0, _classnames2.default)(classes.root, (_classNames = {}, (0, _defineProperty3.default)(_classNames, classes.marginNormal, margin === 'normal'), (0, _defineProperty3.default)(_classNames, classes.marginDense, margin === 'dense'), (0, _defineProperty3.default)(_classNames, classes.fullWidth, fullWidth), _classNames), className)
}, other, {
onFocus: this.handleFocus,
onBlur: this.handleBlur
}),
children
);
return _react2.default.createElement(Component, (0, _extends3.default)({
className: (0, _classnames2.default)(classes.root, (_classNames = {}, (0, _defineProperty3.default)(_classNames, classes['margin' + (0, _helpers.capitalize)(margin)], margin !== 'none'), (0, _defineProperty3.default)(_classNames, classes.fullWidth, fullWidth), _classNames), className)
}, other, {
onFocus: this.handleFocus,
onBlur: this.handleBlur
}));
}
}]);
return FormControl;
}(_react2.default.Component);
FormControl.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The contents of the form control.
*/
children: _propTypes2.default.node,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.func]),
/**
* If `true`, the label, input and helper text should be displayed in a disabled state.
*/
disabled: _propTypes2.default.bool,
/**
* If `true`, the label should be displayed in an error state.
*/
error: _propTypes2.default.bool,
/**
* If `true`, the component will take up the full width of its container.
*/
fullWidth: _propTypes2.default.bool,
/**
* If `dense` or `normal`, will adjust vertical spacing of this and contained components.
*/
margin: _propTypes2.default.oneOf(['none', 'dense', 'normal']),
/**
* @ignore
*/
onBlur: _propTypes2.default.func,
/**
* @ignore
*/
onFocus: _propTypes2.default.func,
/**
* If `true`, the label will indicate that the input is required.
*/
required: _propTypes2.default.bool
} : {};
FormControl.defaultProps = {
component: 'div',
disabled: false,
@@ -291,7 +276,9 @@ FormControl.defaultProps = {
margin: 'none',
required: false
};
FormControl.childContextTypes = {
muiFormControl: _propTypes2.default.object.isRequired
muiFormControl: _propTypes2.default.object
};
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiFormControl' })(FormControl);

View File

@@ -1,14 +1,12 @@
// @flow
import React from 'react';
import type { ElementType, Node } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
import { isDirty, isAdornedStart } from '../Input/Input';
import { capitalize } from '../utils/helpers';
import { isMuiElement } from '../utils/reactHelpers';
export const styles = (theme: Object) => ({
export const styles = theme => ({
root: {
display: 'inline-flex',
flexDirection: 'column',
@@ -32,73 +30,6 @@ export const styles = (theme: Object) => ({
},
});
export type Margin = 'none' | 'dense' | 'normal';
type ProvidedProps = {
disabled: boolean,
classes: Object,
component: ElementType,
error: boolean,
fullWidth: boolean,
margin: Margin,
required: boolean,
};
export type Props = {
/**
* The contents of the form control.
*/
children?: Node,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component?: ElementType,
/**
* If `true`, the label, input and helper text should be displayed in a disabled state.
*/
disabled?: boolean,
/**
* If `true`, the label should be displayed in an error state.
*/
error?: boolean,
/**
* If `true`, the component, as well as its children,
* will take up the full width of its container.
*/
fullWidth?: boolean,
/**
* @ignore
*/
onBlur?: Function,
/**
* @ignore
*/
onFocus?: Function,
/**
* If `true`, the label will indicate that the input is required.
*/
required?: boolean,
/**
* If `dense` or `normal`, will adjust vertical spacing of this and contained components.
*/
margin?: Margin,
};
type State = {
adornedStart: boolean,
dirty: boolean,
focused: boolean,
};
/**
* Provides context such as dirty/focused/error/required for form inputs.
* Relying on the context provides high flexibilty and ensures that the state always stay
@@ -109,20 +40,7 @@ type State = {
* - Input
* - InputLabel
*/
class FormControl extends React.Component<ProvidedProps & Props, State> {
static defaultProps = {
component: 'div',
disabled: false,
error: false,
fullWidth: false,
margin: 'none',
required: false,
};
static childContextTypes = {
muiFormControl: PropTypes.object.isRequired,
};
class FormControl extends React.Component {
constructor(props, context) {
super(props, context);
@@ -172,18 +90,17 @@ class FormControl extends React.Component<ProvidedProps & Props, State> {
if (this.props.onFocus) {
this.props.onFocus(event);
}
if (!this.state.focused) {
this.setState({ focused: true });
}
this.setState(state => (!state.focused ? { focused: true } : null));
};
handleBlur = event => {
if (this.props.onBlur) {
// The event might be undefined.
// For instance, a child component might call this hook
// when an input is disabled but still having the focus.
if (this.props.onBlur && event) {
this.props.onBlur(event);
}
if (this.state.focused) {
this.setState({ focused: false });
}
this.setState(state => (state.focused ? { focused: false } : null));
};
handleDirty = () => {
@@ -200,24 +117,23 @@ class FormControl extends React.Component<ProvidedProps & Props, State> {
render() {
const {
children,
classes,
className,
component: ComponentProp,
component: Component,
disabled,
error,
fullWidth,
margin,
required,
...other
} = this.props;
return (
<ComponentProp
<Component
className={classNames(
classes.root,
{
[classes.marginNormal]: margin === 'normal',
[classes.marginDense]: margin === 'dense',
[classes[`margin${capitalize(margin)}`]]: margin !== 'none',
[classes.fullWidth]: fullWidth,
},
className,
@@ -225,11 +141,70 @@ class FormControl extends React.Component<ProvidedProps & Props, State> {
{...other}
onFocus={this.handleFocus}
onBlur={this.handleBlur}
>
{children}
</ComponentProp>
/>
);
}
}
FormControl.propTypes = {
/**
* The contents of the form control.
*/
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 label, input and helper text 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 component will take up the full width of its container.
*/
fullWidth: PropTypes.bool,
/**
* If `dense` or `normal`, will adjust vertical spacing of this and contained components.
*/
margin: PropTypes.oneOf(['none', 'dense', 'normal']),
/**
* @ignore
*/
onBlur: PropTypes.func,
/**
* @ignore
*/
onFocus: PropTypes.func,
/**
* If `true`, the label will indicate that the input is required.
*/
required: PropTypes.bool,
};
FormControl.defaultProps = {
component: 'div',
disabled: false,
error: false,
fullWidth: false,
margin: 'none',
required: false,
};
FormControl.childContextTypes = {
muiFormControl: PropTypes.object,
};
export default withStyles(styles, { name: 'MuiFormControl' })(FormControl);

View File

@@ -1,11 +1,12 @@
import * as React from 'react';
import { StandardProps } from '..';
export interface FormControlLabelProps extends StandardProps<
React.LabelHTMLAttributes<HTMLLabelElement>,
FormControlLabelClassKey,
'onChange'
> {
export interface FormControlLabelProps
extends StandardProps<
React.LabelHTMLAttributes<HTMLLabelElement>,
FormControlLabelClassKey,
'onChange'
> {
checked?: boolean | string;
control: React.ReactElement<any>;
disabled?: boolean;
@@ -16,11 +17,7 @@ export interface FormControlLabelProps extends StandardProps<
value?: string;
}
export type FormControlLabelClassKey =
| 'root'
| 'disabled'
| 'label'
;
export type FormControlLabelClassKey = 'root' | 'disabled' | 'label';
declare const FormControlLabel: React.ComponentType<FormControlLabelProps>;

View File

@@ -17,9 +17,6 @@ var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProp
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _ref;
/* eslint-disable jsx-a11y/label-has-for */
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
@@ -42,18 +39,16 @@ var _Typography2 = _interopRequireDefault(_Typography);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Element = require('react').babelPluginFlowReactPropTypes_proptype_Element || require('prop-types').any;
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
var styles = exports.styles = function styles(theme) {
return {
root: {
display: 'inline-flex',
alignItems: 'center',
cursor: 'pointer',
// For correct alignment with the text.
verticalAlign: 'middle',
// Remove grey highlight
WebkitTapHighlightColor: theme.palette.common.transparent,
WebkitTapHighlightColor: 'transparent',
marginLeft: -14,
marginRight: theme.spacing.unit * 2 // used for row presentation of radio/checkbox
},
@@ -61,72 +56,16 @@ var styles = exports.styles = function styles(theme) {
color: theme.palette.text.disabled,
cursor: 'default'
},
label: {
userSelect: 'none'
}
label: {}
};
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* If `true`, the component appears selected.
*/
checked: require('prop-types').oneOfType([require('prop-types').bool, require('prop-types').string]),
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string,
/**
* A control element. For instance, it can be be a `Radio`, a `Switch` or a `Checkbox`.
*/
control: typeof babelPluginFlowReactPropTypes_proptype_Element === 'function' ? babelPluginFlowReactPropTypes_proptype_Element.isRequired ? babelPluginFlowReactPropTypes_proptype_Element.isRequired : babelPluginFlowReactPropTypes_proptype_Element : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Element).isRequired,
/**
* If `true`, the control will be disabled.
*/
disabled: require('prop-types').bool,
/**
* Use that property to pass a ref callback to the native input component.
*/
inputRef: require('prop-types').func,
/**
* The text to be used in an enclosing label element.
*/
label: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node.isRequired ? babelPluginFlowReactPropTypes_proptype_Node.isRequired : babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node).isRequired,
/*
* @ignore
*/
name: require('prop-types').string,
/**
* Callback fired when the state is changed.
*
* @param {object} event The event source of the callback
* @param {boolean} checked The `checked` value of the switch
*/
onChange: require('prop-types').func,
/**
* The value of the component.
*/
value: require('prop-types').string
};
/**
* Drop in replacement of the `Radio`, `Switch` and `Checkbox` component.
* Use this component if you want to display an extra label.
*/
/* eslint-disable jsx-a11y/label-has-for */
function FormControlLabel(props, context) {
var checked = props.checked,
classes = props.classes,
@@ -170,16 +109,58 @@ function FormControlLabel(props, context) {
}),
_react2.default.createElement(
_Typography2.default,
{ className: classes.label },
{ component: 'span', className: classes.label },
label
)
);
}
FormControlLabel.propTypes = process.env.NODE_ENV !== "production" ? (_ref = {
classes: require('prop-types').object.isRequired,
checked: require('prop-types').oneOfType([require('prop-types').bool, require('prop-types').string])
}, (0, _defineProperty3.default)(_ref, 'classes', require('prop-types').object), (0, _defineProperty3.default)(_ref, 'className', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'control', typeof babelPluginFlowReactPropTypes_proptype_Element === 'function' ? babelPluginFlowReactPropTypes_proptype_Element.isRequired ? babelPluginFlowReactPropTypes_proptype_Element.isRequired : babelPluginFlowReactPropTypes_proptype_Element : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Element).isRequired), (0, _defineProperty3.default)(_ref, 'disabled', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'inputRef', require('prop-types').func), (0, _defineProperty3.default)(_ref, 'label', typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node.isRequired ? babelPluginFlowReactPropTypes_proptype_Node.isRequired : babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node).isRequired), (0, _defineProperty3.default)(_ref, 'name', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'onChange', require('prop-types').func), (0, _defineProperty3.default)(_ref, 'value', require('prop-types').string), _ref) : {};
FormControlLabel.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* If `true`, the component appears selected.
*/
checked: _propTypes2.default.oneOfType([_propTypes2.default.bool, _propTypes2.default.string]),
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string,
/**
* A control element. For instance, it can be be a `Radio`, a `Switch` or a `Checkbox`.
*/
control: _propTypes2.default.element,
/**
* If `true`, the control will be disabled.
*/
disabled: _propTypes2.default.bool,
/**
* Use that property to pass a ref callback to the native input component.
*/
inputRef: _propTypes2.default.func,
/**
* The text to be used in an enclosing label element.
*/
label: _propTypes2.default.node,
/*
* @ignore
*/
name: _propTypes2.default.string,
/**
* Callback fired when the state is changed.
*
* @param {object} event The event source of the callback
* @param {boolean} checked The `checked` value of the switch
*/
onChange: _propTypes2.default.func,
/**
* The value of the component.
*/
value: _propTypes2.default.string
} : {};
FormControlLabel.contextTypes = {
muiFormControl: _propTypes2.default.object
};

View File

@@ -1,20 +1,20 @@
// @flow
/* eslint-disable jsx-a11y/label-has-for */
import React from 'react';
import type { Node, Element } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
import Typography from '../Typography';
export const styles = (theme: Object) => ({
export const styles = theme => ({
root: {
display: 'inline-flex',
alignItems: 'center',
cursor: 'pointer',
// For correct alignment with the text.
verticalAlign: 'middle',
// Remove grey highlight
WebkitTapHighlightColor: theme.palette.common.transparent,
WebkitTapHighlightColor: 'transparent',
marginLeft: -14,
marginRight: theme.spacing.unit * 2, // used for row presentation of radio/checkbox
},
@@ -22,70 +22,14 @@ export const styles = (theme: Object) => ({
color: theme.palette.text.disabled,
cursor: 'default',
},
label: {
userSelect: 'none',
},
label: {},
});
type Context = {
muiFormControl?: Object,
};
type ProvidedProps = {
classes: Object,
};
export type Props = {
/**
* If `true`, the component appears selected.
*/
checked?: boolean | string,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* A control element. For instance, it can be be a `Radio`, a `Switch` or a `Checkbox`.
*/
control: Element<any>,
/**
* If `true`, the control will be disabled.
*/
disabled?: boolean,
/**
* Use that property to pass a ref callback to the native input component.
*/
inputRef?: Function,
/**
* The text to be used in an enclosing label element.
*/
label: Node,
/*
* @ignore
*/
name?: string,
/**
* Callback fired when the state is changed.
*
* @param {object} event The event source of the callback
* @param {boolean} checked The `checked` value of the switch
*/
onChange?: Function,
/**
* The value of the component.
*/
value?: string,
};
/**
* Drop in replacement of the `Radio`, `Switch` and `Checkbox` component.
* Use this component if you want to display an extra label.
*/
function FormControlLabel(props: ProvidedProps & Props, context: Context) {
function FormControlLabel(props, context) {
const {
checked,
classes,
@@ -133,11 +77,59 @@ function FormControlLabel(props: ProvidedProps & Props, context: Context) {
value: control.props.value || value,
inputRef: control.props.inputRef || inputRef,
})}
<Typography className={classes.label}>{label}</Typography>
<Typography component="span" className={classes.label}>
{label}
</Typography>
</label>
);
}
FormControlLabel.propTypes = {
/**
* If `true`, the component appears selected.
*/
checked: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* A control element. For instance, it can be be a `Radio`, a `Switch` or a `Checkbox`.
*/
control: PropTypes.element,
/**
* If `true`, the control will be disabled.
*/
disabled: PropTypes.bool,
/**
* Use that property to pass a ref callback to the native input component.
*/
inputRef: PropTypes.func,
/**
* The text to be used in an enclosing label element.
*/
label: PropTypes.node,
/*
* @ignore
*/
name: PropTypes.string,
/**
* Callback fired when the state is changed.
*
* @param {object} event The event source of the callback
* @param {boolean} checked The `checked` value of the switch
*/
onChange: PropTypes.func,
/**
* The value of the component.
*/
value: PropTypes.string,
};
FormControlLabel.contextTypes = {
muiFormControl: PropTypes.object,
};

View File

@@ -1,17 +1,12 @@
import * as React from 'react';
import { StandardProps } from '..';
export interface FormGroupProps extends StandardProps<
React.HtmlHTMLAttributes<HTMLDivElement>,
FormGroupClassKey
> {
export interface FormGroupProps
extends StandardProps<React.HtmlHTMLAttributes<HTMLDivElement>, FormGroupClassKey> {
row?: boolean;
}
export type FormGroupClassKey =
| 'root'
| 'row'
;
export type FormGroupClassKey = 'root' | 'row';
declare const FormGroup: React.ComponentType<FormGroupProps>;

View File

@@ -17,12 +17,14 @@ var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProp
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _ref;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
@@ -33,8 +35,6 @@ var _withStyles2 = _interopRequireDefault(_withStyles);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
var styles = exports.styles = {
root: {
display: 'flex',
@@ -46,29 +46,6 @@ var styles = exports.styles = {
}
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* The content of the component.
*/
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string,
/**
* Display group of elements in a compact row.
*/
row: require('prop-types').bool
};
/**
* `FormGroup` wraps controls such as `Checkbox` and `Switch`.
* It provides compact row layout.
@@ -90,10 +67,25 @@ function FormGroup(props) {
);
}
FormGroup.propTypes = process.env.NODE_ENV !== "production" ? (_ref = {
classes: require('prop-types').object.isRequired,
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node)
}, (0, _defineProperty3.default)(_ref, 'classes', require('prop-types').object), (0, _defineProperty3.default)(_ref, 'className', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'row', require('prop-types').bool), _ref) : {};
FormGroup.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the component.
*/
children: _propTypes2.default.node,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string,
/**
* Display group of elements in a compact row.
*/
row: _propTypes2.default.bool
} : {};
FormGroup.defaultProps = {
row: false
};

View File

@@ -1,7 +1,5 @@
// @flow
import React from 'react';
import type { Node } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
@@ -16,35 +14,12 @@ export const styles = {
},
};
type ProvidedProps = {
classes: Object,
};
export type Props = {
/**
* The content of the component.
*/
children?: Node,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* Display group of elements in a compact row.
*/
row?: boolean,
};
/**
* `FormGroup` wraps controls such as `Checkbox` and `Switch`.
* It provides compact row layout.
* For the `Radio`, you should be using the `RadioGroup` component instead of this one.
*/
function FormGroup(props: ProvidedProps & Props) {
function FormGroup(props) {
const { classes, className, children, row, ...other } = props;
const rootClassName = classNames(
classes.root,
@@ -61,6 +36,25 @@ function FormGroup(props: ProvidedProps & Props) {
);
}
FormGroup.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,
/**
* Display group of elements in a compact row.
*/
row: PropTypes.bool,
};
FormGroup.defaultProps = {
row: false,
};

View File

@@ -1,21 +1,14 @@
import * as React from 'react';
import { StandardProps } from '..';
export interface FormHelperTextProps extends StandardProps<
React.HTMLAttributes<HTMLParagraphElement>,
FormHelperTextClassKey
> {
export interface FormHelperTextProps
extends StandardProps<React.HTMLAttributes<HTMLParagraphElement>, FormHelperTextClassKey> {
disabled?: boolean;
error?: boolean;
margin?: 'dense';
}
export type FormHelperTextClassKey =
| 'root'
| 'dense'
| 'error'
| 'disabled'
;
export type FormHelperTextClassKey = 'root' | 'dense' | 'error' | 'disabled';
declare const FormHelperText: React.ComponentType<FormHelperTextProps>;

View File

@@ -17,8 +17,6 @@ var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProp
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _ref;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
@@ -37,12 +35,10 @@ var _withStyles2 = _interopRequireDefault(_withStyles);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
var styles = exports.styles = function styles(theme) {
return {
root: {
color: theme.palette.input.helperText,
color: theme.palette.text.secondary,
fontFamily: theme.typography.fontFamily,
fontSize: theme.typography.pxToRem(12),
textAlign: 'left',
@@ -55,58 +51,24 @@ var styles = exports.styles = function styles(theme) {
marginTop: theme.spacing.unit / 2
},
error: {
color: theme.palette.error.A400
color: theme.palette.error.main
},
disabled: {
color: theme.palette.input.disabled
color: theme.palette.text.disabled
}
};
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* The content of the component.
*/
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string,
/**
* If `true`, the helper text should be displayed in a disabled state.
*/
disabled: require('prop-types').bool,
/**
* If `true`, helper text should be displayed in an error state.
*/
error: require('prop-types').bool,
/**
* If `dense`, will adjust vertical spacing. This is normally obtained via context from
* FormControl.
*/
margin: require('prop-types').oneOf(['dense'])
};
function FormHelperText(props, context) {
var _classNames;
var children = props.children,
classes = props.classes,
var classes = props.classes,
classNameProp = props.className,
disabledProp = props.disabled,
errorProp = props.error,
marginProp = props.margin,
other = (0, _objectWithoutProperties3.default)(props, ['children', 'classes', 'className', 'disabled', 'error', 'margin']);
Component = props.component,
other = (0, _objectWithoutProperties3.default)(props, ['classes', 'className', 'disabled', 'error', 'margin', 'component']);
var muiFormControl = context.muiFormControl;
@@ -130,17 +92,46 @@ function FormHelperText(props, context) {
var className = (0, _classnames2.default)(classes.root, (_classNames = {}, (0, _defineProperty3.default)(_classNames, classes.disabled, disabled), (0, _defineProperty3.default)(_classNames, classes.error, error), (0, _defineProperty3.default)(_classNames, classes.dense, margin === 'dense'), _classNames), classNameProp);
return _react2.default.createElement(
'p',
(0, _extends3.default)({ className: className }, other),
children
);
return _react2.default.createElement(Component, (0, _extends3.default)({ className: className }, other));
}
FormHelperText.propTypes = process.env.NODE_ENV !== "production" ? (_ref = {
classes: require('prop-types').object.isRequired,
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node)
}, (0, _defineProperty3.default)(_ref, 'classes', require('prop-types').object), (0, _defineProperty3.default)(_ref, 'className', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'disabled', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'error', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'margin', require('prop-types').oneOf(['dense'])), _ref) : {};
FormHelperText.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the component.
*/
children: _propTypes2.default.node,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.func]),
/**
* If `true`, the helper text should be displayed in a disabled state.
*/
disabled: _propTypes2.default.bool,
/**
* If `true`, helper text should be displayed in an error state.
*/
error: _propTypes2.default.bool,
/**
* If `dense`, will adjust vertical spacing. This is normally obtained via context from
* FormControl.
*/
margin: _propTypes2.default.oneOf(['dense'])
} : {};
FormHelperText.defaultProps = {
component: 'p'
};
FormHelperText.contextTypes = {
muiFormControl: _propTypes2.default.object
};

View File

@@ -1,14 +1,11 @@
// @flow
import React from 'react';
import type { Node } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
export const styles = (theme: Object) => ({
export const styles = theme => ({
root: {
color: theme.palette.input.helperText,
color: theme.palette.text.secondary,
fontFamily: theme.typography.fontFamily,
fontSize: theme.typography.pxToRem(12),
textAlign: 'left',
@@ -21,53 +18,21 @@ export const styles = (theme: Object) => ({
marginTop: theme.spacing.unit / 2,
},
error: {
color: theme.palette.error.A400,
color: theme.palette.error.main,
},
disabled: {
color: theme.palette.input.disabled,
color: theme.palette.text.disabled,
},
});
type ProvidedProps = {
classes: Object,
};
export type Props = {
/**
* The content of the component.
*/
children?: Node,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* If `true`, the helper text should be displayed in a disabled state.
*/
disabled?: boolean,
/**
* If `true`, helper text should be displayed in an error state.
*/
error?: boolean,
/**
* If `dense`, will adjust vertical spacing. This is normally obtained via context from
* FormControl.
*/
margin?: 'dense',
};
function FormHelperText(props: ProvidedProps & Props, context: { muiFormControl: Object }) {
function FormHelperText(props, context) {
const {
children,
classes,
className: classNameProp,
disabled: disabledProp,
error: errorProp,
margin: marginProp,
component: Component,
...other
} = props;
const { muiFormControl } = context;
@@ -100,13 +65,46 @@ function FormHelperText(props: ProvidedProps & Props, context: { muiFormControl:
classNameProp,
);
return (
<p className={className} {...other}>
{children}
</p>
);
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,
};

View File

@@ -1,22 +1,17 @@
import * as React from 'react';
import { StandardProps } from '..';
export interface FormLabelProps extends StandardProps<
React.LabelHTMLAttributes<HTMLLabelElement>,
FormLabelClassKey
> {
export interface FormLabelProps extends StandardProps<FormLabelBaseProps, FormLabelClassKey> {
component?: React.ReactType<FormLabelBaseProps>;
disabled?: boolean;
error?: boolean;
focused?: boolean;
required?: boolean;
}
export type FormLabelClassKey =
| 'root'
| 'focused'
| 'error'
| 'disabled'
;
export type FormLabelBaseProps = React.LabelHTMLAttributes<HTMLLabelElement>;
export type FormLabelClassKey = 'root' | 'focused' | 'error' | 'disabled';
declare const FormLabel: React.ComponentType<FormLabelProps>;

View File

@@ -17,8 +17,6 @@ var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProp
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _ref;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
@@ -37,76 +35,27 @@ var _withStyles2 = _interopRequireDefault(_withStyles);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
var babelPluginFlowReactPropTypes_proptype_ElementType = require('react').babelPluginFlowReactPropTypes_proptype_ElementType || require('prop-types').any;
var styles = exports.styles = function styles(theme) {
var focusColor = theme.palette.primary[theme.palette.type === 'light' ? 'A700' : 'A200'];
return {
root: {
fontFamily: theme.typography.fontFamily,
color: theme.palette.input.labelText,
color: theme.palette.text.secondary,
fontSize: theme.typography.pxToRem(16),
lineHeight: 1,
padding: 0
},
focused: {
color: focusColor
color: theme.palette.primary[theme.palette.type === 'light' ? 'dark' : 'light']
},
error: {
color: theme.palette.error.A400
color: theme.palette.error.main
},
disabled: {
color: theme.palette.input.disabled
color: theme.palette.text.disabled
}
};
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* The content of the component.
*/
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: typeof babelPluginFlowReactPropTypes_proptype_ElementType === 'function' ? babelPluginFlowReactPropTypes_proptype_ElementType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ElementType),
/**
* If `true`, the label should be displayed in a disabled state.
*/
disabled: require('prop-types').bool,
/**
* If `true`, the label should be displayed in an error state.
*/
error: require('prop-types').bool,
/**
* If `true`, the input of this label is focused (used by `FormGroup` components).
*/
focused: require('prop-types').bool,
/**
* If `true`, the label will indicate that the input is required.
*/
required: require('prop-types').bool
};
function FormLabel(props, context) {
var _classNames;
@@ -158,11 +107,42 @@ function FormLabel(props, context) {
);
}
FormLabel.propTypes = process.env.NODE_ENV !== "production" ? (_ref = {
classes: require('prop-types').object.isRequired,
component: typeof babelPluginFlowReactPropTypes_proptype_ElementType === 'function' ? babelPluginFlowReactPropTypes_proptype_ElementType.isRequired ? babelPluginFlowReactPropTypes_proptype_ElementType.isRequired : babelPluginFlowReactPropTypes_proptype_ElementType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ElementType).isRequired,
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node)
}, (0, _defineProperty3.default)(_ref, 'classes', require('prop-types').object), (0, _defineProperty3.default)(_ref, 'className', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'component', typeof babelPluginFlowReactPropTypes_proptype_ElementType === 'function' ? babelPluginFlowReactPropTypes_proptype_ElementType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ElementType)), (0, _defineProperty3.default)(_ref, 'disabled', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'error', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'focused', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'required', require('prop-types').bool), _ref) : {};
FormLabel.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the component.
*/
children: _propTypes2.default.node,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.func]),
/**
* If `true`, the label should be displayed in a disabled state.
*/
disabled: _propTypes2.default.bool,
/**
* If `true`, the label should be displayed in an error state.
*/
error: _propTypes2.default.bool,
/**
* If `true`, the input of this label is focused (used by `FormGroup` components).
*/
focused: _propTypes2.default.bool,
/**
* If `true`, the label will indicate that the input is required.
*/
required: _propTypes2.default.bool
} : {};
FormLabel.defaultProps = {
component: 'label'
};

View File

@@ -1,75 +1,28 @@
// @flow
import React from 'react';
import type { ElementType, Node } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
export const styles = (theme: Object) => {
const focusColor = theme.palette.primary[theme.palette.type === 'light' ? 'A700' : 'A200'];
return {
root: {
fontFamily: theme.typography.fontFamily,
color: theme.palette.input.labelText,
fontSize: theme.typography.pxToRem(16),
lineHeight: 1,
padding: 0,
},
focused: {
color: focusColor,
},
error: {
color: theme.palette.error.A400,
},
disabled: {
color: theme.palette.input.disabled,
},
};
};
export const styles = theme => ({
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'],
},
error: {
color: theme.palette.error.main,
},
disabled: {
color: theme.palette.text.disabled,
},
});
type ProvidedProps = {
classes: Object,
component: ElementType,
};
export type Props = {
/**
* The content of the component.
*/
children?: Node,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component?: ElementType,
/**
* If `true`, the label should be displayed in a disabled state.
*/
disabled?: boolean,
/**
* If `true`, the label should be displayed in an error state.
*/
error?: boolean,
/**
* If `true`, the input of this label is focused (used by `FormGroup` components).
*/
focused?: boolean,
/**
* If `true`, the label will indicate that the input is required.
*/
required?: boolean,
};
function FormLabel(props: ProvidedProps & Props, context: { muiFormControl: Object }) {
function FormLabel(props, context) {
const {
children,
classes,
@@ -130,6 +83,42 @@ function FormLabel(props: ProvidedProps & Props, context: { muiFormControl: Obje
);
}
FormLabel.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 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 input of this label is focused (used by `FormGroup` components).
*/
focused: PropTypes.bool,
/**
* If `true`, the label will indicate that the input is required.
*/
required: PropTypes.bool,
};
FormLabel.defaultProps = {
component: 'label',
};

View File

@@ -1,5 +1,3 @@
// @flow
export { default as FormGroup } from './FormGroup';
export { default as FormLabel } from './FormLabel';
export { default as FormControl } from './FormControl';