import { cva, type VariantProps } from 'class-variance-authority' import { cn } from '../core/cn' const progressBarVariants = cva( 'relative w-full overflow-hidden rounded-full bg-muted', { variants: { size: { sm: 'h-1', md: 'h-2', lg: 'h-3' }, color: { primary: '[&_.progress-fill]:bg-primary', success: '[&_.progress-fill]:bg-emerald-500', warning: '[&_.progress-fill]:bg-amber-500', destructive: '[&_.progress-fill]:bg-destructive', }, }, defaultVariants: { size: 'md', color: 'primary' }, } ) export interface ProgressBarProps extends VariantProps { value: number max?: number buffer?: number showValue?: boolean animated?: boolean indeterminate?: boolean label?: string className?: string } export function ProgressBar({ value, max = 100, buffer, showValue = false, animated = false, indeterminate = false, size = 'md', color = 'primary', label, className, }: ProgressBarProps) { const percentage = Math.min(100, Math.max(0, (value / max) * 100)) const bufferPercentage = buffer ? Math.min(100, Math.max(0, (buffer / max) * 100)) : undefined return (
{bufferPercentage !== undefined && (
)}
{showValue && !indeterminate && ( {Math.round(percentage)}% )}
) } export { progressBarVariants }