|
24 | 24 |
|
25 | 25 | ## Quickstart
|
26 | 26 |
|
27 |
| -```jsx |
28 |
| -import react from 'react'; |
29 |
| -import { Animate, AnimateKeyframes, AnimateGroup } from 'react-simple-animate'; |
| 27 | +#### Components |
30 | 28 |
|
31 |
| -const props = { |
32 |
| - startStyle: { opacity: 0 } |
33 |
| - endStyle: { opacity: 1 } |
34 |
| -}; |
| 29 | +```jsx |
| 30 | +import React from "react"; |
| 31 | +import { Animate, AnimateKeyframes, AnimateGroup } from "react-simple-animate"; |
35 | 32 |
|
36 |
| -export default () => { |
37 |
| - return ( |
38 |
| - // This example demonstrate animate individual element. |
39 |
| - <Animate play {...props}> |
| 33 | +export default () => ( |
| 34 | + <> |
| 35 | + {/* This example demonstrate animate individual element. */} |
| 36 | + <Animate play start={{ opacity: 0 }} end={{ opacity: 1 }}> |
40 | 37 | <h1>React simple animate</h1>
|
41 | 38 | </Animate>
|
42 |
| - |
43 |
| - // This example demonstrate animate keyframes with individual element. |
44 |
| - <AnimateKeyframes play iterationCount="infinite" keyframes={['opacity: 0', 'opacity: 1']}> |
| 39 | + {/* This example demonstrate animate keyframes with individual element. */} |
| 40 | + <AnimateKeyframes |
| 41 | + play |
| 42 | + iterationCount="infinite" |
| 43 | + keyframes={["opacity: 0", "opacity: 1"]} |
| 44 | + > |
45 | 45 | <h1>React simple animate with keyframes</h1>
|
46 | 46 | </AnimateKeyframes>
|
47 |
| - |
48 |
| - // This example demonstrate animate group of animation with sequenceIndex. |
| 47 | + {/* This example demonstrate animate group of animation with sequenceIndex. */} |
49 | 48 | <AnimateGroup play>
|
50 |
| - <Animate {...props} sequenceIndex={0} /> |
51 |
| - <p>Next animation below: </p> |
52 |
| - <Animate {...props} sequenceIndex={1} /> |
53 |
| - <p>Final animation below: </p> |
54 |
| - <Animate {...props} sequenceIndex={2} /> |
| 49 | + <Animate start={{ opacity: 0 }} end={{ opacity: 1 }} sequenceIndex={0}> |
| 50 | + first |
| 51 | + </Animate> |
| 52 | + |
| 53 | + <Animate start={{ opacity: 0 }} end={{ opacity: 1 }} sequenceIndex={1}> |
| 54 | + second |
| 55 | + </Animate> |
| 56 | + <Animate start={{ opacity: 0 }} end={{ opacity: 1 }} sequenceIndex={2}> |
| 57 | + third |
| 58 | + </Animate> |
55 | 59 | </AnimateGroup>
|
| 60 | + </> |
| 61 | +); |
| 62 | + |
| 63 | +``` |
| 64 | + |
| 65 | +#### Hooks |
| 66 | + |
| 67 | +```jsx |
| 68 | +import react from 'react'; |
| 69 | +import { useAnimate, useAnimateKeyframes, useAnimateGroup } from 'react-simple-animate'; |
| 70 | + |
| 71 | +export const useAnimateExample = () => { |
| 72 | + const { style, play } = useAnimate({ start: { opacity: 0 }, end: { opacity: 1 } }); |
| 73 | + |
| 74 | + useEffect(() => play(true), []); |
| 75 | + |
| 76 | + return <div style={style}>useAnimate</div>; |
| 77 | +}; |
| 78 | + |
| 79 | +export const useAnimateKeyframesExample = () => { |
| 80 | + const { style, play } = useAnimateKeyframes({ |
| 81 | + keyframes: ['opacity: 0', 'opacity: 1'], |
| 82 | + iterationCount: 4 |
| 83 | + }); |
| 84 | + |
| 85 | + useEffect(() => play(true), []); |
| 86 | + |
| 87 | + return <div style={style}>useAnimate</div>; |
| 88 | +}; |
| 89 | + |
| 90 | +export const useAnimateGroup = () => { |
| 91 | + const { styles = [], play } = useAnimateGroup({ |
| 92 | + sequences: [ |
| 93 | + { start: { opacity: 1 }, end: { opacity: 0 } }, |
| 94 | + { start: { background: "red" }, end: { background: "blue" } } |
| 95 | + ] |
| 96 | + }); |
| 97 | + |
| 98 | + useEffect(() => play(true), []); |
| 99 | + |
| 100 | + return ( |
| 101 | + {styles.map(style => <div style={style}>useAnimateGroup</div>)} |
56 | 102 | );
|
57 | 103 | };
|
58 | 104 | ```
|
|
0 commit comments