-
Notifications
You must be signed in to change notification settings - Fork 38
/
react-motion-example.js
49 lines (46 loc) · 1.26 KB
/
react-motion-example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import React from 'react'
import { StaggeredMotion, spring } from 'react-motion'
const AnimatedGridContents = props => {
return (
<StaggeredMotion
defaultStyles={props.items.map(() => ({ opacity: 1, translateY: -30 }))}
styles={prevInterpolatedStyles =>
prevInterpolatedStyles.map((_, i) => {
return i === 0
? { opacity: spring(1), translateY: spring(0) }
: {
opacity: prevInterpolatedStyles[i - 1].opacity,
translateY: spring(prevInterpolatedStyles[i - 1].translateY)
}
})
}
>
{interpolatingStyles => (
<div className="grid">
{interpolatingStyles.map((style, i) => (
<div
className="card"
key={props.items[i]}
style={{
opacity: style.opacity,
transform: `translateY(${style.translateY}px)`
}}
>
{props.items[i]}
</div>
))}
</div>
)}
</StaggeredMotion>
)
}
const TransitionGrid = ({ items, visible }) => {
return (
visible && (
<div className="animated-grid">
<AnimatedGridContents items={items} />
</div>
)
)
}
export default TransitionGrid