| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 1 | import * as React from "react"; |
| 2 | import { cva, type VariantProps } from "class-variance-authority"; |
| 3 | import { cn } from "@/lib/utils"; |
| gio | 7f98e77 | 2025-05-07 11:00:14 +0000 | [diff] [blame] | 4 | |
| 5 | const alertVariants = cva( |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 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: "border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive", |
| 12 | }, |
| 13 | }, |
| 14 | defaultVariants: { |
| 15 | variant: "default", |
| 16 | }, |
| 17 | }, |
| 18 | ); |
| gio | 7f98e77 | 2025-05-07 11:00:14 +0000 | [diff] [blame] | 19 | |
| 20 | const Alert = React.forwardRef< |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 21 | HTMLDivElement, |
| 22 | React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof alertVariants> |
| gio | 7f98e77 | 2025-05-07 11:00:14 +0000 | [diff] [blame] | 23 | >(({ className, variant, ...props }, ref) => ( |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 24 | <div ref={ref} role="alert" className={cn(alertVariants({ variant }), className)} {...props} /> |
| 25 | )); |
| 26 | Alert.displayName = "Alert"; |
| gio | 7f98e77 | 2025-05-07 11:00:14 +0000 | [diff] [blame] | 27 | |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 28 | const AlertTitle = React.forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLHeadingElement>>( |
| 29 | ({ className, ...props }, ref) => ( |
| 30 | <h5 ref={ref} className={cn("mb-1 font-medium leading-none tracking-tight", className)} {...props} /> |
| 31 | ), |
| 32 | ); |
| 33 | AlertTitle.displayName = "AlertTitle"; |
| gio | 7f98e77 | 2025-05-07 11:00:14 +0000 | [diff] [blame] | 34 | |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 35 | const AlertDescription = React.forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLParagraphElement>>( |
| 36 | ({ className, ...props }, ref) => ( |
| 37 | <div ref={ref} className={cn("text-sm [&_p]:leading-relaxed", className)} {...props} /> |
| 38 | ), |
| 39 | ); |
| 40 | AlertDescription.displayName = "AlertDescription"; |
| gio | 7f98e77 | 2025-05-07 11:00:14 +0000 | [diff] [blame] | 41 | |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 42 | export { Alert, AlertTitle, AlertDescription }; |