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

@@ -0,0 +1,19 @@
import * as React from 'react';
import { StandardProps } from '..';
import { CollapseProps } from '../transitions/Collapse';
import { PaperProps, PaperClassKey } from '../Paper';
export interface ExpansionPanelProps
extends StandardProps<PaperProps, ExpansionPanelClassKey, 'onChange'> {
CollapseProps?: React.ComponentType<CollapseProps>;
defaultExpanded?: boolean;
disabled?: boolean;
expanded?: boolean;
onChange?: (event: React.ChangeEvent<{}>, expanded: boolean) => void;
}
export type ExpansionPanelClassKey = PaperClassKey | 'disabled' | 'expanded';
declare const ExpansionPanel: React.ComponentType<ExpansionPanelProps>;
export default ExpansionPanel;

View File

@@ -0,0 +1,204 @@
import _extends from 'babel-runtime/helpers/extends';
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
// @inheritedComponent Paper
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import Collapse from '../transitions/Collapse';
import Paper from '../Paper';
import withStyles from '../styles/withStyles';
import { isMuiElement } from '../utils/reactHelpers';
export const styles = theme => {
const transition = {
duration: theme.transitions.duration.shortest
};
return {
root: {
position: 'relative',
transition: theme.transitions.create(['margin'], transition),
'&:before': {
position: 'absolute',
left: 0,
top: -1,
right: 0,
height: 1,
content: '""',
opacity: 1,
backgroundColor: theme.palette.divider,
transition: theme.transitions.create(['opacity', 'background-color'], transition)
},
'&:first-child': {
borderTopLeftRadius: 2,
borderTopRightRadius: 2,
'&:before': {
display: 'none'
}
},
'&:last-child': {
borderBottomLeftRadius: 2,
borderBottomRightRadius: 2
},
'&$expanded + &': {
'&:before': {
display: 'none'
}
}
},
expanded: {
margin: `${theme.spacing.unit * 2}px 0`,
'&:first-child': {
marginTop: 0
},
'&:last-child': {
marginBottom: 0
},
'&:before': {
opacity: 0
}
},
disabled: {
backgroundColor: theme.palette.action.disabledBackground
}
};
};
class ExpansionPanel extends React.Component {
constructor(...args) {
var _temp;
return _temp = super(...args), this.state = {
expanded: false
}, this.isControlled = null, this.handleChange = event => {
const { onChange } = this.props;
const expanded = !this.state.expanded;
if (onChange) {
onChange(event, expanded);
}
if (!this.isControlled) {
this.setState({ expanded });
}
}, _temp;
}
componentWillMount() {
const { expanded, defaultExpanded } = this.props;
this.isControlled = expanded != null;
this.setState({
expanded: this.isControlled ? expanded : defaultExpanded
});
}
componentWillReceiveProps(nextProps) {
if (this.isControlled) {
this.setState({
expanded: nextProps.expanded
});
}
}
render() {
const _props = this.props,
{
children: childrenProp,
classes,
className: classNameProp,
CollapseProps: CollapsePropsProp,
defaultExpanded,
disabled,
expanded: expandedProp,
onChange
} = _props,
other = _objectWithoutProperties(_props, ['children', 'classes', 'className', 'CollapseProps', 'defaultExpanded', 'disabled', 'expanded', 'onChange']);
const { expanded } = this.state;
const className = classNames(classes.root, {
[classes.expanded]: expanded,
[classes.disabled]: disabled
}, classNameProp);
let summary = null;
const children = React.Children.map(childrenProp, child => {
if (!React.isValidElement(child)) {
return null;
}
if (isMuiElement(child, ['ExpansionPanelSummary'])) {
summary = React.cloneElement(child, {
disabled,
expanded,
onChange: this.handleChange
});
return null;
}
return child;
});
const CollapseProps = !expanded ? {
'aria-hidden': 'true'
} : null;
return React.createElement(
Paper,
_extends({ className: className, elevation: 1, square: true }, other),
summary,
React.createElement(
Collapse,
_extends({ 'in': expanded, timeout: 'auto' }, CollapseProps, CollapsePropsProp),
children
)
);
}
}
ExpansionPanel.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the expansion panel.
*/
children: PropTypes.node.isRequired,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* Properties applied to the `Collapse` element.
*/
CollapseProps: PropTypes.object,
/**
* If `true`, expands the panel by default.
*/
defaultExpanded: PropTypes.bool,
/**
* If `true`, the panel will be displayed in a disabled state.
*/
disabled: PropTypes.bool,
/**
* If `true`, expands the panel, otherwise collapse it.
* Setting this prop enables control over the panel.
*/
expanded: PropTypes.bool,
/**
* Callback fired when the expand/collapse state is changed.
*
* @param {object} event The event source of the callback
* @param {boolean} expanded The `expanded` state of the panel
*/
onChange: PropTypes.func
} : {};
ExpansionPanel.defaultProps = {
defaultExpanded: false,
disabled: false
};
export default withStyles(styles, { name: 'MuiExpansionPanel' })(ExpansionPanel);

View File

@@ -0,0 +1,11 @@
import * as React from 'react';
import { StandardProps } from '..';
export interface ExpansionPanelActionsProps
extends StandardProps<React.HTMLAttributes<HTMLDivElement>, ExpansionPanelActionsClassKey> {}
export type ExpansionPanelActionsClassKey = 'root' | 'action';
declare const ExpansionPanelActions: React.ComponentType<ExpansionPanelActionsProps>;
export default ExpansionPanelActions;

View File

@@ -0,0 +1,47 @@
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 { cloneChildrenWithClassName } from '../utils/reactHelpers';
export const styles = theme => ({
root: {
display: 'flex',
justifyContent: 'flex-end',
alignItems: 'center',
padding: `${theme.spacing.unit * 2}px ${theme.spacing.unit}px`
},
action: {
marginLeft: theme.spacing.unit
}
});
function ExpansionPanelActions(props) {
const { children, classes, className } = props,
other = _objectWithoutProperties(props, ['children', 'classes', 'className']);
return React.createElement(
'div',
_extends({ className: classNames(classes.root, className) }, other),
cloneChildrenWithClassName(children, classes.action)
);
}
ExpansionPanelActions.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the component.
*/
children: PropTypes.node.isRequired,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string
} : {};
export default withStyles(styles, { name: 'MuiExpansionPanelActions' })(ExpansionPanelActions);

View File

@@ -0,0 +1,11 @@
import * as React from 'react';
import { StandardProps } from '..';
export interface ExpansionPanelDetailsProps
extends StandardProps<React.HTMLAttributes<HTMLDivElement>, ExpansionPanelDetailsClassKey> {}
export type ExpansionPanelDetailsClassKey = 'root';
declare const ExpansionPanelDetails: React.ComponentType<ExpansionPanelDetailsProps>;
export default ExpansionPanelDetails;

View File

@@ -0,0 +1,42 @@
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: {
display: 'flex',
flexGrow: 1,
padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px ${theme.spacing.unit * 3}px`
}
});
function ExpansionPanelDetails(props) {
const { classes, children, className } = props,
other = _objectWithoutProperties(props, ['classes', 'children', 'className']);
return React.createElement(
'div',
_extends({ className: classNames(classes.root, className) }, other),
children
);
}
ExpansionPanelDetails.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the expansion panel details.
*/
children: PropTypes.node.isRequired,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string
} : {};
export default withStyles(styles, { name: 'MuiExpansionPanelDetails' })(ExpansionPanelDetails);

View File

@@ -0,0 +1,25 @@
import * as React from 'react';
import { StandardProps } from '..';
import { ButtonBaseProps, ButtonBaseClassKey } from '../ButtonBase';
export interface ExpansionPanelSummaryProps
extends StandardProps<ButtonBaseProps, ExpansionPanelSummaryClassKey> {
disabled?: boolean;
expanded?: boolean;
expandIcon?: React.ReactNode;
onChange?: React.ReactEventHandler<{}>;
}
export type ExpansionPanelSummaryClassKey =
| ButtonBaseClassKey
| 'expanded'
| 'focused'
| 'disabled'
| 'content'
| 'contentExpanded'
| 'expandIcon'
| 'expandIconExpanded';
declare const ExpansionPanelSummary: React.ComponentType<ExpansionPanelSummaryProps>;
export default ExpansionPanelSummary;

View File

@@ -0,0 +1,182 @@
import _extends from 'babel-runtime/helpers/extends';
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
// @inheritedComponent ButtonBase
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import ButtonBase from '../ButtonBase';
import IconButton from '../IconButton';
import withStyles from '../styles/withStyles';
export const styles = theme => {
const transition = {
duration: theme.transitions.duration.shortest
};
return {
root: {
display: 'flex',
minHeight: theme.spacing.unit * 6,
transition: theme.transitions.create(['min-height', 'background-color'], transition),
padding: `0 ${theme.spacing.unit * 3}px 0 ${theme.spacing.unit * 3}px`,
'&:hover:not($disabled)': {
cursor: 'pointer'
}
},
expanded: {
minHeight: 64
},
focused: {
backgroundColor: theme.palette.grey[300]
},
disabled: {
opacity: 0.38
},
content: {
display: 'flex',
flexGrow: 1,
transition: theme.transitions.create(['margin'], transition),
margin: '12px 0',
'& > :last-child': {
paddingRight: theme.spacing.unit * 4
}
},
contentExpanded: {
margin: '20px 0'
},
expandIcon: {
position: 'absolute',
top: '50%',
right: theme.spacing.unit,
transform: 'translateY(-50%) rotate(0deg)',
transition: theme.transitions.create('transform', transition)
},
expandIconExpanded: {
transform: 'translateY(-50%) rotate(180deg)'
}
};
};
class ExpansionPanelSummary extends React.Component {
constructor(...args) {
var _temp;
return _temp = super(...args), this.state = {
focused: false
}, this.handleFocus = () => {
this.setState({
focused: true
});
}, this.handleBlur = () => {
this.setState({
focused: false
});
}, this.handleChange = event => {
const { onChange, onClick } = this.props;
if (onChange) {
onChange(event);
}
if (onClick) {
onClick(event);
}
}, _temp;
}
render() {
const _props = this.props,
{
children,
classes,
className,
disabled,
expanded,
expandIcon,
onChange
} = _props,
other = _objectWithoutProperties(_props, ['children', 'classes', 'className', 'disabled', 'expanded', 'expandIcon', 'onChange']);
const { focused } = this.state;
return React.createElement(
ButtonBase,
_extends({
focusRipple: false,
disableRipple: true,
disabled: disabled,
component: 'div',
'aria-expanded': expanded,
className: classNames(classes.root, {
[classes.disabled]: disabled,
[classes.expanded]: expanded,
[classes.focused]: focused
}, className)
}, other, {
onKeyboardFocus: this.handleFocus,
onBlur: this.handleBlur,
onClick: this.handleChange
}),
React.createElement(
'div',
{ className: classNames(classes.content, { [classes.contentExpanded]: expanded }) },
children
),
expandIcon && React.createElement(
IconButton,
{
disabled: disabled,
className: classNames(classes.expandIcon, {
[classes.expandIconExpanded]: expanded
}),
component: 'div',
tabIndex: -1,
'aria-hidden': 'true'
},
expandIcon
)
);
}
}
ExpansionPanelSummary.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the expansion panel summary.
*/
children: PropTypes.node,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* @ignore
* If `true`, the summary will be displayed in a disabled state.
*/
disabled: PropTypes.bool,
/**
* @ignore
* If `true`, expands the summary, otherwise collapse it.
*/
expanded: PropTypes.bool,
/**
* The icon to display as the expand indicator.
*/
expandIcon: PropTypes.node,
/**
* @ignore
*/
onChange: PropTypes.func,
/**
* @ignore
*/
onClick: PropTypes.func
} : {};
ExpansionPanelSummary.defaultProps = {
disabled: false
};
ExpansionPanelSummary.muiName = 'ExpansionPanelSummary';
export default withStyles(styles, { name: 'MuiExpansionPanelSummary' })(ExpansionPanelSummary);

View File

@@ -0,0 +1,8 @@
export { default } from './ExpansionPanel';
export * from './ExpansionPanel';
export { default as ExpansionPanelSummary } from './ExpansionPanelSummary';
export * from './ExpansionPanelSummary';
export { default as ExpansionPanelDetails } from './ExpansionPanelDetails';
export * from './ExpansionPanelDetails';
export { default as ExpansionPanelActions } from './ExpansionPanelActions';
export * from './ExpansionPanelActions';

View File

@@ -0,0 +1,4 @@
export { default } from './ExpansionPanel';
export { default as ExpansionPanelActions } from './ExpansionPanelActions';
export { default as ExpansionPanelDetails } from './ExpansionPanelDetails';
export { default as ExpansionPanelSummary } from './ExpansionPanelSummary';