forked from Movalabs-crew/mova-store
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToast.jsx
More file actions
37 lines (32 loc) · 950 Bytes
/
Copy pathToast.jsx
File metadata and controls
37 lines (32 loc) · 950 Bytes
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
import { useEffect, useState } from "react";
const Toast = ({ message, show, onClose , time=3000}) => {
const [visible, setVisible] = useState(false);
useEffect(() => {
if (show) {
setVisible(true);
const timer = setTimeout(() => {
setVisible(false);
const exitTimer = setTimeout(() => {
onClose();
}, 300);
return () => clearTimeout(exitTimer);
}, time);
return () => clearTimeout(timer);
} else {
setVisible(false);
}
}, [show, onClose]);
return (
<div
className={`fixed bottom-10 right-5 bg-gray-800 text-white p-3 rounded shadow-lg transform transition-transform duration-300 ease-in-out ${
visible ? "translate-x-0 opacity-100" : "translate-x-full opacity-0"
}`}
>
{message}
<button onClick={onClose} className="ml-4 text-purple-500">
✕
</button>
</div>
);
};
export default Toast;