import { HTMLAttributes } from "react"; import { twMerge } from "tailwind-merge"; interface ProgressCircleProps extends HTMLAttributes { value?: number; max?: number; isLow?: boolean; size?: "small" | "large"; showPercentage?: boolean; reverse?: boolean; } export const ProgressCircle = ({ value = 0, max = 100, isLow = false, size = "large", showPercentage = false, reverse = false, className, ...props }: ProgressCircleProps) => { const percentage = Math.min(Math.max(0, value), max); const displayPercentage = percentage; // Make small circles actually smaller const radius = size === "small" ? 8 : 40; const strokeWidth = size === "small" ? 4 : 6; const circumference = 2 * Math.PI * radius; // Calculate stroke dashoffset differently based on direction const strokeDashoffset = reverse ? (percentage / 100) * circumference // Counter-clockwise : circumference - (percentage / 100) * circumference; // Clockwise const viewBoxSize = (radius + strokeWidth) * 2; return (
{/* For small size, show percentage label outside to the right */} {showPercentage && size === "small" && (
{Math.round(displayPercentage)}%
)} {/* For large size, show percentage in the center */} {showPercentage && size === "large" && (
{Math.round(displayPercentage)}%
)}
); }; export default ProgressCircle;