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

@@ -1,13 +1,11 @@
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
import _extends from 'babel-runtime/helpers/extends';
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
import React 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 => ({
@@ -45,7 +43,6 @@ export const styles = theme => ({
* - InputLabel
*/
class FormControl extends React.Component {
constructor(props, context) {
super(props, context);
@@ -61,18 +58,17 @@ class FormControl extends React.Component {
if (this.props.onFocus) {
this.props.onFocus(event);
}
if (!this.state.focused) {
this.setState({ focused: true });
}
this.setState(state => !state.focused ? { focused: true } : null);
};
this.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);
};
this.handleDirty = () => {
@@ -124,34 +120,77 @@ class FormControl extends React.Component {
render() {
const _props = this.props,
{
children,
classes,
className,
component: ComponentProp,
component: Component,
disabled,
error,
fullWidth,
margin
margin,
required
} = _props,
other = _objectWithoutProperties(_props, ['children', 'classes', 'className', 'component', 'disabled', 'error', 'fullWidth', 'margin']);
other = _objectWithoutProperties(_props, ['classes', 'className', 'component', 'disabled', 'error', 'fullWidth', 'margin', 'required']);
return React.createElement(
ComponentProp,
_extends({
className: classNames(classes.root, {
[classes.marginNormal]: margin === 'normal',
[classes.marginDense]: margin === 'dense',
[classes.fullWidth]: fullWidth
}, className)
}, other, {
onFocus: this.handleFocus,
onBlur: this.handleBlur
}),
children
);
return React.createElement(Component, _extends({
className: classNames(classes.root, {
[classes[`margin${capitalize(margin)}`]]: margin !== 'none',
[classes.fullWidth]: fullWidth
}, className)
}, other, {
onFocus: this.handleFocus,
onBlur: this.handleBlur
}));
}
}
FormControl.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* 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,
@@ -160,7 +199,9 @@ FormControl.defaultProps = {
margin: 'none',
required: false
};
FormControl.childContextTypes = {
muiFormControl: PropTypes.object.isRequired
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

@@ -1,11 +1,8 @@
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
import _extends from 'babel-runtime/helpers/extends';
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
/* eslint-disable jsx-a11y/label-has-for */
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
@@ -16,8 +13,10 @@ export const styles = theme => ({
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
},
@@ -25,9 +24,7 @@ export const styles = theme => ({
color: theme.palette.text.disabled,
cursor: 'default'
},
label: {
userSelect: 'none'
}
label: {}
});
/**
@@ -81,12 +78,58 @@ function FormControlLabel(props, context) {
}),
React.createElement(
Typography,
{ className: classes.label },
{ component: 'span', className: classes.label },
label
)
);
}
FormControlLabel.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* 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

@@ -1,9 +1,7 @@
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
import _extends from 'babel-runtime/helpers/extends';
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
@@ -37,6 +35,25 @@ function FormGroup(props) {
);
}
FormGroup.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* 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

@@ -1,16 +1,13 @@
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
import _extends from 'babel-runtime/helpers/extends';
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
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.input.helperText,
color: theme.palette.text.secondary,
fontFamily: theme.typography.fontFamily,
fontSize: theme.typography.pxToRem(12),
textAlign: 'left',
@@ -23,23 +20,23 @@ export const 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
}
});
function FormHelperText(props, context) {
const {
children,
classes,
className: classNameProp,
disabled: disabledProp,
error: errorProp,
margin: marginProp
margin: marginProp,
component: Component
} = props,
other = _objectWithoutProperties(props, ['children', 'classes', 'className', 'disabled', 'error', 'margin']);
other = _objectWithoutProperties(props, ['classes', 'className', 'disabled', 'error', 'margin', 'component']);
const { muiFormControl } = context;
let disabled = disabledProp;
@@ -66,13 +63,46 @@ function FormHelperText(props, context) {
[classes.dense]: margin === 'dense'
}, classNameProp);
return React.createElement(
'p',
_extends({ className: className }, other),
children
);
return React.createElement(Component, _extends({ className: className }, other));
}
FormHelperText.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* 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

@@ -1,34 +1,28 @@
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
import _extends from 'babel-runtime/helpers/extends';
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
export const styles = theme => {
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
}
});
function FormLabel(props, context) {
const {
@@ -81,12 +75,48 @@ function FormLabel(props, context) {
children,
required && React.createElement(
'span',
{ className: asteriskClassName, 'data-mui-test': 'FormLabelAsterisk' },
{ className: asteriskClassName },
'\u2009*'
)
);
}
FormLabel.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* 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'
};