Add Fadable component

This commit is contained in:
Tom Raithel
2017-02-25 23:34:25 +01:00
parent 5e57c9caae
commit 5f20c00bec
9 changed files with 163 additions and 46 deletions

45
js/components/Fadeable.js Normal file
View File

@@ -0,0 +1,45 @@
import React from 'react';
import classNames from 'classnames';
class Fadeable extends React.Component {
constructor(props) {
super(props);
this.state = {
faded: props.leaving,
};
}
componentWillReceiveProps({ leaving }) {
if (!this.props.leaving && leaving) {
this.setState({
...this.state,
faded: true,
});
}
if (this.props.leaving && !leaving) {
this.setState({
...this.state,
faded: false,
});
}
}
handleTransitionEnd = () => {
if (this.state.faded) {
this.props.onLeave();
}
};
render() {
return (
<div
className={classNames('fadable', { 'is-faded': this.state.faded })}
onTransitionEnd={this.handleTransitionEnd}
>
{this.props.children}
</div>
);
}
}
export default Fadeable;