import { cn } from "@/app/_utils/cn"; import { HTMLAttributes, forwardRef } from "react"; export interface ProgressBarProps extends HTMLAttributes { value: number; max?: number; showLabel?: boolean; size?: "sm" | "md" | "lg"; variant?: "default" | "gradient"; } const ProgressBar = forwardRef( ( { className, value, max = 100, showLabel = true, size = "md", variant = "default", ...props }, ref ) => { const percentage = Math.min(Math.max((value / max) * 100, 0), 100); const getColorClass = (percentage: number) => { if (percentage >= 90) return "bg-destructive"; if (percentage >= 80) return "bg-orange-500"; if (percentage >= 70) return "bg-yellow-500"; return "bg-emerald-500"; }; const getGradientClass = (percentage: number) => { if (percentage >= 90) return "bg-gradient-to-r from-destructive to-red-600"; if (percentage >= 80) return "bg-gradient-to-r from-orange-500 to-orange-600"; if (percentage >= 70) return "bg-gradient-to-r from-yellow-500 to-yellow-600"; return "bg-gradient-to-r from-emerald-500 to-emerald-600"; }; return (
{showLabel && (
Usage {Math.round(percentage)}%
)}
); } ); ProgressBar.displayName = "ProgressBar"; export { ProgressBar };