| gio | 7f98e77 | 2025-05-07 11:00:14 +0000 | [diff] [blame] | 1 | import * as React from "react" |
| 2 | import { cva, type VariantProps } from "class-variance-authority" |
| 3 | import { cn } from "@/lib/utils" |
| 4 | |
| 5 | const alertVariants = cva( |
| 6 | "relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground", |
| 7 | { |
| 8 | variants: { |
| 9 | variant: { |
| 10 | default: "bg-background text-foreground", |
| 11 | destructive: |
| 12 | "border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive", |
| 13 | }, |
| 14 | }, |
| 15 | defaultVariants: { |
| 16 | variant: "default", |
| 17 | }, |
| 18 | } |
| 19 | ) |
| 20 | |
| 21 | const Alert = React.forwardRef< |
| 22 | HTMLDivElement, |
| 23 | React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof alertVariants> |
| 24 | >(({ className, variant, ...props }, ref) => ( |
| 25 | <div |
| 26 | ref={ref} |
| 27 | role="alert" |
| 28 | className={cn(alertVariants({ variant }), className)} |
| 29 | {...props} |
| 30 | /> |
| 31 | )) |
| 32 | Alert.displayName = "Alert" |
| 33 | |
| 34 | const AlertTitle = React.forwardRef< |
| 35 | HTMLParagraphElement, |
| 36 | React.HTMLAttributes<HTMLHeadingElement> |
| 37 | >(({ className, ...props }, ref) => ( |
| 38 | <h5 |
| 39 | ref={ref} |
| 40 | className={cn("mb-1 font-medium leading-none tracking-tight", className)} |
| 41 | {...props} |
| 42 | /> |
| 43 | )) |
| 44 | AlertTitle.displayName = "AlertTitle" |
| 45 | |
| 46 | const AlertDescription = React.forwardRef< |
| 47 | HTMLParagraphElement, |
| 48 | React.HTMLAttributes<HTMLParagraphElement> |
| 49 | >(({ className, ...props }, ref) => ( |
| 50 | <div |
| 51 | ref={ref} |
| 52 | className={cn("text-sm [&_p]:leading-relaxed", className)} |
| 53 | {...props} |
| 54 | /> |
| 55 | )) |
| 56 | AlertDescription.displayName = "AlertDescription" |
| 57 | |
| 58 | export { Alert, AlertTitle, AlertDescription } |