animation toast

This commit is contained in:
hamid zarghami
2025-05-03 14:57:58 +03:30
parent 7fd9aca86f
commit fbd15e25a1
2 changed files with 28 additions and 6 deletions
+9 -1
View File
@@ -5,6 +5,7 @@ interface Toast {
id: string; id: string;
message: string; message: string;
type?: 'success' | 'error' | 'info'; type?: 'success' | 'error' | 'info';
isExiting?: boolean;
} }
let addToast: (toast: Toast) => void; let addToast: (toast: Toast) => void;
@@ -17,8 +18,14 @@ const ToastContainer: React.FC = () => {
setToasts((prev) => [...prev, toast]); setToasts((prev) => [...prev, toast]);
// حذف خودکار بعد از ۳ ثانیه // حذف خودکار بعد از ۳ ثانیه
setTimeout(() => {
setToasts((prev) => prev.map(t =>
t.id === toast.id ? { ...t, isExiting: true } : t
));
setTimeout(() => { setTimeout(() => {
setToasts((prev) => prev.filter((t) => t.id !== toast.id)); setToasts((prev) => prev.filter((t) => t.id !== toast.id));
}, 300);
}, 3000); }, 3000);
}; };
@@ -32,7 +39,8 @@ const ToastContainer: React.FC = () => {
{toasts.map((toast) => ( {toasts.map((toast) => (
<div <div
key={toast.id} key={toast.id}
className={`px-4 flex items-center gap-2 backdrop-blur-2xl h-16 min-w-[300px] rounded-2xl shadow-md transition-transform ${toast.type === 'success' className={`px-4 flex items-center gap-2 backdrop-blur-2xl h-16 min-w-[300px] rounded-2xl shadow-md
${toast.isExiting ? 'animate-slide-out-right' : 'animate-slide-in-right'} ${toast.type === 'success'
? 'bg-white/70 text-black' ? 'bg-white/70 text-black'
: toast.type === 'error' : toast.type === 'error'
? 'bg-white/70 text-black' ? 'bg-white/70 text-black'
+14
View File
@@ -21,6 +21,20 @@ module.exports = withMT({
}, },
borderRadius: { borderRadius: {
'2.5': '10px' '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'
} }
}, },
}, },