Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transition group #2676

Merged
merged 6 commits into from
Jul 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10,326 changes: 10,326 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@
"keycode": "^2.1.2",
"prop-types": "^15.5.6",
"prop-types-extra": "^1.0.1",
"react-overlays": "^0.7.0",
"react-overlays": "^0.8.0",
"react-prop-types": "^0.4.0",
"react-transition-group": "^2.0.0",
"uncontrollable": "^4.1.0",
"warning": "^3.0.0"
},
Expand Down
72 changes: 35 additions & 37 deletions src/Collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import classNames from 'classnames';
import css from 'dom-helpers/style';
import React from 'react';
import PropTypes from 'prop-types';
import Transition from 'react-overlays/lib/Transition';
import Transition, { EXITED, ENTERED, ENTERING, EXITING }
from 'react-transition-group/Transition';

import capitalize from './utils/capitalize';
import createChainedFunction from './utils/createChainedFunction';
Expand All @@ -28,6 +29,13 @@ function getDimensionValue(dimension, elem) {
);
}

const collapseStyles = {
[EXITED]: 'collapse',
[EXITING]: 'collapsing',
[ENTERING]: 'collapsing',
[ENTERED]: 'collapse in',
};

const propTypes = {
/**
* Show the component; triggers the expand or collapse animation
Expand All @@ -48,7 +56,7 @@ const propTypes = {
* Run the expand animation when the component mounts, if it is initially
* shown
*/
transitionAppear: PropTypes.bool,
appear: PropTypes.bool,

/**
* Duration of the collapse animation in milliseconds, to ensure that
Expand Down Expand Up @@ -114,52 +122,40 @@ const defaultProps = {
timeout: 300,
mountOnEnter: false,
unmountOnExit: false,
transitionAppear: false,
appear: false,

dimension: 'height',
getDimensionValue,
};

class Collapse extends React.Component {
constructor(props, context) {
super(props, context);

this.handleEnter = this.handleEnter.bind(this);
this.handleEntering = this.handleEntering.bind(this);
this.handleEntered = this.handleEntered.bind(this);
this.handleExit = this.handleExit.bind(this);
this.handleExiting = this.handleExiting.bind(this);
}

/* -- Expanding -- */
handleEnter(elem) {
const dimension = this._dimension();
elem.style[dimension] = '0';
handleEnter = (elem) => {
elem.style[this.getDimension()] = '0';
}

handleEntering(elem) {
const dimension = this._dimension();
handleEntering = (elem) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we enabled this transform? nice

const dimension = this.getDimension();
elem.style[dimension] = this._getScrollDimensionValue(elem, dimension);
}

handleEntered(elem) {
const dimension = this._dimension();
elem.style[dimension] = null;
handleEntered = (elem) => {
elem.style[this.getDimension()] = null;
}

/* -- Collapsing -- */
handleExit(elem) {
const dimension = this._dimension();
handleExit = (elem) => {
const dimension = this.getDimension();
elem.style[dimension] = this.props.getDimensionValue(dimension, elem) + 'px';
triggerBrowserReflow(elem);
}

handleExiting(elem) {
const dimension = this._dimension();
elem.style[dimension] = '0';
handleExiting = (elem) => {
elem.style[this.getDimension()] = '0';
}

_dimension() {
getDimension() {
return typeof this.props.dimension === 'function'
? this.props.dimension()
: this.props.dimension;
Expand All @@ -172,7 +168,8 @@ class Collapse extends React.Component {

render() {
const {
onEnter, onEntering, onEntered, onExit, onExiting, className, ...props
onEnter, onEntering, onEntered, onExit, onExiting,
className, children, ...props
} = this.props;

delete props.dimension;
Expand All @@ -189,25 +186,26 @@ class Collapse extends React.Component {
const handleExiting =
createChainedFunction(this.handleExiting, onExiting);

const classes = {
width: this._dimension() === 'width',
};

return (
<Transition
{...props}
aria-expanded={props.role ? props.in : null}
className={classNames(className, classes)}
exitedClassName="collapse"
exitingClassName="collapsing"
enteredClassName="collapse in"
enteringClassName="collapsing"
onEnter={handleEnter}
onEntering={handleEntering}
onEntered={handleEntered}
onExit={handleExit}
onExiting={handleExiting}
/>
>
{(state, innerProps) => React.cloneElement(children, {
...innerProps,
className: classNames(
className,
children.props.className,
collapseStyles[state],
this.getDimension() === 'width' && 'width'
)
})}
</Transition>
);
}
}
Expand Down
32 changes: 23 additions & 9 deletions src/Fade.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import classNames from 'classnames';
import React from 'react';
import PropTypes from 'prop-types';
import Transition from 'react-overlays/lib/Transition';
import Transition, { ENTERED, ENTERING }
from 'react-transition-group/Transition';

const propTypes = {
/**
Expand All @@ -23,7 +24,7 @@ const propTypes = {
* Run the fade in animation when the component mounts, if it is initially
* shown
*/
transitionAppear: PropTypes.bool,
appear: PropTypes.bool,

/**
* Duration of the fade animation in milliseconds, to ensure that finishing
Expand Down Expand Up @@ -63,18 +64,31 @@ const defaultProps = {
timeout: 300,
mountOnEnter: false,
unmountOnExit: false,
transitionAppear: false,
appear: false,
};


const fadeStyles = {
[ENTERING]: 'in',
[ENTERED]: 'in',
};

class Fade extends React.Component {
render() {
const { className, children, ...props } = this.props;

return (
<Transition
{...this.props}
className={classNames(this.props.className, 'fade')}
enteredClassName="in"
enteringClassName="in"
/>
<Transition {...props}>
{(status, innerProps) => React.cloneElement(children, {
...innerProps,
className: classNames(
'fade',
className,
children.props.className,
fadeStyles[status]
),
})}
</Transition>
);
}
}
Expand Down
22 changes: 16 additions & 6 deletions src/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ const childContextTypes = {
}),
};

/* eslint-disable no-use-before-define, react/no-multi-comp */
function DialogTransition(props) {
return <Fade {...props} timeout={Modal.TRANSITION_DURATION} />;
}

function BackdropTransition(props) {
return <Fade {...props} timeout={Modal.BACKDROP_TRANSITION_DURATION} />;
}

/* eslint-enable no-use-before-define */

class Modal extends React.Component {
constructor(props, context) {
super(props, context);
Expand Down Expand Up @@ -227,14 +238,13 @@ class Modal extends React.Component {
{...baseModalProps}
ref={c => { this._modal = c; }}
show={show}
onEntering={createChainedFunction(onEntering, this.handleEntering)}
onExited={createChainedFunction(onExited, this.handleExited)}
containerClassName={prefix(props, 'open')}
transition={animation ? DialogTransition : undefined}
backdrop={backdrop}
backdropTransition={animation ? BackdropTransition : undefined}
backdropClassName={classNames(prefix(props, 'backdrop'), inClassName)}
containerClassName={prefix(props, 'open')}
transition={animation ? Fade : undefined}
dialogTransitionTimeout={Modal.TRANSITION_DURATION}
backdropTransitionTimeout={Modal.BACKDROP_TRANSITION_DURATION}
onEntering={createChainedFunction(onEntering, this.handleEntering)}
onExited={createChainedFunction(onExited, this.handleExited)}
>
<Dialog
{...dialogProps}
Expand Down
4 changes: 2 additions & 2 deletions src/TabContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const propTypes = {

/**
* Sets a default animation strategy for all children `<TabPane>`s. Use
* `false` to disable, `true` to enable the default `<Fade>` animation or any
* `<Transition>` component.
* `false` to disable, `true` to enable the default `<Fade>` animation or
* a react-transition-group v2 `<Transition/>` component.
*/
animation: PropTypes.oneOfType([
PropTypes.bool, elementType,
Expand Down
4 changes: 2 additions & 2 deletions src/TabPane.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const propTypes = {

/**
* Use animation when showing or hiding `<TabPane>`s. Use `false` to disable,
* `true` to enable the default `<Fade>` animation or any `<Transition>`
* component.
* `true` to enable the default `<Fade>` animation or
* a react-transition-group v2 `<Transition/>` component.
*/
animation: PropTypes.oneOfType([PropTypes.bool, elementType]),

Expand Down
4 changes: 2 additions & 2 deletions test/CollapseSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ describe('<Collapse>', () => {
});

it('Defaults to height', () => {
assert.equal(instance.collapse._dimension(), 'height');
assert.equal(instance.collapse.getDimension(), 'height');
});

it('Uses getCollapsibleDimension if exists', () => {
Expand All @@ -215,7 +215,7 @@ describe('<Collapse>', () => {

instance.setState({ dimension });

assert.equal(instance.collapse._dimension(), 'whatevs');
assert.equal(instance.collapse.getDimension(), 'whatevs');
});
});

Expand Down