import * as React from "react"; import { cn } from "../../lib/utils"; import { AlertCircle, CheckCircle, Info, X, AlertTriangle } from "lucide-react"; const alertVariants = { variant: { default: "bg-white dark:bg-black text-foreground", destructive: " border-gray-400 dark:border-gray-700/50 text-red-500 [&>svg]:text-destructive", success: "border-green-500/50 text-green-700 dark:text-green-500 [&>svg]:text-green-500", warning: "border-yellow-500/50 text-yellow-700 dark:text-yellow-500 [&>svg]:text-yellow-500", info: "border-blue-500/50 text-blue-700 dark:text-blue-500 [&>svg]:text-blue-500", }, size: { default: "p-4", sm: "p-3 text-sm", lg: "p-6 text-base" } }; interface AlertProps extends React.HTMLAttributes { /** The style variant of the alert */ variant?: keyof typeof alertVariants.variant; /** The size of the alert */ size?: keyof typeof alertVariants.size; /** Whether the alert should be dismissible */ dismissible?: boolean; /** Callback fired when dismissing the alert */ onDismiss?: () => void; /** Whether to display an icon */ withIcon?: boolean; /** Custom icon to display */ icon?: React.ReactNode; } const Alert = React.forwardRef( ({ className, variant = "default", size = "default", dismissible = false, onDismiss, withIcon = false, icon, children, ...props }, ref) => { // Icon mapping based on variant const variantIcons = { default: , destructive: , success: , warning: , info: }; const handleDismiss = () => { if (onDismiss) { onDismiss(); } }; return (
svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground", withIcon && "[&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px]", alertVariants.variant[variant], alertVariants.size[size], className )} {...props} > {withIcon && (icon || variantIcons[variant])} {children} {dismissible && ( )}
); } ); Alert.displayName = "Alert"; const AlertTitle = React.forwardRef< HTMLParagraphElement, React.HTMLAttributes & { /** Size of the title */ size?: "sm" | "default" | "lg"; } >(({ className, size = "default", ...props }, ref) => { const sizeClasses = { sm: "text-sm", default: "text-base", lg: "text-lg" }; return (
); }); AlertTitle.displayName = "AlertTitle"; const AlertDescription = React.forwardRef< HTMLParagraphElement, React.HTMLAttributes & { /** Text color intensity */ intensity?: "muted" | "default"; } >(({ className, intensity = "default", ...props }, ref) => (
)); AlertDescription.displayName = "AlertDescription"; export { Alert, AlertTitle, AlertDescription };