-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathindex.tsx
More file actions
90 lines (85 loc) · 2.09 KB
/
Copy pathindex.tsx
File metadata and controls
90 lines (85 loc) · 2.09 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
82
83
84
85
86
87
88
89
90
import clsx from 'clsx';
import type { ReactNode } from 'react';
import './style.scss';
const CircularProgressBar = ( {
currentStep,
numberOfSteps,
size,
enableDesktopScaling = false,
strokeColor,
strokeWidth = 4,
showProgressText = true,
customText,
variant,
ariaLabelledBy,
ariaValueText,
}: {
currentStep: number | null;
numberOfSteps: number | null;
size: number;
enableDesktopScaling?: boolean;
strokeColor?: string;
strokeWidth?: number;
showProgressText?: boolean;
customText?: ReactNode;
variant?: 'success';
ariaLabelledBy?: string;
ariaValueText?: string;
} ) => {
const SIZE = size;
const RADIUS = SIZE / 2 - strokeWidth / 2;
const FULL_ARC = 2 * Math.PI * RADIUS;
if ( currentStep === null || ! numberOfSteps ) {
return null;
}
return (
<div
role="progressbar"
aria-valuemin={ 0 }
aria-valuemax={ numberOfSteps }
aria-valuenow={ currentStep }
aria-valuetext={ ariaValueText }
aria-labelledby={ ariaLabelledBy }
className={ clsx( 'circular__progress-bar', {
'desktop-scaling': enableDesktopScaling,
'is-success': variant === 'success',
} ) }
style={ { width: SIZE, height: SIZE, flex: `0 0 ${ SIZE }px` } }
>
<svg
viewBox={ `0 0 ${ SIZE } ${ SIZE }` }
style={ { width: SIZE, height: SIZE } }
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<circle
className="circular__progress-bar-empty-circle"
fill="none"
cx={ SIZE / 2 }
cy={ SIZE / 2 }
r={ RADIUS }
strokeWidth={ strokeWidth }
/>
<circle
style={ {
display: currentStep === 0 ? 'none' : 'block',
stroke: strokeColor,
strokeDasharray: `${ FULL_ARC * ( currentStep / numberOfSteps ) }, ${ FULL_ARC }`,
} }
className="circular__progress-bar-fill-circle"
fill="none"
cx={ SIZE / 2 }
cy={ SIZE / 2 }
r={ RADIUS }
strokeWidth={ strokeWidth }
/>
</svg>
{ ( customText || showProgressText ) && (
<div className="circular__progress-bar-text">
{ customText || `${ currentStep }/${ numberOfSteps }` }
</div>
) }
</div>
);
};
export default CircularProgressBar;