-
Notifications
You must be signed in to change notification settings - Fork 27
/
Example2.js
93 lines (82 loc) · 2.33 KB
/
Example2.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// @flow weak
// example adpated from https://react-move.js.org/#/story/animate
import React, { PureComponent } from 'react';
import { range } from 'd3-array';
import { easeExpInOut } from 'd3-ease';
import Animate from 'resonance/Animate';
function getRandomColor() {
return range(6).reduce((m) => {
return `${m}${'0123456789ABCDEF'[Math.floor(Math.random() * 16)]}`;
}, '#');
}
function getItems() {
return range(5).map((d) => ({
key: `id-${d}`,
scale: Math.random() * 1,
color: getRandomColor(),
rotate: Math.random() > 0.5 ? 360 : 0,
}));
}
class Example extends PureComponent {
state = {
items: getItems(),
}
update = () => {
this.setState({
items: getItems(),
});
}
render() {
const { items } = this.state;
return (
<div>
<button onClick={this.update}>
Update
</button>
<div style={{ height: '200px' }}>
{items.map((d) => (
<Animate
key={d.key}
start={({ scale, color, rotate }) => ({
scale,
color,
rotate,
})}
update={({ scale, color, rotate }) => ({
scale: [scale],
color: [color],
rotate: [rotate],
timing: { duration: 500, ease: easeExpInOut },
})}
data={d}
>
{(data, { scale, color, rotate }) => {
return (
<div
style={{
float: 'left',
width: '100px',
height: '100px',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
fontWeight: 'bold',
color: 'white',
textAlign: 'center',
borderRadius: `${(rotate / 360) * 100}px`,
transform: `translate(${scale * 50}%, ${scale * 50}%) scale(${scale}) rotate(${rotate}deg)`,
background: color,
}}
>
{Math.round(scale * 100)}
</div>
);
}}
</Animate>
))}
</div>
</div>
);
}
}
export default Example;