/** * Toast notification component * Displays temporary success/error/info messages */ import { useEffect } from 'react'; export type ToastType = 'success' | 'error' | 'info' | 'warning'; export interface ToastMessage { id: string; message: string; type: ToastType; duration?: number; } interface ToastProps { message: ToastMessage; onClose: (id: string) => void; } /** * Single toast notification */ export function Toast({ message, onClose }: ToastProps) { useEffect(() => { const timer = setTimeout(() => { onClose(message.id); }, message.duration || 5000); return () => clearTimeout(timer); }, [message.id, message.duration, onClose]); const bgColor = { success: 'bg-green-600', error: 'bg-red-600', info: 'bg-blue-600', warning: 'bg-yellow-600', }[message.type]; const icon = { success: '✓', error: '✕', info: 'ℹ', warning: '⚠', }[message.type]; return (
{icon} {message.message}
); } /** * Toast container that displays all active toasts */ interface ToastContainerProps { messages: ToastMessage[]; onClose: (id: string) => void; } export function ToastContainer({ messages, onClose }: ToastContainerProps) { if (messages.length === 0) return null; return (
{messages.map((message) => ( ))}
); }