forked from deriv-com/ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
58 lines (55 loc) · 1.96 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
import clsx from "clsx";
import React, { ReactNode} from "react";
import "./CircularProgressBar.scss"
type TCircularProgressProps = {
children?: ReactNode;
className?: string;
danger_limit?: number;
is_clockwise?: boolean;
progress?: number;
radius?: number;
stroke?: number;
warning_limit?: number;
icon?: ReactNode;
};
export const CircularProgressBar = ({
children,
className,
danger_limit = 20,
is_clockwise = false,
progress = 0,
radius = 22,
stroke = 3,
warning_limit = 50,
}: TCircularProgressProps) => {
const normalizedRadius = radius - stroke / 2;
const circumference = normalizedRadius * 2 * Math.PI;
const strokeDashoffset = circumference - (progress / 100) * circumference;
return (
<div className={clsx("deriv-circular-progress", className)}>
<svg height={radius * 2} width={radius * 2}>
{children && (
<foreignObject x="0" y="0" width={radius * 2} height={radius * 2}>
<div className={clsx("deriv-circular-progress__content")}>
{children}
</div>
</foreignObject>
)}
<circle
className={clsx("deriv-circular-progress__bar", {
"deriv-circular-progress--clockwise": is_clockwise,
"deriv-circular-progress__bar--warning": progress <= warning_limit && progress > danger_limit,
"deriv-circular-progress__bar--danger": progress <= danger_limit,
})}
cx={radius}
cy={radius}
fill={"transparent"}
r={normalizedRadius}
strokeDasharray={`${circumference} ${circumference}`}
strokeWidth={stroke}
style={{ strokeDashoffset }}
/>
</svg>
</div>
);
};