import * as React from "react" import { AlertCircleIcon, CheckCircle2Icon, InfoIcon, TriangleAlertIcon } from "lucide-react" import { cn } from "@/lib/utils" export type AlertTone = "info" | "success" | "warning" | "destructive" | "muted" export type AlertProps = React.ComponentProps<"div"> & { tone?: AlertTone variant?: "soft" | "outline" | "solid" size?: "sm" | "md" title?: React.ReactNode description?: React.ReactNode icon?: React.ReactNode action?: React.ReactNode dismissible?: boolean dismissLabel?: string onDismiss?: () => void actionsAlign?: "start" | "end" } const alertToneClassName: Record, string>> = { info: { soft: "border-primary/25 bg-primary/5 text-foreground", outline: "border-primary/35 bg-background text-foreground", solid: "border-primary bg-primary text-primary-foreground", }, success: { soft: "border-emerald-500/25 bg-emerald-500/10 text-foreground", outline: "border-emerald-500/35 bg-background text-foreground", solid: "border-emerald-600 bg-emerald-600 text-white", }, warning: { soft: "border-amber-500/30 bg-amber-500/10 text-foreground", outline: "border-amber-500/35 bg-background text-foreground", solid: "border-amber-500 bg-amber-500 text-amber-950", }, destructive: { soft: "border-destructive/30 bg-destructive/10 text-foreground", outline: "border-destructive/35 bg-background text-foreground", solid: "border-destructive bg-destructive text-destructive-foreground", }, muted: { soft: "border-border bg-muted/50 text-foreground", outline: "border-border bg-background text-foreground", solid: "border-border bg-foreground text-background", }, } const alertIconClassName: Record = { info: "text-primary", success: "text-emerald-600 dark:text-emerald-400", warning: "text-amber-600 dark:text-amber-400", destructive: "text-destructive", muted: "text-muted-foreground", } function defaultIcon(tone: AlertTone) { switch (tone) { case "success": return case "warning": return case "destructive": return default: return } } function Alert({ tone = "info", variant = "soft", size = "md", title, description, icon, action, dismissible = false, dismissLabel = "Dismiss alert", onDismiss, actionsAlign = "end", className, children, ...props }: AlertProps) { return (
{icon ?? defaultIcon(tone)}
{title &&
{title}
} {(description || children) && (
{description ?? children}
)}
{(action || dismissible) ? (
{action} {dismissible ? ( ) : null}
) : null}
) } export { Alert }