Skip to content

Instantly share code, notes, and snippets.

@mb8z
Last active October 2, 2018 14:52
Show Gist options
  • Save mb8z/3a2d69b7a51e62529f53f6b144397e44 to your computer and use it in GitHub Desktop.
Save mb8z/3a2d69b7a51e62529f53f6b144397e44 to your computer and use it in GitHub Desktop.
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