Last active
October 2, 2018 14:52
-
-
Save mb8z/3a2d69b7a51e62529f53f6b144397e44 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { TweenOneGroup } from 'rc-tween-one'; | |
const defaults = { | |
durations: { | |
in: 300, | |
out: 300, | |
width: 300, | |
}, | |
easings: { | |
in: 'easeOutQuart', | |
out: 'easeOutQuart', | |
}, | |
}; | |
const animations = { | |
in: { | |
fade: [ | |
{ opacity: 0, duration: 0 }, | |
{ opacity: 1, duration: defaults.durations.in, ease: defaults.easings.in }, | |
], | |
}, | |
out: { | |
fade:[ | |
{ opacity: 0, duration: defaults.durations.out, ease: defaults.easings.out }, | |
{ width: 0, duration: defaults.durations.width, ease: defaults.easings.in }, | |
], | |
}, | |
}; | |
const Animatable = ({ | |
children, | |
inAnim = 'fade', | |
outAnim = 'fade', | |
...rest | |
}) => { | |
const animationProps = { | |
enter: animations.in[inAnim], | |
leave: animations.out[outAnim], | |
}; | |
return ( | |
<TweenOneGroup | |
appear={false} | |
{...animationProps} | |
{...rest} | |
> | |
{children} | |
</TweenOneGroup> | |
); | |
}; | |
export default Animatable; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment