diff --git a/src/contexts/ToastContext.tsx b/src/contexts/ToastContext.tsx
index 5fb8ef0..3f5a18f 100644
--- a/src/contexts/ToastContext.tsx
+++ b/src/contexts/ToastContext.tsx
@@ -1,4 +1,5 @@
import React, { createContext, useContext, useState, useCallback, ReactNode, useEffect } from 'react';
+import { CheckCircle2, AlertCircle, Info, XCircle, X } from 'lucide-react';
export type ToastVariant = 'success' | 'info' | 'warning' | 'error';
@@ -25,13 +26,16 @@ export const ToastProvider: React.FC<{ children: ReactNode }> = ({ children }) =
}, []);
const removeToast = useCallback((id: string) => {
- setToasts(prev => prev.filter(t => t.id !== id));
+ setToasts(prev => prev.map(t => t.id === id ? { ...t, exiting: true } : t) as any);
+ setTimeout(() => {
+ setToasts(prev => prev.filter(t => t.id !== id));
+ }, 300); // Matches the exit animation duration
}, []);
return (
{children}
-
+
);
};
@@ -42,16 +46,13 @@ export const useToast = () => {
return context;
};
-const ToastItem: React.FC<{ toast: ToastMessage; removeToast: (id: string) => void }> = ({ toast, removeToast }) => {
+const ToastItem: React.FC<{ toast: ToastMessage & { exiting?: boolean }; removeToast: (id: string) => void }> = ({ toast, removeToast }) => {
const [isHovered, setIsHovered] = useState(false);
useEffect(() => {
- // Determine duration
let timeoutDuration = toast.duration ?? 5000;
- if (timeoutDuration < 5000) timeoutDuration = 5000; // at least 5 seconds
+ if (timeoutDuration < 5000) timeoutDuration = 5000;
- // Don't auto-dismiss actionable or important errors (unless they specified a duration)
- // Actually, "Do not auto-dismiss actionable or important errors"
if (toast.isActionable || (toast.variant === 'error' && !toast.duration)) {
return;
}
@@ -69,36 +70,45 @@ const ToastItem: React.FC<{ toast: ToastMessage; removeToast: (id: string) => vo
const role = toast.variant === 'error' ? 'alert' : 'status';
- // Variant styling
const variantStyles = {
- success: 'border-[#10b981]/20 bg-[#064e3b]/95 text-[#34d399]',
- info: 'border-[hsl(var(--border-modal))] bg-[hsl(var(--surface-overlay))] text-[hsl(var(--text-primary))]',
- warning: 'border-[#eab308]/20 bg-[#713f12]/95 text-[#fde047]',
- error: 'border-[#ef4444]/20 bg-[#7f1d1d]/95 text-[#f87171]',
+ success: 'border-emerald-500/30 bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 shadow-emerald-500/10',
+ info: 'border-blue-500/30 bg-blue-500/10 text-blue-600 dark:text-blue-400 shadow-blue-500/10',
+ warning: 'border-amber-500/30 bg-amber-500/10 text-amber-600 dark:text-amber-400 shadow-amber-500/10',
+ error: 'border-red-500/30 bg-red-500/10 text-red-600 dark:text-red-400 shadow-red-500/10',
};
- const style = variantStyles[toast.variant || 'info'];
+ const icons = {
+ success: ,
+ error: ,
+ warning: ,
+ info: ,
+ };
+
+ const variant = toast.variant || 'info';
+ const style = variantStyles[variant];
+ const Icon = icons[variant];
return (
setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
onFocus={() => setIsHovered(true)}
onBlur={() => setIsHovered(false)}
>
-
{toast.message}
+
{Icon}
+
{toast.message}
);
@@ -106,7 +116,13 @@ const ToastItem: React.FC<{ toast: ToastMessage; removeToast: (id: string) => vo
const ToastContainer: React.FC<{ toasts: ToastMessage[]; removeToast: (id: string) => void }> = ({ toasts, removeToast }) => {
return (
-
+
+
{toasts.map(toast => (
))}