| 1 | import type { VariantProps } from 'class-variance-authority' |
| 2 | import { cva } from 'class-variance-authority' |
| 3 | import * as React from 'react' |
| 4 | |
| 5 | import { cn } from '@/utils/className' |
| 6 | |
| 7 | const alertVariants = cva( |
| 8 | 'relative w-full rounded-lg border px-4 py-3 text-sm flex items-start gap-3 [&>svg]:shrink-0 [&>svg]:mt-0.5 [&>svg]:text-foreground', |
| 9 | { |
| 10 | variants: { |
| 11 | variant: { |
| 12 | default: 'bg-background text-foreground', |
| 13 | destructive: |
| 14 | 'border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive', |
| 15 | }, |
| 16 | }, |
| 17 | defaultVariants: { |
| 18 | variant: 'default', |
| 19 | }, |
| 20 | }, |
| 21 | ) |
| 22 | |
| 23 | const Alert = React.forwardRef< |
| 24 | HTMLDivElement, |
| 25 | React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof alertVariants> |
| 26 | >(({ className, variant, ...props }, ref) => ( |
| 27 | <div ref={ref} role="alert" className={cn(alertVariants({ variant }), className)} {...props} /> |
| 28 | )) |
| 29 | Alert.displayName = 'Alert' |
| 30 | |
| 31 | const AlertTitle = React.forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLHeadingElement>>( |
| 32 | ({ className, ...props }, ref) => ( |
| 33 | <h5 |
| 34 | ref={ref} |
| 35 | className={cn('mb-1 font-medium leading-none tracking-tight', className)} |
| 36 | {...props} |
| 37 | /> |
| 38 | ), |
| 39 | ) |
| 40 | AlertTitle.displayName = 'AlertTitle' |
| 41 | |
| 42 | const AlertDescription = React.forwardRef< |
| 43 | HTMLParagraphElement, |
| 44 | React.HTMLAttributes<HTMLParagraphElement> |
| 45 | >(({ className, ...props }, ref) => ( |
| 46 | <div ref={ref} className={cn('text-sm [&_p]:leading-relaxed', className)} {...props} /> |
| 47 | )) |
| 48 | AlertDescription.displayName = 'AlertDescription' |
| 49 | |
| 50 | export { Alert, AlertDescription, AlertTitle } |
| 51 |