-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
40 lines (40 loc) · 1.14 KB
/
main.js
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
38
39
40
const notification = document.querySelector(".notification"),
buttons = document.querySelectorAll(".buttons .btn");
const toastDetails = {
timer: 5000,
success:{
icon: 'fa-circle-check',
Text: 'Success: This is Success.',
},
error:{
icon: 'fa-xmark',
Text: 'Error: This is Error',
},
warning:{
icon: 'fa-triangle-exclamation',
Text: 'Warning: This is Warning.',
},
info:{
icon: 'fa-circle-info',
Text: 'Info: This is Info.',
}
}
const removeToast = (toast) =>{
toast.classList.add("hide");
if (toast.timeoutId) clearTimeout(toast.timeoutId);
setTimeout(()=> toast.remove(), 500);
}
const createToast = (id) => {
const {icon, Text} = toastDetails[id];
const toast = document.createElement("li");
toast.className = `toast ${id}`;
toast.innerHTML = `<div class="column">
<i class="fa-solid ${icon}"></i>
<span>${Text}</span>
</div><i class = "fa-solid fa-xmark" onclick="removeToast(this.parentElement)"> </i>`;
notification.appendChild(toast);
toast.timeoutId = setTimeout(() => removeToast(toast), toastDetails.timer);
}
buttons.forEach(btn => {
btn.addEventListener("click", () => createToast(btn.id));
});