react-animated-transitions
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
; // animate a child (when mounted/unmounted)<Animated> <Foo /></Animated> // animate a group of children<Animated items> foos</Animated>
animate.css
transition presets
With List of available animations in animate.css
.
; // once, you don't need it if you are using your custom presets// you can also create a custom build with only the presets you are using // you can use any combination<Animated enter="fadeIn" exit="fadeOut" /><Animated enter="tada" exit="zoomOut" /> // you can import presets individually as well;; // when you import individually, you need add the duration to your css /* duration.css */ animated animation-duration: 1000ms; ; // after individual imports
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.css */ /* example: fade.css */
Then in your JavaScript:
; <Animated preset="foo" />; // notice that foo is used as a unique identifier in the css
Passing a custom timeout
The timeout should match the css transition duration.
<Animated timeout=1000 /> // default is 1000ms // different timeout for entrance and exit<Animated timeout= enter: 750 exit: 500 />
animate.css
default duration
Overwriting animate.css
presets have a default timeout of 1000ms, to change this number you can overwrite the css.
/* overwrite.css */ /* global */ /* specific */
Then in your JavaScript:
; // make sure you include animate.css before this line <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.