blob: 350d1cdaadfce399b6b35509b3c3ec7cf7c560e4 [file] [log] [blame]
gio7f98e772025-05-07 11:00:14 +00001import * as React from "react"
2import { cva, type VariantProps } from "class-variance-authority"
3import { cn } from "@/lib/utils"
4
5const 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
21const 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))
32Alert.displayName = "Alert"
33
34const 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))
44AlertTitle.displayName = "AlertTitle"
45
46const 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))
56AlertDescription.displayName = "AlertDescription"
57
58export { Alert, AlertTitle, AlertDescription }