/** * Toast Notification Component */ import React, { useState, useEffect } from 'react'; import type { ToastNotification as ToastType } from '../types'; interface ToastNotificationProps { notification: ToastType; onDismiss: (id: string) => void; } export const ToastNotification: React.FC = ({ notification, onDismiss }) => { const [isVisible, setIsVisible] = useState(true); const [progress, setProgress] = useState(100); const duration = notification.duration || 5000; // 5 seconds default useEffect(() => { const progressInterval = setInterval(() => { setProgress((prev) => { const decrease = (100 / duration) * 100; // Update every 100ms return Math.max(0, prev - decrease); }); }, 100); const timeoutId = setTimeout(() => { setIsVisible(false); setTimeout(() => onDismiss(notification.id), 300); // Wait for animation }, duration); return () => { clearInterval(progressInterval); clearTimeout(timeoutId); }; }, [notification.id, duration, onDismiss]); const getIcon = () => { switch (notification.type) { case 'success': return ( ); case 'info': return ( ); case 'warning': return ( ); case 'error': return ( ); } }; const bgColor = { success: 'bg-green-900/90', info: 'bg-blue-900/90', warning: 'bg-yellow-900/90', error: 'bg-red-900/90' }[notification.type]; const borderColor = { success: 'border-green-600', info: 'border-blue-600', warning: 'border-yellow-600', error: 'border-red-600' }[notification.type]; const progressColor = { success: 'bg-green-400', info: 'bg-blue-400', warning: 'bg-yellow-400', error: 'bg-red-400' }[notification.type]; return (
{getIcon()}

{notification.title}

{notification.message}

{/* Progress bar */}
); };