import { type HTMLAttributes, type Ref, type ReactNode } from 'react'; import { cn } from '@/lib/cn'; import { progressTrackVariants, progressBarVariants, type ProgressVariants } from './progress.variants'; interface ProgressProps extends Omit, 'ref'> { ref?: Ref; value?: number; max?: number; variant?: ProgressVariants['variant']; size?: ProgressVariants['size']; showLabel?: boolean; children?: ReactNode; } export function Progress({ ref, value, max = 100, variant = 'default', size = 'md', showLabel = false, className, children, ...rest }: ProgressProps) { const isIndeterminate = value === undefined; const percentage = isIndeterminate || max <= 0 ? 0 : Math.min(100, Math.max(0, (value / max) * 100)); return (
{showLabel && !isIndeterminate && (
{children} {Math.round(percentage)}%
)}
); } export default Progress;