-
Notifications
You must be signed in to change notification settings - Fork 156
/
simple.tsx
58 lines (54 loc) · 1.49 KB
/
simple.tsx
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
import * as React from 'react';
import { Line, Circle, ProgressProps } from '../src';
class Example extends React.Component<ProgressProps, any> {
constructor(props) {
super(props);
this.state = {
percent: 30,
color: '#3FC7FA',
};
this.changeState = this.changeState.bind(this);
}
changeState() {
const colorMap = ['#3FC7FA', '#85D262', '#FE8C6A'];
const value = parseInt((Math.random() * 100).toString(), 10);
this.setState({
percent: value,
color: colorMap[parseInt((Math.random() * 3).toString(), 10)],
});
}
render() {
const { percent, color } = this.state;
const containerStyle = {
width: '250px',
};
const circleContainerStyle = {
width: '250px',
height: '250px',
display: 'inline-block',
};
return (
<div>
<h3>Line Progress {percent}%</h3>
<div style={containerStyle}>
<Line percent={percent} strokeWidth={4} strokeColor={color} />
<Line
percent={[percent / 2, percent / 2]}
strokeWidth={4}
strokeColor={[color, '#CCC']}
/>
</div>
<h3>Circle Progress {percent}%</h3>
<div style={circleContainerStyle}>
<Circle percent={percent} strokeWidth={6} strokeLinecap="round" strokeColor={color} />
</div>
<p>
<button type="button" onClick={this.changeState}>
Change State
</button>
</p>
</div>
);
}
}
export default Example;