import { useEffect } from 'react'; import { ToastEntry } from './types'; interface Props { toasts: ToastEntry[]; onDismiss: (id: number) => void; } export function ToastStack({ toasts, onDismiss }: Props) { return (
{toasts.map((t) => ( onDismiss(t.id)} /> ))}
); } function Toast({ entry, onDismiss }: { entry: ToastEntry; onDismiss: () => void }) { useEffect(() => { if (entry.kind === 'error') return; const timer = setTimeout(onDismiss, 4500); return () => clearTimeout(timer); }, [entry.kind, onDismiss]); return (
{entry.text}
{entry.details && entry.details.length > 0 && ( )}
); } let nextId = 1; export function makeToast(kind: ToastEntry['kind'], text: string, details?: string[]): ToastEntry { return { id: nextId++, kind, text, details }; }