forked from HoanghoDev/toast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
54 lines (49 loc) · 1.68 KB
/
app.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
41
42
43
44
45
46
47
48
49
50
51
52
let success = document.getElementById('success');
let error = document.getElementById('error');
let warning = document.getElementById('warning');
let info = document.getElementById('info');
let notifications = document.querySelector('.notifications');
function createToast(type, icon, title, text){
let newToast = document.createElement('div');
newToast.innerHTML = `
<div class="toast ${type}">
<i class="${icon}"></i>
<div class="content">
<div class="title">${title}</div>
<span>${text}</span>
</div>
<i class="close fa-solid fa-xmark"
onclick="(this.parentElement).remove()"
></i>
</div>`;
notifications.appendChild(newToast);
newToast.timeOut = setTimeout(() => newToast.remove(), 5000)
}
success.onclick = function(){
let type = 'success';
let icon = 'fa-solid fa-circle-check';
let title = 'Success';
let text = 'This is a success toast.';
createToast(type, icon, title, text);
}
error.onclick = function(){
let type = 'error';
let icon = 'fa-solid fa-circle-exclamation';
let title = 'Error';
let text = 'This is a error toast.';
createToast(type, icon, title, text);
}
warning.onclick = function(){
let type = 'warning';
let icon = 'fa-solid fa-triangle-exclamation';
let title = 'Warning';
let text = 'This is a warning toast.';
createToast(type, icon, title, text);
}
info.onclick = function(){
let type = 'info';
let icon = 'fa-solid fa-circle-info';
let title = 'Info';
let text = 'This is a info toast.';
createToast(type, icon, title, text);
}