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

@@ -2,29 +2,9 @@ import * as React from 'react';
import { StandardProps } from '..';
import { SwitchBaseProps, SwitchBaseClassKey } from '../internal/SwitchBase';
export interface RadioProps extends StandardProps<
SwitchBaseProps,
RadioClassKey
> {
checked?: boolean | string;
checkedClassName?: string;
checkedIcon?: React.ReactNode;
defaultChecked?: boolean;
disabled?: boolean;
disabledClassName?: string;
disableRipple?: boolean;
icon?: React.ReactNode;
inputProps?: Object;
inputRef?: React.Ref<any>;
name?: string;
onChange?: (event: React.ChangeEvent<{}>, checked: boolean) => void;
tabIndex?: number;
value?: string;
}
export interface RadioProps extends StandardProps<SwitchBaseProps, RadioClassKey> {}
export type RadioClassKey =
| SwitchBaseClassKey
;
export type RadioClassKey = SwitchBaseClassKey;
declare const Radio: React.ComponentType<RadioProps>;

View File

@@ -3,45 +3,61 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.RadioDocs = exports.styles = undefined;
exports.styles = undefined;
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _ref2; // weak
var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _withStyles = require('../styles/withStyles');
var _propTypes = require('prop-types');
var _withStyles2 = _interopRequireDefault(_withStyles);
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _SwitchBase = require('../internal/SwitchBase');
var _SwitchBase2 = _interopRequireDefault(_SwitchBase);
var _RadioButtonChecked = require('../svg-icons/RadioButtonChecked');
var _RadioButtonChecked = require('../internal/svg-icons/RadioButtonChecked');
var _RadioButtonChecked2 = _interopRequireDefault(_RadioButtonChecked);
var _RadioButtonUnchecked = require('../svg-icons/RadioButtonUnchecked');
var _RadioButtonUnchecked = require('../internal/svg-icons/RadioButtonUnchecked');
var _RadioButtonUnchecked2 = _interopRequireDefault(_RadioButtonUnchecked);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _withStyles = require('../styles/withStyles');
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
var _withStyles2 = _interopRequireDefault(_withStyles);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var styles = exports.styles = function styles(theme) {
return {
default: {
color: theme.palette.text.secondary
},
checked: {
color: theme.palette.primary[500]
checked: {},
checkedPrimary: {
color: theme.palette.primary.main
},
checkedSecondary: {
color: theme.palette.secondary.main
},
disabled: {
color: theme.palette.action.disabled
@@ -49,112 +65,91 @@ var styles = exports.styles = function styles(theme) {
};
};
var Radio = (0, _withStyles2.default)(styles, { name: 'MuiRadio' })((0, _SwitchBase2.default)({
inputType: 'radio',
defaultIcon: _react2.default.createElement(_RadioButtonUnchecked2.default, null),
defaultCheckedIcon: _react2.default.createElement(_RadioButtonChecked2.default, null)
}));
var _ref = _react2.default.createElement(_RadioButtonUnchecked2.default, null);
Radio.displayName = 'Radio';
var _ref2 = _react2.default.createElement(_RadioButtonChecked2.default, null);
exports.default = Radio;
var babelPluginFlowReactPropTypes_proptype_Props = {
function Radio(props) {
var _classNames;
var classes = props.classes,
color = props.color,
other = (0, _objectWithoutProperties3.default)(props, ['classes', 'color']);
var checkedClass = (0, _classnames2.default)(classes.checked, (_classNames = {}, (0, _defineProperty3.default)(_classNames, classes.checkedPrimary, color === 'primary'), (0, _defineProperty3.default)(_classNames, classes.checkedSecondary, color === 'secondary'), _classNames));
return _react2.default.createElement(_SwitchBase2.default, (0, _extends3.default)({
type: 'radio',
icon: _ref,
checkedIcon: _ref2,
classes: {
default: classes.default,
checked: checkedClass,
disabled: classes.disabled
}
}, other));
}
Radio.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* If `true`, the component is checked.
*/
checked: require('prop-types').oneOfType([require('prop-types').bool, require('prop-types').string]),
/**
* The CSS class name of the root element when checked.
*/
checkedClassName: require('prop-types').string,
checked: _propTypes2.default.oneOfType([_propTypes2.default.bool, _propTypes2.default.string]),
/**
* The icon to display when the component is checked.
* If a string is provided, it will be used as a font ligature.
*/
checkedIcon: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
checkedIcon: _propTypes2.default.node,
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
* The color of the component. It supports those theme colors that make sense for this component.
*/
className: require('prop-types').string,
/**
* @ignore
*/
defaultChecked: require('prop-types').bool,
color: _propTypes2.default.oneOf(['primary', 'secondary']),
/**
* If `true`, the switch will be disabled.
*/
disabled: require('prop-types').bool,
/**
* The CSS class name of the root element when disabled.
*/
disabledClassName: require('prop-types').string,
disabled: _propTypes2.default.bool,
/**
* If `true`, the ripple effect will be disabled.
*/
disableRipple: require('prop-types').bool,
disableRipple: _propTypes2.default.bool,
/**
* The icon to display when the component is unchecked.
* If a string is provided, it will be used as a font ligature.
*/
icon: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
icon: _propTypes2.default.node,
/**
* The id of the `input` element.
*/
id: _propTypes2.default.string,
/**
* Properties applied to the `input` element.
*/
inputProps: require('prop-types').object,
inputProps: _propTypes2.default.object,
/**
* Use that property to pass a ref callback to the native input component.
*/
inputRef: require('prop-types').func,
/*
* @ignore
*/
name: require('prop-types').string,
inputRef: _propTypes2.default.func,
/**
* 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,
onChange: _propTypes2.default.func,
/**
* @ignore
* The input component property `type`.
*/
tabIndex: require('prop-types').oneOfType([require('prop-types').number, require('prop-types').string]),
type: _propTypes2.default.string,
/**
* The value of the component.
*/
value: require('prop-types').string
value: _propTypes2.default.string
} : {};
Radio.defaultProps = {
color: 'secondary'
};
var _ref = _react2.default.createElement('span', null);
// This is here solely to trigger api doc generation
// eslint-disable-next-line no-unused-vars
var RadioDocs = exports.RadioDocs = function RadioDocs(props) {
return _ref;
};
RadioDocs.propTypes = process.env.NODE_ENV !== "production" ? (_ref2 = {
classes: require('prop-types').object.isRequired,
checked: require('prop-types').oneOfType([require('prop-types').bool, require('prop-types').string]),
checkedClassName: require('prop-types').string,
checkedIcon: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node)
}, (0, _defineProperty3.default)(_ref2, 'classes', require('prop-types').object), (0, _defineProperty3.default)(_ref2, 'className', require('prop-types').string), (0, _defineProperty3.default)(_ref2, 'defaultChecked', require('prop-types').bool), (0, _defineProperty3.default)(_ref2, 'disabled', require('prop-types').bool), (0, _defineProperty3.default)(_ref2, 'disabledClassName', require('prop-types').string), (0, _defineProperty3.default)(_ref2, 'disableRipple', require('prop-types').bool), (0, _defineProperty3.default)(_ref2, 'icon', typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node)), (0, _defineProperty3.default)(_ref2, 'inputProps', require('prop-types').object), (0, _defineProperty3.default)(_ref2, 'inputRef', require('prop-types').func), (0, _defineProperty3.default)(_ref2, 'name', require('prop-types').string), (0, _defineProperty3.default)(_ref2, 'onChange', require('prop-types').func), (0, _defineProperty3.default)(_ref2, 'tabIndex', require('prop-types').oneOfType([require('prop-types').number, require('prop-types').string])), (0, _defineProperty3.default)(_ref2, 'value', require('prop-types').string), _ref2) : {};
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiRadio' })(Radio);

View File

@@ -1,112 +1,109 @@
// @flow weak
import React from 'react';
import type { Node } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import SwitchBase from '../internal/SwitchBase';
import RadioButtonCheckedIcon from '../internal/svg-icons/RadioButtonChecked';
import RadioButtonUncheckedIcon from '../internal/svg-icons/RadioButtonUnchecked';
import withStyles from '../styles/withStyles';
import createSwitch from '../internal/SwitchBase';
import RadioButtonCheckedIcon from '../svg-icons/RadioButtonChecked';
import RadioButtonUncheckedIcon from '../svg-icons/RadioButtonUnchecked';
export const styles = (theme: Object) => ({
export const styles = theme => ({
default: {
color: theme.palette.text.secondary,
},
checked: {
color: theme.palette.primary[500],
checked: {},
checkedPrimary: {
color: theme.palette.primary.main,
},
checkedSecondary: {
color: theme.palette.secondary.main,
},
disabled: {
color: theme.palette.action.disabled,
},
});
const Radio = withStyles(styles, { name: 'MuiRadio' })(
createSwitch({
inputType: 'radio',
defaultIcon: <RadioButtonUncheckedIcon />,
defaultCheckedIcon: <RadioButtonCheckedIcon />,
}),
);
function Radio(props) {
const { classes, color, ...other } = props;
const checkedClass = classNames(classes.checked, {
[classes.checkedPrimary]: color === 'primary',
[classes.checkedSecondary]: color === 'secondary',
});
Radio.displayName = 'Radio';
return (
<SwitchBase
type="radio"
icon={<RadioButtonUncheckedIcon />}
checkedIcon={<RadioButtonCheckedIcon />}
classes={{
default: classes.default,
checked: checkedClass,
disabled: classes.disabled,
}}
{...other}
/>
);
}
export default Radio;
type ProvidedProps = {
classes: Object,
};
export type Props = {
Radio.propTypes = {
/**
* If `true`, the component is checked.
*/
checked?: boolean | string,
/**
* The CSS class name of the root element when checked.
*/
checkedClassName?: string,
checked: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
/**
* The icon to display when the component is checked.
* If a string is provided, it will be used as a font ligature.
*/
checkedIcon?: Node,
checkedIcon: PropTypes.node,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
classes: PropTypes.object.isRequired,
/**
* @ignore
* The color of the component. It supports those theme colors that make sense for this component.
*/
className?: string,
/**
* @ignore
*/
defaultChecked?: boolean,
color: PropTypes.oneOf(['primary', 'secondary']),
/**
* If `true`, the switch will be disabled.
*/
disabled?: boolean,
/**
* The CSS class name of the root element when disabled.
*/
disabledClassName?: string,
disabled: PropTypes.bool,
/**
* If `true`, the ripple effect will be disabled.
*/
disableRipple?: boolean,
disableRipple: PropTypes.bool,
/**
* The icon to display when the component is unchecked.
* If a string is provided, it will be used as a font ligature.
*/
icon?: Node,
icon: PropTypes.node,
/**
* The id of the `input` element.
*/
id: PropTypes.string,
/**
* Properties applied to the `input` element.
*/
inputProps?: Object,
inputProps: PropTypes.object,
/**
* Use that property to pass a ref callback to the native input component.
*/
inputRef?: Function,
/*
* @ignore
*/
name?: string,
inputRef: PropTypes.func,
/**
* 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,
onChange: PropTypes.func,
/**
* @ignore
* The input component property `type`.
*/
tabIndex?: number | string,
type: PropTypes.string,
/**
* The value of the component.
*/
value?: string,
value: PropTypes.string,
};
// This is here solely to trigger api doc generation
// eslint-disable-next-line no-unused-vars
export const RadioDocs = (props: ProvidedProps & Props) => <span />;
Radio.defaultProps = {
color: 'secondary',
};
export default withStyles(styles, { name: 'MuiRadio' })(Radio);

View File

@@ -2,19 +2,14 @@ import * as React from 'react';
import { StandardProps } from '..';
import { FormGroupProps, FormGroupClassKey } from '../Form/FormGroup';
export interface RadioGroupProps extends StandardProps<
FormGroupProps,
RadioGroupClassKey,
'onChange'
> {
export interface RadioGroupProps
extends StandardProps<FormGroupProps, RadioGroupClassKey, 'onChange'> {
name?: string;
onChange?: (event: React.ChangeEvent<{}>, value: string) => void;
value?: string;
}
export type RadioGroupClassKey =
| FormGroupClassKey
;
export type RadioGroupClassKey = FormGroupClassKey;
declare const RadioGroup: React.ComponentType<RadioGroupProps>;

View File

@@ -36,6 +36,10 @@ var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _FormGroup = require('../Form/FormGroup');
var _FormGroup2 = _interopRequireDefault(_FormGroup);
@@ -44,44 +48,8 @@ var _helpers = require('../utils/helpers');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
// @inheritedComponent FormGroup
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),
/**
* The name used to reference the value of the control.
*/
name: require('prop-types').string,
/**
* @ignore
*/
onBlur: require('prop-types').func,
/**
* Callback fired when a radio button is selected.
*
* @param {object} event The event source of the callback
* @param {string} value The `value` of the selected radio button
*/
onChange: require('prop-types').func,
/**
* @ignore
*/
onKeyDown: require('prop-types').func,
/**
* Value of the selected radio button.
*/
value: require('prop-types').string
};
var RadioGroup = function (_React$Component) {
(0, _inherits3.default)(RadioGroup, _React$Component);
@@ -168,11 +136,33 @@ var RadioGroup = function (_React$Component) {
}(_react2.default.Component);
RadioGroup.propTypes = process.env.NODE_ENV !== "production" ? {
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
name: require('prop-types').string,
onBlur: require('prop-types').func,
onChange: require('prop-types').func,
onKeyDown: require('prop-types').func,
value: require('prop-types').string
/**
* The content of the component.
*/
children: _propTypes2.default.node,
/**
* The name used to reference the value of the control.
*/
name: _propTypes2.default.string,
/**
* @ignore
*/
onBlur: _propTypes2.default.func,
/**
* Callback fired when a radio button is selected.
*
* @param {object} event The event source of the callback
* @param {string} value The `value` of the selected radio button
*/
onChange: _propTypes2.default.func,
/**
* @ignore
*/
onKeyDown: _propTypes2.default.func,
/**
* Value of the selected radio button.
*/
value: _propTypes2.default.string
} : {};
exports.default = RadioGroup;

View File

@@ -1,43 +1,12 @@
// @flow
// @inheritedComponent FormGroup
import React from 'react';
import type { Node } from 'react';
import PropTypes from 'prop-types';
import FormGroup from '../Form/FormGroup';
import { find } from '../utils/helpers';
export type Props = {
/**
* The content of the component.
*/
children?: Node,
/**
* The name used to reference the value of the control.
*/
name?: string,
/**
* @ignore
*/
onBlur?: Function,
/**
* Callback fired when a radio button is selected.
*
* @param {object} event The event source of the callback
* @param {string} value The `value` of the selected radio button
*/
onChange?: Function,
/**
* @ignore
*/
onKeyDown?: Function,
/**
* Value of the selected radio button.
*/
value?: string,
};
class RadioGroup extends React.Component<Props> {
radios: Array<HTMLInputElement> = [];
class RadioGroup extends React.Component {
radios = [];
focus = () => {
if (!this.radios || !this.radios.length) {
@@ -60,7 +29,7 @@ class RadioGroup extends React.Component<Props> {
focusRadios[0].focus();
};
handleRadioChange = (event: SyntheticInputEvent<*>, checked: boolean) => {
handleRadioChange = (event, checked) => {
if (checked && this.props.onChange) {
this.props.onChange(event, event.target.value);
}
@@ -95,4 +64,34 @@ class RadioGroup extends React.Component<Props> {
}
}
RadioGroup.propTypes = {
/**
* The content of the component.
*/
children: PropTypes.node,
/**
* The name used to reference the value of the control.
*/
name: PropTypes.string,
/**
* @ignore
*/
onBlur: PropTypes.func,
/**
* Callback fired when a radio button is selected.
*
* @param {object} event The event source of the callback
* @param {string} value The `value` of the selected radio button
*/
onChange: PropTypes.func,
/**
* @ignore
*/
onKeyDown: PropTypes.func,
/**
* Value of the selected radio button.
*/
value: PropTypes.string,
};
export default RadioGroup;

View File

@@ -1,4 +1,2 @@
// @flow
export { default } from './Radio';
export { default as RadioGroup } from './RadioGroup';