blob: ee9db6ac568294633bec53730c7c03db8731223b [file] [log] [blame]
giod0026612025-05-08 13:00:36 +00001import * as React from "react";
2import { cva, type VariantProps } from "class-variance-authority";
3import { cn } from "@/lib/utils";
gio7f98e772025-05-07 11:00:14 +00004
5const alertVariants = cva(
giod0026612025-05-08 13:00:36 +00006 "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);
gio7f98e772025-05-07 11:00:14 +000019
20const Alert = React.forwardRef<
giod0026612025-05-08 13:00:36 +000021 HTMLDivElement,
22 React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof alertVariants>
gio7f98e772025-05-07 11:00:14 +000023>(({ className, variant, ...props }, ref) => (
giod0026612025-05-08 13:00:36 +000024 <div ref={ref} role="alert" className={cn(alertVariants({ variant }), className)} {...props} />
25));
26Alert.displayName = "Alert";
gio7f98e772025-05-07 11:00:14 +000027
giod0026612025-05-08 13:00:36 +000028const 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);
33AlertTitle.displayName = "AlertTitle";
gio7f98e772025-05-07 11:00:14 +000034
giod0026612025-05-08 13:00:36 +000035const 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);
40AlertDescription.displayName = "AlertDescription";
gio7f98e772025-05-07 11:00:14 +000041
giod0026612025-05-08 13:00:36 +000042export { Alert, AlertTitle, AlertDescription };