'use client' import * as React from 'react' import * as ProgressPrimitive from '@radix-ui/react-progress' import { cva, type VariantProps } from 'class-variance-authority' import { cn } from '@/lib/utils' const progressVariants = cva( 'relative w-full overflow-hidden rounded-full bg-muted', { variants: { size: { sm: 'h-1', default: 'h-2', lg: 'h-3', xl: 'h-4', }, variant: { default: '', gradient: '', success: '', warning: '', danger: '', }, }, defaultVariants: { size: 'default', variant: 'default', }, }, ) const indicatorVariants = cva( 'h-full w-full flex-1 transition-all duration-500 ease-out', { variants: { variant: { default: 'bg-primary', gradient: 'bg-gradient-to-r from-primary to-secondary', success: 'bg-success', warning: 'bg-warning', danger: 'bg-destructive', }, animated: { true: '', false: '', }, }, compoundVariants: [ { animated: true, className: 'relative after:absolute after:inset-0 after:bg-gradient-to-r after:from-transparent after:via-white/20 after:to-transparent after:animate-[shimmer_2s_ease-in-out_infinite]', }, ], defaultVariants: { variant: 'default', animated: false, }, }, ) interface ProgressProps extends React.ComponentProps, VariantProps { showValue?: boolean animated?: boolean label?: string } function Progress({ className, value = 0, size, variant, showValue = false, animated = false, label, ...props }: ProgressProps) { return (
{(label || showValue) && (
{label && {label}} {showValue && ( {Math.round(value || 0)}% )}
)}
) } // Circular Progress interface CircularProgressProps { value?: number size?: number strokeWidth?: number variant?: 'default' | 'gradient' showValue?: boolean className?: string } function CircularProgress({ value = 0, size = 48, strokeWidth = 4, variant = 'default', showValue = false, className, }: CircularProgressProps) { const radius = (size - strokeWidth) / 2 const circumference = radius * 2 * Math.PI const offset = circumference - (value / 100) * circumference return (
{variant === 'gradient' && ( )} {showValue && ( {Math.round(value)}% )}
) } // Indeterminate Loader Bar function LoaderBar({ className }: { className?: string }) { return (
) } export { Progress, CircularProgress, LoaderBar, progressVariants }