@@ -27,6 +27,47 @@ Usage of `Observer` component together with `Tweenful`. Animate movement with `T
2727
2828![ Observer] ( https://github.com/teodosii/react-tweenful/raw/master/gif/observer.gif " Observer ")
2929
30+ ``` jsx
31+ import React , { useEffect , useState } from ' react' ;
32+ import Tweenful , { Observer , elastic } from ' react-tweenful' ;
33+
34+ const props = {
35+ delay: 200 ,
36+ render: true ,
37+ duration: 1600 ,
38+ easing: elastic (1 , 0.1 ),
39+ loop: false ,
40+ animate: { translateX: ' 400px' },
41+ events: {
42+ onAnimationStart : () => console .log (' AnimationStart' ),
43+ onAnimationEnd : () => console .log (' AnimationEnd' )
44+ }
45+ };
46+
47+ const ObserverDemo = () => {
48+ const [shouldRender , setShouldRender ] = useState (true );
49+
50+ useEffect (() => {
51+ setTimeout (() => setShouldRender (false ), 3000 );
52+ }, []);
53+
54+ return (
55+ < Observer
56+ render= {shouldRender}
57+ duration= {1200 }
58+ style= {{ opacity: 0 }}
59+ mount= {{ opacity: 1 }}
60+ unmount= {[{ opacity: 0 }]}
61+ easing= " linear"
62+ >
63+ < div className= " observer-demo" >
64+ < Tweenful .div className= " box-demo" {... props}>< / Tweenful .div >
65+ < / div>
66+ < / Observer>
67+ );
68+ };
69+ ```
70+
3071### ObserverGroup
3172
3273Usage of ` ObserverGroup ` component to watch for mounting and unmounting over a list of notifications
@@ -58,6 +99,74 @@ Usage of `ObserverGroup` component to watch for mounting and unmounting over a l
5899
59100![ Routing] ( https://github.com/teodosii/react-tweenful/raw/master/gif/transition.gif " Routing ")
60101
102+ ``` jsx
103+ import React from ' react' ;
104+ import { Route , Switch , NavLink } from ' react-router-dom' ;
105+ import ObserverGroup from ' react-tweenful/ObserverGroup' ;
106+ import Observer from ' react-tweenful/Observer' ;
107+
108+ const colors = {
109+ red: ' #EE4266' ,
110+ yellow: ' #FDB833' ,
111+ blue: ' #296EB4' ,
112+ green: ' #0EAD69'
113+ };
114+
115+ const Red = () => < div className= " color-block" style= {{ backgroundColor: colors .red }}>< / div> ;
116+ const Yellow = () => < div className= " color-block" style= {{ backgroundColor: colors .yellow }}>< / div> ;
117+ const Blue = () => < div className= " color-block" style= {{ backgroundColor: colors .blue }}>< / div> ;
118+ const Green = () => < div className= " color-block" style= {{ backgroundColor: colors .green }}>< / div> ;
119+
120+ class RouteTransitionDemo extends React .Component {
121+ constructor (props ) {
122+ super (props);
123+ }
124+
125+ render () {
126+ const { location } = this .props ;
127+
128+ return (
129+ < div className= " route-transition-demo" >
130+ < ul className= " nav-links" >
131+ < li>< NavLink to= " /transition/red" > Red< / NavLink>< / li>
132+ < li>< NavLink to= " /transition/yellow" > Yellow< / NavLink>< / li>
133+ < li>< NavLink to= " /transition/blue" > Blue< / NavLink>< / li>
134+ < li>< NavLink to= " /transition/green" > Green< / NavLink>< / li>
135+ < / ul>
136+ < div className= " observer" >
137+ < ObserverGroup>
138+ < Observer .div
139+ key= {location .pathname }
140+ className= " key-wrapper"
141+ duration= {1000 }
142+ style= {{ opacity: 0 }}
143+ mount= {{ opacity: 1 }}
144+ unmount= {{ opacity: 0 }}
145+ events= {{
146+ onMountStart : () => console .log (' onMountStart' ),
147+ onUnmountEnd : () => console .log (' onUnmountEnd' )
148+ }}
149+ easing= {' easeOutQuad' }
150+ >
151+ < Switch location= {location}>
152+ < Route exact path= {` /transition/red` } component= {Red} / >
153+ < Route exact path= {` /transition/green` } component= {Green} / >
154+ < Route exact path= {` /transition/blue` } component= {Blue} / >
155+ < Route exact path= {` /transition/yellow` } component= {Yellow} / >
156+ < Route render= {() => < div> Not Found< / div> } / >
157+ < / Switch>
158+ < / Observer .div >
159+ < / ObserverGroup>
160+ < / div>
161+ < / div>
162+ );
163+ }
164+ }
165+
166+ export default RouteTransitionDemo ;
167+
168+ ```
169+
61170### Prism
62171
63172![ Prism] ( https://github.com/teodosii/react-tweenful/raw/master/gif/rotating-svg.gif " Prism ")
0 commit comments