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,22 +1,17 @@
import * as React from 'react';
import { StandardProps } from '..';
import { Theme } from '../styles/createMuiTheme';
import { TransitionDuration, TransitionProps } from '../internal/transition';
import { TransitionProps } from './transition';
export interface CollapseProps extends StandardProps<
TransitionProps,
CollapseClassKey,
'children'
> {
export interface CollapseProps extends StandardProps<TransitionProps, CollapseClassKey, 'timeout'> {
children?: React.ReactNode;
collapsedHeight?: string;
component?: React.ReactType<CollapseProps>;
theme?: Theme;
timeout?: TransitionDuration | 'auto';
timeout?: TransitionProps['timeout'] | 'auto';
}
export type CollapseClassKey =
| 'container'
| 'entered'
;
export type CollapseClassKey = 'container' | 'entered';
declare const Collapse: React.ComponentType<CollapseProps>;

View File

@@ -1,16 +1,14 @@
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';
// @inheritedComponent Transition
import React from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import Transition from 'react-transition-group/Transition';
import withStyles from '../styles/withStyles';
import { duration } from '../styles/transitions';
import { getTransitionProps } from './utils';
export const styles = theme => ({
container: {
@@ -30,11 +28,16 @@ export const styles = theme => ({
}
});
/**
* The Collapes transition is used by the
* [Vetical Stepper](/demos/steppers#vertical-stepper) StepContent component.
* It uses [react-transition-group](https://github.com/reactjs/react-transition-group) internally.
*/
class Collapse extends React.Component {
constructor(...args) {
var _temp;
return _temp = super(...args), this.wrapper = null, this.autoTransitionDuration = undefined, this.handleEnter = node => {
return _temp = super(...args), this.wrapper = null, this.autoTransitionDuration = undefined, this.timer = null, this.handleEnter = node => {
node.style.height = this.props.collapsedHeight;
if (this.props.onEnter) {
@@ -44,16 +47,16 @@ class Collapse extends React.Component {
const { timeout, theme } = this.props;
const wrapperHeight = this.wrapper ? this.wrapper.clientHeight : 0;
const { duration: transitionDuration } = getTransitionProps(this.props, {
mode: 'enter'
});
if (timeout === 'auto') {
const duration2 = theme.transitions.getAutoHeightDuration(wrapperHeight);
node.style.transitionDuration = `${duration2}ms`;
this.autoTransitionDuration = duration2;
} else if (typeof timeout === 'number') {
node.style.transitionDuration = `${timeout}ms`;
} else if (timeout) {
node.style.transitionDuration = `${timeout.enter}ms`;
} else {
// The propType will warn in this case.
node.style.transitionDuration = typeof transitionDuration === 'string' ? transitionDuration : `${transitionDuration}ms`;
}
node.style.height = `${wrapperHeight}px`;
@@ -78,16 +81,16 @@ class Collapse extends React.Component {
const { timeout, theme } = this.props;
const wrapperHeight = this.wrapper ? this.wrapper.clientHeight : 0;
const { duration: transitionDuration } = getTransitionProps(this.props, {
mode: 'exit'
});
if (timeout === 'auto') {
const duration2 = theme.transitions.getAutoHeightDuration(wrapperHeight);
node.style.transitionDuration = `${duration2}ms`;
this.autoTransitionDuration = duration2;
} else if (typeof timeout === 'number') {
node.style.transitionDuration = `${timeout}ms`;
} else if (timeout) {
node.style.transitionDuration = `${timeout.exit}ms`;
} else {
// The propType will warn in this case.
node.style.transitionDuration = typeof transitionDuration === 'string' ? transitionDuration : `${transitionDuration}ms`;
}
node.style.height = this.props.collapsedHeight;
@@ -95,57 +98,58 @@ class Collapse extends React.Component {
if (this.props.onExiting) {
this.props.onExiting(node);
}
}, this.addEndListener = (node, next) => {
let timeout;
}, this.addEndListener = (_, next) => {
if (this.props.timeout === 'auto') {
timeout = this.autoTransitionDuration || 0;
} else {
timeout = this.props.timeout;
this.timer = setTimeout(next, this.autoTransitionDuration || 0);
}
setTimeout(next, timeout);
}, _temp;
}
componentWillUnmount() {
clearTimeout(this.timer);
}
render() {
const _props = this.props,
{
appear,
children,
classes,
className,
collapsedHeight,
component: Component,
onEnter,
onEntering,
onEntered,
onEntering,
onExit,
onExiting,
style,
timeout,
theme
theme,
timeout
} = _props,
other = _objectWithoutProperties(_props, ['appear', 'children', 'classes', 'collapsedHeight', 'onEnter', 'onEntering', 'onEntered', 'onExit', 'onExiting', 'style', 'timeout', 'theme']);
other = _objectWithoutProperties(_props, ['children', 'classes', 'className', 'collapsedHeight', 'component', 'onEnter', 'onEntered', 'onEntering', 'onExit', 'onExiting', 'style', 'theme', 'timeout']);
return React.createElement(
Transition,
_extends({
appear: appear,
onEntering: this.handleEntering,
onEnter: this.handleEnter,
onEntered: this.handleEntered,
onExiting: this.handleExiting,
onExit: this.handleExit,
addEndListener: this.addEndListener,
style: _extends({ minHeight: collapsedHeight }, style)
timeout: timeout === 'auto' ? null : timeout
}, other),
state => {
(state, childProps) => {
return React.createElement(
'div',
{
Component,
_extends({
className: classNames(classes.container, {
[classes.entered]: state === 'entered'
}, className),
style: _extends({}, style, {
minHeight: collapsedHeight
})
},
}, childProps),
React.createElement(
'div',
{
@@ -166,11 +170,75 @@ class Collapse extends React.Component {
}
}
Collapse.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content node to be collapsed.
*/
children: PropTypes.node,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The height of the container when collapsed.
*/
collapsedHeight: 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 component will transition in.
*/
in: PropTypes.bool,
/**
* @ignore
*/
onEnter: PropTypes.func,
/**
* @ignore
*/
onEntered: PropTypes.func,
/**
* @ignore
*/
onEntering: PropTypes.func,
/**
* @ignore
*/
onExit: PropTypes.func,
/**
* @ignore
*/
onExiting: PropTypes.func,
/**
* @ignore
*/
style: PropTypes.object,
/**
* @ignore
*/
theme: PropTypes.object.isRequired,
/**
* The duration for the transition, in milliseconds.
* You may specify a single timeout for all transitions, or individually with an object.
*
* Set to 'auto' to automatically calculate transition time based on height.
*/
timeout: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({ enter: PropTypes.number, exit: PropTypes.number }), PropTypes.oneOf(['auto'])])
} : {};
Collapse.defaultProps = {
appear: false,
collapsedHeight: '0px',
component: 'div',
timeout: duration.standard
};
export default withStyles(styles, {
withTheme: true,
name: 'MuiCollapse'

View File

@@ -1,10 +1,9 @@
import * as React from 'react';
import { Theme } from '../styles/createMuiTheme';
import { TransitionDuration, TransitionProps } from '../internal/transition';
import { TransitionProps } from './transition';
export interface FadeProps extends TransitionProps {
theme?: Theme;
timeout?: TransitionDuration;
}
declare const Fade: React.ComponentType<FadeProps>;

View File

@@ -1,57 +1,63 @@
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';
// @inheritedComponent Transition
import React from 'react';
import PropTypes from 'prop-types';
import Transition from 'react-transition-group/Transition';
import { duration } from '../styles/transitions';
import withTheme from '../styles/withTheme';
import { reflow, getTransitionProps } from './utils';
const reflow = node => node.scrollTop;
const styles = {
entering: {
opacity: 1
},
entered: {
opacity: 1
}
};
/**
* The Fade transition is used by the Modal component.
* It's using [react-transition-group](https://github.com/reactjs/react-transition-group) internally.
* The Fade transition is used by the [Modal](/demos/modals) component.
* It uses [react-transition-group](https://github.com/reactjs/react-transition-group) internally.
*/
class Fade extends React.Component {
constructor(...args) {
var _temp;
return _temp = super(...args), this.handleEnter = node => {
node.style.opacity = '0';
reflow(node);
const { theme } = this.props;
reflow(node); // So the animation always start from the start.
const { duration: transitionDuration, delay } = getTransitionProps(this.props, {
mode: 'enter'
});
node.style.transition = theme.transitions.create('opacity', {
duration: transitionDuration,
delay
});
node.style.webkitTransition = theme.transitions.create('opacity', {
duration: transitionDuration,
delay
});
if (this.props.onEnter) {
this.props.onEnter(node);
}
}, this.handleEntering = node => {
const { theme, timeout } = this.props;
node.style.transition = theme.transitions.create('opacity', {
duration: typeof timeout === 'number' ? timeout : timeout.enter
});
// $FlowFixMe - https://github.com/facebook/flow/pull/5161
node.style.webkitTransition = theme.transitions.create('opacity', {
duration: typeof timeout === 'number' ? timeout : timeout.enter
});
node.style.opacity = '1';
if (this.props.onEntering) {
this.props.onEntering(node);
}
}, this.handleExit = node => {
const { theme, timeout } = this.props;
const { theme } = this.props;
const { duration: transitionDuration, delay } = getTransitionProps(this.props, {
mode: 'exit'
});
node.style.transition = theme.transitions.create('opacity', {
duration: typeof timeout === 'number' ? timeout : timeout.exit
duration: transitionDuration,
delay
});
// $FlowFixMe - https://github.com/facebook/flow/pull/5161
node.style.webkitTransition = theme.transitions.create('opacity', {
duration: typeof timeout === 'number' ? timeout : timeout.exit
duration: transitionDuration,
delay
});
node.style.opacity = '0';
if (this.props.onExit) {
this.props.onExit(node);
@@ -61,43 +67,66 @@ class Fade extends React.Component {
render() {
const _props = this.props,
{
appear,
children,
onEnter,
onEntering,
onExit,
style: styleProp,
theme
} = _props,
other = _objectWithoutProperties(_props, ['appear', 'children', 'onEnter', 'onEntering', 'onExit', 'style', 'theme']);
{ children, onEnter, onExit, style: styleProp, theme } = _props,
other = _objectWithoutProperties(_props, ['children', 'onEnter', 'onExit', 'style', 'theme']);
const style = _extends({}, styleProp);
// For server side rendering.
if (!this.props.in || appear) {
style.opacity = '0';
}
const style = _extends({}, styleProp, React.isValidElement(children) ? children.props.style : {});
return React.createElement(
Transition,
_extends({
appear: appear,
style: style,
onEnter: this.handleEnter,
onEntering: this.handleEntering,
onExit: this.handleExit
}, other),
children
_extends({ appear: true, onEnter: this.handleEnter, onExit: this.handleExit }, other),
(state, childProps) => {
return React.cloneElement(children, _extends({
style: _extends({
opacity: 0
}, styles[state], style)
}, childProps));
}
);
}
}
Fade.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* A single child content element.
*/
children: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
/**
* If `true`, the component will transition in.
*/
in: PropTypes.bool,
/**
* @ignore
*/
onEnter: PropTypes.func,
/**
* @ignore
*/
onEntering: PropTypes.func,
/**
* @ignore
*/
onExit: PropTypes.func,
/**
* @ignore
*/
style: PropTypes.object,
/**
* @ignore
*/
theme: PropTypes.object.isRequired,
/**
* The duration for the transition, in milliseconds.
* You may specify a single timeout for all transitions, or individually with an object.
*/
timeout: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({ enter: PropTypes.number, exit: PropTypes.number })])
} : {};
Fade.defaultProps = {
appear: true,
timeout: {
enter: duration.enteringScreen,
exit: duration.leavingScreen
}
};
export default withTheme()(Fade);

View File

@@ -1,10 +1,11 @@
import * as React from 'react';
import { Omit } from '..';
import { Theme } from '../styles/createMuiTheme';
import { TransitionDuration, TransitionProps } from '../internal/transition';
import { TransitionProps } from './transition';
export interface GrowProps extends TransitionProps {
export interface GrowProps extends Omit<TransitionProps, 'timeout'> {
theme?: Theme;
timeout?: TransitionDuration | 'auto';
timeout?: TransitionProps['timeout'] | 'auto';
}
declare const Grow: React.ComponentType<GrowProps>;

View File

@@ -1,82 +1,82 @@
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; }
// @inheritedComponent CSSTransition
import _extends from 'babel-runtime/helpers/extends';
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
// @inheritedComponent Transition
import React from 'react';
import CSSTransition from 'react-transition-group/CSSTransition';
import PropTypes from 'prop-types';
import Transition from 'react-transition-group/Transition';
import withTheme from '../styles/withTheme';
import { reflow, getTransitionProps } from './utils';
// Only exported for tests.
export function getScale(value) {
function getScale(value) {
return `scale(${value}, ${Math.pow(value, 2)})`;
}
const styles = {
entering: {
opacity: 1,
transform: getScale(1)
},
entered: {
opacity: 1,
transform: getScale(1)
}
};
/**
* The Grow transition is used by the Popover component.
* It's using [react-transition-group](https://github.com/reactjs/react-transition-group) internally.
* The Grow transition is used by the [Popover](/demos/popovers) component.
* It uses [react-transition-group](https://github.com/reactjs/react-transition-group) internally.
*/
class Grow extends React.Component {
constructor(...args) {
var _temp;
return _temp = super(...args), this.autoTimeout = undefined, this.handleEnter = node => {
node.style.opacity = '0';
node.style.transform = getScale(0.75);
if (this.props.onEnter) {
this.props.onEnter(node);
}
}, this.handleEntering = node => {
return _temp = super(...args), this.autoTimeout = undefined, this.timer = null, this.handleEnter = node => {
const { theme, timeout } = this.props;
let duration = 0;
reflow(node); // So the animation always start from the start.
const { duration: transitionDuration, delay } = getTransitionProps(this.props, {
mode: 'enter'
});
let duration = 0;
if (timeout === 'auto') {
duration = theme.transitions.getAutoHeightDuration(node.clientHeight);
this.autoTimeout = duration;
} else if (typeof timeout === 'number') {
duration = timeout;
} else if (timeout) {
duration = timeout.enter;
} else {
// The propType will warn in this case.
duration = transitionDuration;
}
node.style.transition = [theme.transitions.create('opacity', {
duration
duration,
delay
}), theme.transitions.create('transform', {
duration: duration * 0.666
duration: duration * 0.666,
delay
})].join(',');
node.style.opacity = '1';
node.style.transform = getScale(1);
if (this.props.onEntering) {
this.props.onEntering(node);
if (this.props.onEnter) {
this.props.onEnter(node);
}
}, this.handleExit = node => {
const { theme, timeout } = this.props;
let duration = 0;
const { duration: transitionDuration, delay } = getTransitionProps(this.props, {
mode: 'exit'
});
if (timeout === 'auto') {
duration = theme.transitions.getAutoHeightDuration(node.clientHeight);
this.autoTimeout = duration;
} else if (typeof timeout === 'number') {
duration = timeout;
} else if (timeout) {
duration = timeout.exit;
} else {
// The propType will warn in this case.
duration = transitionDuration;
}
node.style.transition = [theme.transitions.create('opacity', {
duration
duration,
delay
}), theme.transitions.create('transform', {
duration: duration * 0.666,
delay: duration * 0.333
delay: delay || duration * 0.333
})].join(',');
node.style.opacity = '0';
@@ -85,63 +85,89 @@ class Grow extends React.Component {
if (this.props.onExit) {
this.props.onExit(node);
}
}, this.addEndListener = (node, next) => {
let timeout;
}, this.addEndListener = (_, next) => {
if (this.props.timeout === 'auto') {
timeout = this.autoTimeout || 0;
} else {
timeout = this.props.timeout;
this.timer = setTimeout(next, this.autoTimeout || 0);
}
setTimeout(next, timeout);
}, _temp;
}
componentWillUnmount() {
clearTimeout(this.timer);
}
render() {
const _props = this.props,
{
appear,
children,
onEnter,
onEntering,
onExit,
rootRef,
style: styleProp,
transitionClasses,
timeout,
theme
} = _props,
other = _objectWithoutProperties(_props, ['appear', 'children', 'onEnter', 'onEntering', 'onExit', 'rootRef', 'style', 'transitionClasses', 'timeout', 'theme']);
{ children, onEnter, onExit, style: styleProp, theme, timeout } = _props,
other = _objectWithoutProperties(_props, ['children', 'onEnter', 'onExit', 'style', 'theme', 'timeout']);
const style = _extends({}, children.props.style, styleProp);
// For server side rendering.
if (!this.props.in || appear) {
style.opacity = '0';
}
const style = _extends({}, styleProp, React.isValidElement(children) ? children.props.style : {});
return React.createElement(
CSSTransition,
Transition,
_extends({
classNames: transitionClasses,
appear: true,
onEnter: this.handleEnter,
onEntering: this.handleEntering,
onExit: this.handleExit,
addEndListener: this.addEndListener,
appear: appear,
style: style
}, other, {
ref: rootRef
}),
children
timeout: timeout === 'auto' ? null : timeout
}, other),
(state, childProps) => {
return React.cloneElement(children, _extends({
style: _extends({
opacity: 0,
transform: getScale(0.75)
}, styles[state], style)
}, childProps));
}
);
}
}
Grow.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* A single child content element.
*/
children: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
/**
* If `true`, show the component; triggers the enter or exit animation.
*/
in: PropTypes.bool,
/**
* @ignore
*/
onEnter: PropTypes.func,
/**
* @ignore
*/
onEntered: PropTypes.func,
/**
* @ignore
*/
onEntering: PropTypes.func,
/**
* @ignore
*/
onExit: PropTypes.func,
/**
* @ignore
*/
style: PropTypes.object,
/**
* @ignore
*/
theme: PropTypes.object.isRequired,
/**
* The duration for the transition, in milliseconds.
* You may specify a single timeout for all transitions, or individually with an object.
*
* Set to 'auto' to automatically calculate transition time based on height.
*/
timeout: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({ enter: PropTypes.number, exit: PropTypes.number }), PropTypes.oneOf(['auto'])])
} : {};
Grow.defaultProps = {
appear: true,
timeout: 'auto',
transitionClasses: {}
timeout: 'auto'
};
export default withTheme()(Grow);

View File

@@ -1,11 +1,10 @@
import * as React from 'react';
import { Theme } from '../styles/createMuiTheme';
import { TransitionDuration, TransitionProps } from '../internal/transition';
import { TransitionProps } from './transition';
export interface SlideProps extends TransitionProps {
direction?: 'left' | 'right' | 'up' | 'down';
direction: 'left' | 'right' | 'up' | 'down';
theme?: Theme;
timeout?: TransitionDuration;
}
declare const Slide: React.ComponentType<SlideProps>;

View File

@@ -1,18 +1,17 @@
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';
// @inheritedComponent Transition
import React from 'react';
import PropTypes from 'prop-types';
import { findDOMNode } from 'react-dom';
import EventListener from 'react-event-listener';
import debounce from 'lodash/debounce';
import Transition from 'react-transition-group/Transition';
import ownerWindow from 'dom-helpers/ownerWindow';
import withTheme from '../styles/withTheme';
import { duration } from '../styles/transitions';
import { reflow, getTransitionProps } from './utils';
const GUTTER = 24;
@@ -28,7 +27,7 @@ function getTranslateValue(props, node) {
if (node.fakeTransform) {
transform = node.fakeTransform;
} else {
const computedStyle = window.getComputedStyle(node);
const computedStyle = ownerWindow(node).getComputedStyle(node);
transform = computedStyle.getPropertyValue('-webkit-transform') || computedStyle.getPropertyValue('transform');
}
@@ -49,7 +48,7 @@ function getTranslateValue(props, node) {
return `translateY(100vh) translateY(-${rect.top - offsetY}px)`;
}
// direction === 'down
// direction === 'down'
return `translate3d(0, ${0 - (rect.top + rect.height)}px, 0)`;
}
@@ -62,15 +61,16 @@ export function setTranslateValue(props, node) {
}
}
const reflow = node => node.scrollTop;
/**
* The Slide transition is used by the [Snackbar](/demos/snackbars) component.
* It uses [react-transition-group](https://github.com/reactjs/react-transition-group) internally.
*/
class Slide extends React.Component {
constructor(...args) {
var _temp;
return _temp = super(...args), this.state = {
// We use this state to handle the server-side rendering.
firstMount: true
mounted: false
}, this.transition = null, this.handleResize = debounce(() => {
// Skip configuration where the position is screen size invariant.
if (this.props.in || this.props.direction === 'down' || this.props.direction === 'right') {
@@ -78,7 +78,7 @@ class Slide extends React.Component {
}
const node = findDOMNode(this.transition);
if (node instanceof HTMLElement) {
if (node) {
setTranslateValue(this.props, node);
}
}, 166), this.handleEnter = node => {
@@ -89,15 +89,20 @@ class Slide extends React.Component {
this.props.onEnter(node);
}
}, this.handleEntering = node => {
const { theme, timeout } = this.props;
node.style.transition = theme.transitions.create('transform', {
duration: typeof timeout === 'number' ? timeout : timeout.enter,
easing: theme.transitions.easing.easeOut
const { theme } = this.props;
const { duration: transitionDuration, delay } = getTransitionProps(this.props, {
mode: 'enter'
});
node.style.transition = theme.transitions.create('transform', {
duration: transitionDuration,
easing: theme.transitions.easing.easeOut,
delay
});
// $FlowFixMe - https://github.com/facebook/flow/pull/5161
node.style.webkitTransition = theme.transitions.create('-webkit-transform', {
duration: typeof timeout === 'number' ? timeout : timeout.enter,
easing: theme.transitions.easing.easeOut
duration: transitionDuration,
easing: theme.transitions.easing.easeOut,
delay
});
node.style.transform = 'translate3d(0, 0, 0)';
node.style.webkitTransform = 'translate3d(0, 0, 0)';
@@ -105,59 +110,97 @@ class Slide extends React.Component {
this.props.onEntering(node);
}
}, this.handleExit = node => {
const { theme, timeout } = this.props;
node.style.transition = theme.transitions.create('transform', {
duration: typeof timeout === 'number' ? timeout : timeout.exit,
easing: theme.transitions.easing.sharp
const { theme } = this.props;
const { duration: transitionDuration, delay } = getTransitionProps(this.props, {
mode: 'exit'
});
node.style.transition = theme.transitions.create('transform', {
duration: transitionDuration,
easing: theme.transitions.easing.sharp,
delay
});
// $FlowFixMe - https://github.com/facebook/flow/pull/5161
node.style.webkitTransition = theme.transitions.create('-webkit-transform', {
duration: typeof timeout === 'number' ? timeout : timeout.exit,
easing: theme.transitions.easing.sharp
duration: transitionDuration,
easing: theme.transitions.easing.sharp,
delay
});
setTranslateValue(this.props, node);
if (this.props.onExit) {
this.props.onExit(node);
}
}, this.handleExited = node => {
// No need for transitions when the component is hidden
node.style.transition = '';
node.style.webkitTransition = '';
if (this.props.onExited) {
this.props.onExited(node);
}
}, _temp;
}
componentDidMount() {
// state.firstMount handle SSR, once the component is mounted, we need
// to propery hide it.
// state.mounted handle SSR, once the component is mounted, we need
// to properly hide it.
if (!this.props.in) {
// We need to set initial translate values of transition element
// otherwise component will be shown when in=false.
const element = findDOMNode(this.transition);
if (element instanceof HTMLElement) {
element.style.visibility = 'inherit';
setTranslateValue(this.props, element);
}
this.updatePosition();
}
}
componentWillReceiveProps() {
this.setState({
firstMount: false
mounted: true
});
}
componentDidUpdate(prevProps) {
if (prevProps.direction !== this.props.direction && !this.props.in) {
// We need to update the position of the drawer when the direction change and
// when it's hidden.
this.updatePosition();
}
}
componentWillUnmount() {
this.handleResize.cancel();
}
updatePosition() {
const node = findDOMNode(this.transition);
if (node) {
node.style.visibility = 'inherit';
setTranslateValue(this.props, node);
}
}
render() {
const _props = this.props,
{ children, onEnter, onEntering, onExit, style: styleProp, theme } = _props,
other = _objectWithoutProperties(_props, ['children', 'onEnter', 'onEntering', 'onExit', 'style', 'theme']);
{
children,
onEnter,
onEntering,
onExit,
onExited,
style: styleProp,
theme
} = _props,
other = _objectWithoutProperties(_props, ['children', 'onEnter', 'onEntering', 'onExit', 'onExited', 'style', 'theme']);
const style = _extends({}, styleProp);
let style = {};
if (!this.props.in && this.state.firstMount) {
// We use this state to handle the server-side rendering.
// We don't know the width of the children ahead of time.
// We need to render it.
if (!this.props.in && !this.state.mounted) {
style.visibility = 'hidden';
}
style = _extends({}, style, styleProp, React.isValidElement(children) ? children.props.style : {});
return React.createElement(
EventListener,
{ target: 'window', onResize: this.handleResize },
@@ -167,19 +210,71 @@ class Slide extends React.Component {
onEnter: this.handleEnter,
onEntering: this.handleEntering,
onExit: this.handleExit,
onExited: this.handleExited,
appear: true,
style: style
}, other, {
style: style,
ref: node => {
this.transition = node;
}
}),
}, other),
children
)
);
}
}
Slide.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* A single child content element.
*/
children: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
/**
* Direction the child node will enter from.
*/
direction: PropTypes.oneOf(['left', 'right', 'up', 'down']),
/**
* If `true`, show the component; triggers the enter or exit animation.
*/
in: PropTypes.bool,
/**
* @ignore
*/
onEnter: PropTypes.func,
/**
* @ignore
*/
onEntered: PropTypes.func,
/**
* @ignore
*/
onEntering: PropTypes.func,
/**
* @ignore
*/
onExit: PropTypes.func,
/**
* @ignore
*/
onExited: PropTypes.func,
/**
* @ignore
*/
onExiting: PropTypes.func,
/**
* @ignore
*/
style: PropTypes.object,
/**
* @ignore
*/
theme: PropTypes.object.isRequired,
/**
* The duration for the transition, in milliseconds.
* You may specify a single timeout for all transitions, or individually with an object.
*/
timeout: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({ enter: PropTypes.number, exit: PropTypes.number })])
} : {};
Slide.defaultProps = {
direction: 'down',
timeout: {
@@ -187,4 +282,5 @@ Slide.defaultProps = {
exit: duration.leavingScreen
}
};
export default withTheme()(Slide);

View File

@@ -0,0 +1,11 @@
import * as React from 'react';
import { Theme } from '../styles/createMuiTheme';
import { TransitionProps } from './transition';
export interface ZoomProps extends TransitionProps {
theme?: Theme;
}
declare const Zoom: React.ComponentType<ZoomProps>;
export default Zoom;

View File

@@ -0,0 +1,129 @@
import _extends from 'babel-runtime/helpers/extends';
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
// @inheritedComponent Transition
import React from 'react';
import PropTypes from 'prop-types';
import Transition from 'react-transition-group/Transition';
import { duration } from '../styles/transitions';
import withTheme from '../styles/withTheme';
import { reflow, getTransitionProps } from './utils';
const styles = {
entering: {
transform: 'scale(1)'
},
entered: {
transform: 'scale(1)'
}
};
/**
* The Zoom transition can be used for the floating variant of the
* [Button](https://material-ui-next.com/demos/buttons/#floating-action-buttons) component.
* It uses [react-transition-group](https://github.com/reactjs/react-transition-group) internally.
*/
class Zoom extends React.Component {
constructor(...args) {
var _temp;
return _temp = super(...args), this.handleEnter = node => {
const { theme } = this.props;
reflow(node); // So the animation always start from the start.
const { duration: transitionDuration, delay } = getTransitionProps(this.props, {
mode: 'enter'
});
node.style.transition = theme.transitions.create('transform', {
duration: transitionDuration,
delay
});
node.style.webkitTransition = theme.transitions.create('transform', {
duration: transitionDuration,
delay
});
if (this.props.onEnter) {
this.props.onEnter(node);
}
}, this.handleExit = node => {
const { theme } = this.props;
const { duration: transitionDuration, delay } = getTransitionProps(this.props, {
mode: 'exit'
});
node.style.transition = theme.transitions.create('transform', {
duration: transitionDuration,
delay
});
node.style.webkitTransition = theme.transitions.create('transform', {
duration: transitionDuration,
delay
});
if (this.props.onExit) {
this.props.onExit(node);
}
}, _temp;
}
render() {
const _props = this.props,
{ children, onEnter, onExit, style: styleProp, theme } = _props,
other = _objectWithoutProperties(_props, ['children', 'onEnter', 'onExit', 'style', 'theme']);
const style = _extends({}, styleProp, React.isValidElement(children) ? children.props.style : {});
return React.createElement(
Transition,
_extends({ appear: true, onEnter: this.handleEnter, onExit: this.handleExit }, other),
(state, childProps) => {
return React.cloneElement(children, _extends({
style: _extends({
transform: 'scale(0)'
}, styles[state], style)
}, childProps));
}
);
}
}
Zoom.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* A single child content element.
*/
children: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
/**
* If `true`, the component will transition in.
*/
in: PropTypes.bool,
/**
* @ignore
*/
onEnter: PropTypes.func,
/**
* @ignore
*/
onExit: PropTypes.func,
/**
* @ignore
*/
style: PropTypes.object,
/**
* @ignore
*/
theme: PropTypes.object.isRequired,
/**
* The duration for the transition, in milliseconds.
* You may specify a single timeout for all transitions, or individually with an object.
*/
timeout: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({ enter: PropTypes.number, exit: PropTypes.number })])
} : {};
Zoom.defaultProps = {
timeout: {
enter: duration.enteringScreen,
exit: duration.leavingScreen
}
};
export default withTheme()(Zoom);

View File

@@ -0,0 +1,10 @@
export { default as Slide } from './Slide';
export * from './Slide';
export { default as Grow } from './Grow';
export * from './Grow';
export { default as Fade } from './Fade';
export * from './Fade';
export { default as Collapse } from './Collapse';
export * from './Collapse';
export { default as Zoom } from './Zoom';
export * from './Zoom';

View File

@@ -0,0 +1,5 @@
export { default as Slide } from './Slide';
export { default as Grow } from './Grow';
export { default as Fade } from './Fade';
export { default as Collapse } from './Collapse';
export { default as Zoom } from './Zoom';

View File

@@ -0,0 +1,25 @@
import {
TransitionProps as _TransitionProps,
TransitionActions,
} from 'react-transition-group/Transition';
import { TransitionEventHandler } from 'react';
export type TransitionHandlerKeys =
| 'onEnter'
| 'onEntering'
| 'onEntered'
| 'onExit'
| 'onExiting'
| 'onExited';
export type TransitionHandlerProps = Pick<_TransitionProps, TransitionHandlerKeys>;
export type TransitionKeys =
| 'in'
| 'mountOnEnter'
| 'unmountOnExit'
| 'timeout'
| 'addEndListener'
| TransitionHandlerKeys;
export interface TransitionProps
extends TransitionActions,
Partial<Pick<_TransitionProps, TransitionKeys>> {}

View File

@@ -0,0 +1,10 @@
export const reflow = node => node.scrollTop;
export function getTransitionProps(props, options) {
const { timeout, style = {} } = props;
return {
duration: style.transitionDuration || typeof timeout === 'number' ? timeout : timeout[options.mode],
delay: style.transitionDelay
};
}