import { useSyncExternalStore } from "react"; import { useTranslation } from "react-i18next"; import { AlertCircle, AlertTriangle, CheckCircle2, Info, X, XCircle, } from "lucide-react"; import { dismiss, getActiveToasts, subscribe, type NotifLevel, } from "../lib/notifications"; export const LEVEL_STYLE: Record< NotifLevel, { icon: typeof Info; color: string; bar: string } > = { info: { icon: Info, color: "text-accent", bar: "bg-accent" }, success: { icon: CheckCircle2, color: "text-emerald-400", bar: "bg-emerald-400" }, warning: { icon: AlertTriangle, color: "text-amber-400", bar: "bg-amber-400" }, error: { icon: AlertCircle, color: "text-red-400", bar: "bg-red-400" }, fatal: { icon: XCircle, color: "text-red-500", bar: "bg-red-500" }, }; export default function Toaster() { const { t } = useTranslation(); const toasts = useSyncExternalStore(subscribe, getActiveToasts, getActiveToasts); return (
{toasts.map((toast) => { const { icon: Icon, color, bar } = LEVEL_STYLE[toast.level]; return (
{toast.title &&
{toast.title}
}
{toast.message}
{toast.action && ( )}
{toast.duration && (
)}
); })}
); }