react-tweenful
Looking for an amazing React library for animating stuff? Look no more, we've got you covered!
Demo
https://teodosii.github.io/react-tweenful/
Features
- Loop support (infinite or up to a specific number)
- Wide variety of easings (bezier, predefined and custom easing)
- Delayed animations (before and after)
- Events support
- Negative delay support to mimic CSS animations
- Percent based animations to mimic CSS animations (e.g.
0%
,50%
,100%
) Tweenful
component for animating DOM nodesSVG
component to animate SVG nodesObserver
component for mount/unmount animationsObserverGroup
component to handle child transition (list removal/insertion, page transition etc)
Getting started
npm install react-tweenful
Development
In order to build the project and run it on your local machine, you'll need to build both the site
project and the library itself. The site
project will have a dependency of react-tweenful
and there you'll be able to play with the examples.
npm run build:library:dev
npm run start
Or if you want to be able to modify both projects at once and let webpack watch the changes and do the build for you, then open 2 separate terminals and run the following commands
npm run watch:library:dev
And in a separate terminal run
npm run start
Both commands will instruct webpack to watch for changes.
Navigate to http://localhost:8080/react-tweenful
or whatever port you're running the application on.
Usage
react-tweenful
exports the following:
Tweenful
- component to animate DOM elements. It requires a DOM node to perform animation on.SVG
- component to animate SVG elements. It requires a SVG node to perform animation on.Observer
- component to animate mounting and unmounting of an element.ObserverGroup
- component to watch over a list ofObserver
elements such as list removal/insertion or route transition
A couple of utility functions are also exported to help you out animating:
percentage
for percentage based animationsbezier
for bezier easingselastic
for elastic easing
Import the needed component, for example Tweenful
import Tweenful elastic from 'react-tweenful';
Tweenful
requires a node to render on which it will perform the animation. We've got most of the DOM nodes covered in the form of namespacing such as Tweenful.div
, Tweenful.span
and so on.
const Example = <Tweenful.div ="tween-box" = = = = ></Tweenful.div>;
Voila!
Examples
Observer
View animation here
Usage of Observer
component together with Tweenful
. Animate movement with Tweenful
and subscribe to mount and unmount with Observer
.
import React useEffect useState from 'react';import Tweenful Observer elastic from 'react-tweenful'; const props = delay: 200 render: true duration: 1600 easing: loop: false animate: translateX: '400px' events: console console ; const ObserverDemo = const shouldRender setShouldRender = ; ; return <Observer = = = = = ="linear" > <div ="observer-demo"> <Tweenful.div ="box-demo" ></Tweenful.div> </div> </Observer> ;;
ObserverGroup
View animation here
Usage of ObserverGroup
component to watch for mounting and unmounting over a list of notifications
<ObserverGroup = => thisstatenotifications</ObserverGroup>
Animate route transition
View animation here
Usage of ObserverGroup
to animate route change
import React from 'react';import Route Switch NavLink from 'react-router-dom';import ObserverGroup from 'react-tweenful/ObserverGroup';import Observer from 'react-tweenful/Observer'; const colors = red: '#EE4266' yellow: '#FDB833' blue: '#296EB4' green: '#0EAD69'; const Red = <div ="color-block" =></div>;const Yellow = <div ="color-block" =></div>;const Blue = <div ="color-block" =></div>;const Green = <div ="color-block" =></div>; Component { ; } { const location = thisprops; return <div ="route-transition-demo"> <ul ="nav-links"> <li><NavLink ="/transition/red">Red</NavLink></li> <li><NavLink ="/transition/yellow">Yellow</NavLink></li> <li><NavLink ="/transition/blue">Blue</NavLink></li> <li><NavLink ="/transition/green">Green</NavLink></li> </ul> <div ="observer"> <ObserverGroup> <Observer.div = ="key-wrapper" = = = = = > <Switch => <Route = = /> <Route = = /> <Route = = /> <Route = = /> <Route = /> </Switch> </Observer.div> </ObserverGroup> </div> </div> ; } ;
Prism
View animation here
react-tweenful
in action powering a super awesome looking animation.
import React from 'react';import SVG from 'react-tweenful'; const WAVE_COUNT = 16;const offset = 40;const waveLength = 375;const duration = 1500; const waves = WAVE_COUNT; const RotatingSvg = return <svg ="300" ="http://www.w3.org/2000/svg" ="0px" ="0px" ="0 0 1000 1000"> <defs> <clipPath ="world"> <circle ="500" ="500" ="450" ="none" ="none"></circle> </clipPath> </defs> <circle ="500" ="500" ="450" ="none" ="#000"></circle> <SVG ="g" ="circle" = = = ="linear" = > waves </SVG> </svg> ;;
SVG
View animation here
An example animating SVG path
and fill
properties one after the other.
Gradients
View animation here
An example using elastic
easing to animate gradient boxes.
import React from 'react';import Tweenful elastic from 'react-tweenful'; const Gradients = const elements = 10 ; return <div ="gradients-container"> <div ="row">elements</div> </div> ;;
Loader
View animation here
import React from 'react';import Tweenful percentage from 'react-tweenful'; const rotate = ;const dot1Animate = ;const dot2Animate = ;const dot3Animate = ; const LoadingCircles = return <div ="loading-wrapper"> <Tweenful.div ="loading-circles-container" = = ="easeInOutCubic" = = > <Tweenful.div ="dot dot-1" = ="easeOutCubic" = = = ></Tweenful.div> <Tweenful.div ="dot dot-2" = ="easeOutCubic" = = = ></Tweenful.div> <Tweenful.div ="dot dot-3" = ="easeOutCubic" = = = ></Tweenful.div> </Tweenful.div> <svg ="http://www.w3.org/2000/svg" ="1.1"> <defs> <filter ="goo"> <feGaussianBlur ="SourceGraphic" ="10" ="blur" /> <feColorMatrix ="blur" ="matrix" ="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 21 -7" /> </filter> </defs> </svg> </div> ;;
Bouncing Balls
View animation here
Bouncing balls illustrate negative delay support in react-tweenful
import React from 'react';import SVG percentage elastic from 'react-tweenful'; const circles = 10; const BouncingBalls = return <div ="bouncing-balls"> <svg ="http://www.w3.org/2000/svg" ="0px" ="0px" ="0 0 1000 500"> circles </svg> </div> ;;
API
Update in progress. Stay in touch!
Note
A couple of the animations shown here have been initially created for CodePen by other folks. My only contribution to them was to convert them to react-tweenful
to show real world examples on animating stuff.
License
MIT