-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgressBar.tsx
More file actions
81 lines (73 loc) · 1.89 KB
/
ProgressBar.tsx
File metadata and controls
81 lines (73 loc) · 1.89 KB
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
/* @author Rohil Visariya
@description ProgressBar Indicator
@created 10 Aug 2020
*/
import React from 'react';
interface ifPercentage {
percentage: string | number
totalValue: never
completedValue: never
}
interface ifOutOf {
percentage: never
totalValue: number
completedValue: number
}
type Props = {
completedValue: number,
totalValue: number,
percentage: string | number,
height?: number,
color?: string,
labelColor?: string,
prefixLabelText?: string | any,
suffixLabelText?: string | any
}
export default function Progressbar(
{
height = 20,
color,
labelColor = '#ffffff',
percentage,
completedValue,
totalValue,
prefixLabelText,
suffixLabelText
}: Props
) {
let percent = percentage ? percentage : ((completedValue * 100) / totalValue);
const containerStyles = {
height: height,
width: '100%',
backgroundColor: "#dddddd",
textAlign: 'left' as const
}
const fillerStyles = {
height: '100%',
width: `${percent}%`,
backgroundColor: color,
textAlign: 'center' as const,
transition: 'width 1s ease-in-out',
}
const labelStyles = {
padding: 5,
display: 'inline-flex',
alignItems: 'middle',
height: height,
color: `${labelColor}`,
fontWeight: 700,
fontSize: '100%',
lineHeight: '1.2em'
}
return (
<div className="ProgressBar" style={containerStyles}>
<div style={fillerStyles}>
<span style={labelStyles}>
{prefixLabelText ? prefixLabelText : null}
{percentage ? ` ${percent}% ` : ` ${completedValue} / ${totalValue} `}
{suffixLabelText ? suffixLabelText : null}
</span>
</div>
</div>
);
}