react-move
Beautifully animate anything in react with interia or time + easing.
Features
Table of Contents
Installation
$ yarn add react-move
A component used for animating any property of any object.
import React from 'react'
import { Animate } from 'react-move'
<Animate
default={{
scale: 0,
color: 'blue',
rotate: 0
}}
data={{
scale: Math.random() * 1,
color: ['red', 'blue', 'yellow'].find((d, i) => i === Math.round(Math.random() * 2)),
rotate: Math.random() > 0.5 ? 360 : 0
}}
tension={100}
damping={5}
duration={800}
easing='easeQuadIn'
>
{data => {
return (
<div
style={{
borderRadius: ((data.rotate / 360) * 100) + 'px',
transform: `translate(${data.scale * 50}%, ${data.scale * 50}%) scale(${data.scale}) rotate(${data.rotate}deg)`,
background: data.color
}}
>
{Math.round(data.scale * 100) / 100}
</div>
)
}}
</Animate>
A component that enables animating multiple elements, including enter and exit animations.
import React from 'react'
import { Transition } from 'react-move'
const items = _.filter(items, (d, i) => i > Math.random() * 10)
<Transition
data={items}
getKey={d => d}
update={d => ({
translate: 1,
opacity: 1,
color: 'grey'
})}
enter={d => ({
translate: 0,
opacity: 0,
color: 'blue'
})}
leave={d => ({
translate: 2,
opacity: 0,
color: 'red'
})}
tension={100}
damping={5}
duration={800}
easing='easeQuadIn'
stagger={0.3}
staggerGroup
>
{data => {
return (
<div style={{height: (20 * 10) + 'px'}}>
{data.map(d => {
return (
<div
key={d.key}
style={{
position: 'absolute',
transform: `translate(${100 * d.state.translate}px, ${20 * d.key}px)`,
opacity: d.state.opacity,
color: d.state.color
}}
>
{d.data} - {Math.round(d.percentage * 100)}
</div>
)
})}
</div>
)
}}
</Transition>
Contributing
To suggest a feature, create an issue if it does not already exist.
If you would like to help develop a suggested feature follow these steps:
- Fork this repo
$ yarn
$ yarn run storybook
- Implement your changes to files in the
src/
directory - View changes as you code via our React Storybook
localhost:8000
- Make changes to stories in
/stories
, or create a new one if needed - Submit PR for review
Scripts
$ yarn run storybook
Runs the storybook server$ yarn run test
Runs the test suite$ yarn run prepublish
Builds for NPM distribution$ yarn run docs
Builds the website/docs from the storybook for github pages