Spaces:
Runtime error
Runtime error
File size: 1,692 Bytes
ef865f2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | import React, { useEffect } from 'react';
import { CheckCircle, XCircle, AlertTriangle, Info, X } from 'lucide-react';
const ICONS = {
success: CheckCircle,
error: XCircle,
warning: AlertTriangle,
info: Info,
};
const COLORS = {
success: 'border-emerald-500/40 bg-emerald-500/10 text-emerald-400',
error: 'border-red-500/40 bg-red-500/10 text-red-400',
warning: 'border-amber-500/40 bg-amber-500/10 text-amber-400',
info: 'border-blue-500/40 bg-blue-500/10 text-blue-400',
};
const Toast = ({ toast, onRemove }) => {
const Icon = ICONS[toast.type] || Info;
useEffect(() => {
const t = setTimeout(() => onRemove(toast.id), toast.duration ?? 4000);
return () => clearTimeout(t);
}, [toast.id, toast.duration, onRemove]);
return (
<div className={`flex items-start space-x-3 px-4 py-3 rounded-xl border shadow-2xl backdrop-blur-sm max-w-sm animate-in slide-in-from-right-4 duration-300 ${COLORS[toast.type] || COLORS.info}`}>
<Icon size={15} className="shrink-0 mt-0.5" />
<p className="text-xs font-medium flex-1 leading-relaxed">{toast.message}</p>
<button onClick={() => onRemove(toast.id)} className="shrink-0 opacity-50 hover:opacity-100 transition-opacity">
<X size={13} />
</button>
</div>
);
};
export const ToastContainer = ({ toasts, removeToast }) => {
if (!toasts.length) return null;
return (
<div className="fixed bottom-6 right-6 z-[9999] flex flex-col space-y-2 pointer-events-none">
{toasts.map(t => (
<div key={t.id} className="pointer-events-auto">
<Toast toast={t} onRemove={removeToast} />
</div>
))}
</div>
);
};
export default Toast;
|