({
progress = 0,
size = 40,
stroke = 5,
showPercentage = false,
color = 'brand',
}: ProgressCircleProps)
| 35 | }; |
| 36 | |
| 37 | const ProgressCircle = ({ |
| 38 | progress = 0, |
| 39 | size = 40, |
| 40 | stroke = 5, |
| 41 | showPercentage = false, |
| 42 | color = 'brand', |
| 43 | }: ProgressCircleProps): ReactElement => { |
| 44 | const normalizedCompletion = Math.min(100, Math.max(0, progress)); |
| 45 | const isComplete = normalizedCompletion >= 100; |
| 46 | const radius = size / 2 - 3; |
| 47 | const circumference = 2 * Math.PI * radius; |
| 48 | const strokeDashoffset = circumference * (1 - normalizedCompletion / 100); |
| 49 | |
| 50 | return ( |
| 51 | <div |
| 52 | className="relative inline-flex size-10 items-center justify-center" |
| 53 | style={{ width: size, height: size }} |
| 54 | > |
| 55 | {isComplete ? ( |
| 56 | <VIcon size={IconSize.Medium} className={colorConfig[color].text} /> |
| 57 | ) : ( |
| 58 | <> |
| 59 | <svg |
| 60 | width={size} |
| 61 | height={size} |
| 62 | viewBox={`0 0 ${size} ${size}`} |
| 63 | fill="none" |
| 64 | xmlns="http://www.w3.org/2000/svg" |
| 65 | > |
| 66 | <circle |
| 67 | cx={size / 2} |
| 68 | cy={size / 2} |
| 69 | r={radius} |
| 70 | className="stroke-border-subtlest-tertiary" |
| 71 | strokeWidth={stroke} |
| 72 | fill="transparent" |
| 73 | /> |
| 74 | |
| 75 | <circle |
| 76 | cx={size / 2} |
| 77 | cy={size / 2} |
| 78 | r={radius} |
| 79 | strokeWidth={stroke} |
| 80 | strokeLinecap="round" |
| 81 | strokeDasharray={circumference} |
| 82 | strokeDashoffset={strokeDashoffset} |
| 83 | transform={`rotate(-90 ${size / 2} ${size / 2})`} |
| 84 | fill="transparent" |
| 85 | className={colorConfig[color].stroke} |
| 86 | /> |
| 87 | </svg> |
| 88 | {showPercentage && ( |
| 89 | <Typography |
| 90 | bold |
| 91 | color={colorConfig[color].typography} |
| 92 | type={TypographyType.Callout} |
| 93 | className="absolute leading-none" |
| 94 | > |
nothing calls this directly
no outgoing calls
no test coverage detected