This repository has been archived by the owner on Jun 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
/
index.tsx
62 lines (58 loc) 路 1.47 KB
/
index.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
59
60
61
62
import { ProgressBarWrap, ProgressContainer, Progress, Label, FlexWrap, HiddenRange, ProgressVal } from './styled'
interface ProgressBarProps {
percentage: number // between 0 - 100
onPercentageClick: (percentage: number) => void
}
export function ProgressBar({ percentage, onPercentageClick }: ProgressBarProps) {
const statPercentages = [
{
value: 0,
label: '0%',
},
{
value: 25,
label: '25%',
},
{
value: 50,
label: '50%',
},
{
value: 75,
label: '75%',
},
{
value: 100,
label: '100%',
},
]
const minVal = statPercentages[0].value
const maxVal = statPercentages[statPercentages.length - 1].value
if (percentage > 100) {
percentage = 100
} else if (percentage < 0) {
percentage = 0
}
return (
<FlexWrap>
<ProgressBarWrap>
{statPercentages.map((item, index) => (
<Label position={item.value} onClick={() => onPercentageClick(item.value)} key={`${item.value}-${index}`}>
{item.label}
</Label>
))}
<ProgressContainer>
<HiddenRange
onChange={(e) => onPercentageClick(parseFloat(e.target.value))}
min={minVal}
max={maxVal}
value={percentage}
type="range"
/>
<Progress percentage={percentage} />
<ProgressVal>{percentage}%</ProgressVal>
</ProgressContainer>
</ProgressBarWrap>
</FlexWrap>
)
}