Spaces:
Running
Running
File size: 1,148 Bytes
180dc07 |
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 |
function showNotification(type, message, duration = 5000) {
const container = document.querySelector(".notification-container");
const notification = document.createElement("div");
notification.classList.add("notification", `notification-${type}`);
notification.innerHTML = `
<div class="notification-icon">${getIconForType(type)}</div>
<div class="notification-content">
<div class="notification-title">${type}</div>
<div class="notification-message">${message}</div>
</div>
<button class="notification-close" onclick='this.parentNode.remove()' aria-label="Close notification">X</button>`;
container.appendChild(notification);
if (duration > 0) {
setTimeout(() => {
closeNotification(notification);
}, duration);
}
}
function closeNotification(notification) {
notification.classList.add("hide");
setTimeout(() => {
notification.remove();
}, 300);
}
function getIconForType(type) {
switch (type) {
case "error":
return "❌";
case "warning":
return "⚠️";
case "success":
return "✅";
case "info":
return "ℹ️";
default:
return "";
}
}
|