Import source: cshare-app/src/components/Toast

Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality.
This commit is contained in:
arsam
2026-09-18 23:14:20 +03:30
parent 89afc61022
commit 329e3bd7d8
+27
View File
@@ -0,0 +1,27 @@
import { useState, useCallback } from 'react';
import { ToastContext } from './ToastContext';
export function ToastProvider({ children }) {
const [toasts, setToasts] = useState([]);
const addToast = useCallback((message, type = 'info') => {
const id = Date.now() + Math.random();
setToasts((prev) => [...prev, { id, message, type }]);
setTimeout(() => {
setToasts((prev) => prev.filter((t) => t.id !== id));
}, 3000);
}, []);
return (
<ToastContext.Provider value={addToast}>
{children}
<div className="toast-container">
{toasts.map((toast) => (
<div key={toast.id} className={`toast toast-${toast.type}`}>
{toast.message}
</div>
))}
</div>
</ToastContext.Provider>
);
}