From fbd15e25a1f5b7f34e4a160d1cb69b7c33bad33e Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Sat, 3 May 2025 14:57:58 +0330 Subject: [PATCH] animation toast --- src/components/Toast.tsx | 20 ++++++++++++++------ tailwind.config.js | 14 ++++++++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) 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' } }, },