alert.jsx
1 import * as React from "react" 2 import { cva } from "class-variance-authority"; 3 4 import { cn } from "@/lib/utils" 5 6 const alertVariants = cva( 7 "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", 8 { 9 variants: { 10 variant: { 11 default: "bg-background text-foreground", 12 destructive: 13 "border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive", 14 }, 15 }, 16 defaultVariants: { 17 variant: "default", 18 }, 19 } 20 ) 21 22 const Alert = React.forwardRef(({ className, variant, ...props }, ref) => ( 23 <div 24 ref={ref} 25 role="alert" 26 className={cn(alertVariants({ variant }), className)} 27 {...props} /> 28 )) 29 Alert.displayName = "Alert" 30 31 const AlertTitle = React.forwardRef(({ className, ...props }, ref) => ( 32 <h5 33 ref={ref} 34 className={cn("mb-1 font-medium leading-none tracking-tight", className)} 35 {...props} /> 36 )) 37 AlertTitle.displayName = "AlertTitle" 38 39 const AlertDescription = React.forwardRef(({ className, ...props }, ref) => ( 40 <div 41 ref={ref} 42 className={cn("text-sm [&_p]:leading-relaxed", className)} 43 {...props} /> 44 )) 45 AlertDescription.displayName = "AlertDescription" 46 47 export { Alert, AlertTitle, AlertDescription }