diff --git a/src/components/Toast.tsx b/src/components/Toast.tsx index eff3b7e..2069aff 100644 --- a/src/components/Toast.tsx +++ b/src/components/Toast.tsx @@ -5,6 +5,7 @@ interface Toast { id: string; message: string; type?: 'success' | 'error' | 'info'; + isExiting?: boolean; } let addToast: (toast: Toast) => void; @@ -18,7 +19,13 @@ const ToastContainer: React.FC = () => { // حذف خودکار بعد از ۳ ثانیه setTimeout(() => { - setToasts((prev) => prev.filter((t) => t.id !== toast.id)); + setToasts((prev) => prev.map(t => + t.id === toast.id ? { ...t, isExiting: true } : t + )); + + setTimeout(() => { + setToasts((prev) => prev.filter((t) => t.id !== toast.id)); + }, 300); }, 3000); }; @@ -28,15 +35,16 @@ const ToastContainer: React.FC = () => { }, []); return ( -
+
{toasts.map((toast) => (
{ diff --git a/tailwind.config.js b/tailwind.config.js index 627586e..50e1a75 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -21,6 +21,20 @@ module.exports = withMT({ }, borderRadius: { '2.5': '10px' + }, + keyframes: { + 'slide-in-right': { + '0%': { transform: 'translateX(100%)', opacity: '0' }, + '100%': { transform: 'translateX(0)', opacity: '1' } + }, + 'slide-out-right': { + '0%': { transform: 'translateX(0)', opacity: '1' }, + '100%': { transform: 'translateX(100%)', opacity: '0' } + } + }, + animation: { + 'slide-in-right': 'slide-in-right 0.3s ease-out', + 'slide-out-right': 'slide-out-right 0.3s ease-out' } }, },