import { cn } from "@/utils/cn"; import type { ElementType } from "react"; interface CircularProgressProps { as?: As; value: number; renderLabel?: (progress: number) => number | string; size?: number; strokeWidth?: number; circleStrokeWidth?: number; progressStrokeWidth?: number; shape?: "square" | "round"; className?: string; progressClassName?: string; labelClassName?: string; showLabel?: boolean; } export function CircularProgress({ as, value, renderLabel, className, progressClassName, labelClassName, showLabel, shape = "round", size = 100, strokeWidth, circleStrokeWidth = 10, progressStrokeWidth = 10, ...props }: CircularProgressProps & React.ComponentPropsWithoutRef) { const Comp = as || "div"; const maxStrokeWidth = Math.max(strokeWidth ?? circleStrokeWidth, strokeWidth ?? progressStrokeWidth); const radius = (size - maxStrokeWidth) / 2; const circumference = Math.ceil(3.14 * radius * 2); const percentage = Math.ceil(circumference * ((100 - value) / 100)); const viewBox = `0 0 ${size} ${size}`; return ( {/* Base Circle */} {/* Progress */} {showLabel && (
{renderLabel ? renderLabel(value) : value}
)}
); }