"use client"; import React, { useState, useRef, useEffect } from "react"; import { AlertCircle, AlertTriangle, CheckCircle2, Info, X, ChevronDown, ChevronUp, } from "lucide-react"; export type AlertTone = "neutral" | "info" | "success" | "warning" | "danger" | "error"; export type AlertVariant = "subtle" | "outline" | "solid" | "glass"; export interface AlertProps { title?: React.ReactNode; description?: React.ReactNode; children?: React.ReactNode; tone?: AlertTone; variant?: AlertVariant; /** Pass custom icon, or false to suppress the icon */ icon?: React.ReactNode | false; /** Whether the alert can be dismissed by the user */ dismissible?: boolean; /** Callback fired after the dismiss animation completes */ onDismiss?: () => void; /** Action slot (e.g. Retry button, Upgrade link) */ action?: React.ReactNode; /** Technical details or stack trace for collapsible drawer */ details?: React.ReactNode | string; className?: string; style?: React.CSSProperties; } const TONE_CONFIGS: Record< string, { icon: typeof AlertCircle; color: string; bgSubtle: string; borderSubtle: string; glow: string; } > = { danger: { icon: AlertCircle, color: "var(--color-error, #EF4444)", bgSubtle: "rgba(239, 68, 68, 0.08)", borderSubtle: "rgba(239, 68, 68, 0.25)", glow: "0 0 20px -4px rgba(239, 68, 68, 0.18)", }, error: { icon: AlertCircle, color: "var(--color-error, #EF4444)", bgSubtle: "rgba(239, 68, 68, 0.08)", borderSubtle: "rgba(239, 68, 68, 0.25)", glow: "0 0 20px -4px rgba(239, 68, 68, 0.18)", }, warning: { icon: AlertTriangle, color: "var(--color-warning, #F59E0B)", bgSubtle: "rgba(245, 158, 11, 0.08)", borderSubtle: "rgba(245, 158, 11, 0.25)", glow: "0 0 20px -4px rgba(245, 158, 11, 0.18)", }, info: { icon: Info, color: "var(--color-info, #3B82F6)", bgSubtle: "rgba(59, 130, 246, 0.08)", borderSubtle: "rgba(59, 130, 246, 0.25)", glow: "0 0 20px -4px rgba(59, 130, 246, 0.18)", }, success: { icon: CheckCircle2, color: "var(--color-success, #10B981)", bgSubtle: "rgba(16, 185, 129, 0.08)", borderSubtle: "rgba(16, 185, 129, 0.25)", glow: "0 0 20px -4px rgba(16, 185, 129, 0.18)", }, neutral: { icon: Info, color: "var(--text-secondary, #A7A3B4)", bgSubtle: "var(--bg-elevated, #17151F)", borderSubtle: "var(--border-color, #272430)", glow: "none", }, }; /** * EasyUI-inspired Alert component. * Features smooth spring-like entrance, collapse dismissal, tone-aware styling, * action slot, and expandable diagnostics. */ export function Alert({ title, description, children, tone = "neutral", variant = "subtle", icon, dismissible = false, onDismiss, action, details, className = "", style, }: AlertProps) { const [isDismissing, setIsDismissing] = useState(false); const [isDismissed, setIsDismissed] = useState(false); const [showDetails, setShowDetails] = useState(false); const alertRef = useRef(null); const normalizedTone = tone === "error" ? "danger" : tone; const config = TONE_CONFIGS[normalizedTone] || TONE_CONFIGS.neutral; const IconComponent = config.icon; const handleDismiss = () => { setIsDismissing(true); setTimeout(() => { setIsDismissed(true); onDismiss?.(); }, 280); }; if (isDismissed) { return null; } const isUrgent = normalizedTone === "danger" || normalizedTone === "warning"; let bg = config.bgSubtle; let borderColor = config.borderSubtle; let boxShadow = config.glow; if (variant === "outline") { bg = "transparent"; } else if (variant === "solid") { bg = config.color; borderColor = config.color; } else if (variant === "glass") { bg = "rgba(18, 16, 22, 0.65)"; boxShadow = `${config.glow}, inset 0 1px 0 rgba(255, 255, 255, 0.08)`; } return (
{/* Top accent glow line */}
{/* Tone Icon */} {icon !== false && (
{icon ? icon : }
)} {/* Content */}
{title && (
{title}
)} {description && (
{description}
)} {children && (
{children}
)} {/* Action Slot & Expandable Details Button */} {(action || details) && (
{action} {details && ( )}
)}
{/* Dismiss Button */} {dismissible && ( )}
{/* Expandable Technical Details Drawer */} {details && showDetails && (
{typeof details === "string" ? details : JSON.stringify(details, null, 2)}
)}
); }