-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircular.jsx
More file actions
65 lines (61 loc) · 1.48 KB
/
circular.jsx
File metadata and controls
65 lines (61 loc) · 1.48 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
import React, { useEffect, useState } from 'react';
import { data_pointer } from './helpers.jsx';
export function CircularProgress({
size = 13,
strokeWidth = 2,
percentage = 0,
fontSize = 6,
color = window[data_pointer]?.colors?.primary || '#1A1A1A',
colorSecondary = window[data_pointer]?.colors?.tertiary || '#E3E5E8',
showPercent = false,
className
}) {
const [progress, setProgress] = useState(0);
useEffect(() => {
setProgress(percentage);
}, [percentage]);
const viewBox = `0 0 ${size} ${size}`;
const radius = (size - strokeWidth) / 2;
const circumference = radius * Math.PI * 2;
const dash = (progress * circumference) / 100;
return (
<svg width={size} height={size} viewBox={viewBox} className={className}>
<circle
fill="none"
stroke={colorSecondary}
cx={size / 2}
cy={size / 2}
r={radius}
strokeWidth={`${strokeWidth}px`}
/>
{(percentage && (
<circle
fill="none"
stroke={color}
cx={size / 2}
cy={size / 2}
r={radius}
strokeWidth={`${strokeWidth}px`}
transform={`rotate(-90 ${size / 2} ${size / 2})`}
strokeDasharray={[dash, circumference - dash]}
strokeLinecap="round"
style={{ transition: 'all 0.5s' }}
/>
)) ||
null}
{(showPercent && (
<text
fill="black"
fontSize={fontSize + 'px'}
x="50%"
y="50%"
dy={fontSize / 2 + 'px'}
textAnchor="middle"
>
{`${percentage}%`}
</text>
)) ||
null}
</svg>
);
}