/* eslint-disable react-refresh/only-export-components */ import React, { createContext, useContext, useState, useCallback } from "react"; import { motion, AnimatePresence } from "framer-motion"; import { CheckCircle2, XCircle, AlertCircle, Info, X } from "lucide-react"; import { cn } from "../../utils/cn"; const ToastContext = createContext(); export function ToastProvider({ children }) { const [toasts, setToasts] = useState([]); const removeToast = useCallback((id) => { setToasts((prev) => prev.filter((toast) => toast.id !== id)); }, []); const addToast = useCallback(({ title, description, variant = "default", duration = 3000 }) => { const id = Math.random().toString(36).substr(2, 9); setToasts((prev) => [...prev, { id, title, description, variant, duration }]); if (duration !== Infinity) { setTimeout(() => { removeToast(id); }, duration); } }, [removeToast]); return ( {children} ); } const icons = { default: , success: , error: , warning: , }; function ToastContainer({ toasts, removeToast }) { return (
{toasts.map((toast) => (
{icons[toast.variant || "default"]}
{toast.title &&
{toast.title}
} {toast.description && (
{toast.description}
)}
))}