'use client'; import { useEffect, useState } from 'react'; import { CheckCircle, AlertCircle, Info, X } from 'lucide-react'; import { cva, type VariantProps } from 'class-variance-authority'; import { cn } from '@/lib/utils'; export type NotificationType = 'success' | 'error' | 'info'; const notificationVariants = cva( "fixed z-50 top-4 right-4 flex items-center gap-3 p-4 rounded-lg shadow-lg border max-w-sm transition-all duration-300 animate-in fade-in slide-in-from-top-5", { variants: { variant: { success: "bg-background border-border text-foreground", error: "bg-background border-border text-foreground", info: "bg-background border-border text-foreground", } }, defaultVariants: { variant: "info", }, } ); interface NotificationProps extends VariantProps { type: NotificationType; message: string; duration?: number; onClose?: () => void; } export function Notification({ type, message, duration = 5000, // Default duration of 5 seconds onClose }: NotificationProps) { const [isVisible, setIsVisible] = useState(true); useEffect(() => { if (duration > 0) { const timer = setTimeout(() => { setIsVisible(false); if (onClose) onClose(); }, duration); return () => clearTimeout(timer); } }, [duration, onClose]); const handleClose = () => { setIsVisible(false); if (onClose) onClose(); }; if (!isVisible) return null; const getIcon = () => { switch (type) { case 'success': return ; case 'error': return ; case 'info': return ; default: return null; } }; return (
{getIcon()}
{message}
); }