-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCircularProgressBar.tsx
57 lines (50 loc) · 1.69 KB
/
CircularProgressBar.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
import type {MetricStatus} from '../../store/reducers/tenants/types';
import {normalizeProgress} from '../../store/reducers/tenants/utils';
import {cn} from '../../utils/cn';
import './CircularProgressBar.scss';
const b = cn('ydb-circular-progress-bar');
interface CircularProgressBarProps {
size?: number;
progress?: number;
strokeWidth?: number;
content?: React.ReactNode;
status?: MetricStatus;
circleBgClassName?: string;
}
export function CircularProgressBar({
size = 100,
progress = 0,
strokeWidth = 10,
content,
status,
circleBgClassName,
}: CircularProgressBarProps) {
const center = size / 2;
const radius = size / 2 - strokeWidth / 2;
const circumference = 2 * Math.PI * radius;
const normalizedProgress = normalizeProgress(progress);
const offset = ((100 - normalizedProgress) / 100) * circumference;
return (
<div className={b('wrapper')}>
{content && <div className={b('content')}>{content}</div>}
<svg className={b()} width={size} height={size}>
<circle
className={b('circle-bg', circleBgClassName)}
cx={center}
cy={center}
r={radius}
strokeWidth={strokeWidth}
/>
<circle
className={b('circle', {status: status?.toLocaleLowerCase()})}
cx={center}
cy={center}
r={radius}
strokeWidth={strokeWidth}
strokeDasharray={circumference}
strokeDashoffset={offset}
/>
</svg>
</div>
);
}