react-animated-transitions
Demo.
Installation
yarn add react-transition-group react-animated-transitions animate.css
animate.css
is optional, without it you will have to write your own transition presets. The package includes only a single preset out of the box (a simple fade transition).
Usage
import Animated from 'react-animated-transitions';
<Animated>
<Foo />
</Animated>
<Animated items>
{foos.map(() => <Animated item><Foo /></Animated>)}
</Animated>
With animate.css
transition presets
List of available animations in animate.css
.
import 'animate.css';
<Animated enter="fadeIn" exit="fadeOut" />
<Animated enter="tada" exit="zoomOut" />
import 'animate.css/source/attention_seekers/tada.css';
import 'animate.css/source/zooming_exits/zoomOut.css';
import './duration.css';
Presets are not needed for <Animated items />
, you can use them with <Animated />
and <Animated item />
.
With a custom transition preset
To pass a custom preset, you need to add its css first, which is based on react-transition-group.
.foo-appear,
.foo-enter {
}
.foo-appear-active,
.foo-enter-active {
}
.foo-exit {
}
.foo-exit-active {
}
.fade-appear,
.fade-enter {
opacity: 0;
}
.fade-appear-active,
.fade-enter-active {
opacity: 1;
transition: opacity 1000ms ease-in;
}
.fade-exit {
opacity: 1;
}
.fade-exit-active {
opacity: 0;
transition: opacity 1000ms ease-out;
}
Then in your JavaScript:
import './foo.css';
<Animated preset="foo" />;
Passing a custom timeout
The timeout should match the css transition duration.
<Animated timeout={500} />
<Animated timeout={{ enter: 750, exit: 500 }} />
Overwriting animate.css
default duration
animate.css
presets have a default timeout of 1000ms, to change this number you can overwrite the css.
.animated {
animation-duration: 3000ms;
}
.animated.fadeIn {
animation-duration: 3000ms;
}
Then in your JavaScript:
import './overwrite.css';
<Animated timeout={3000} />;
Disabling animation
Sometimes you may want to prevent your component from animating, but it is still being wrapped in <Animated />
.
<Animated disabled />
Examples
Available here.