This commit is contained in:
27
public/ts-build/ui/toast.js
Normal file
27
public/ts-build/ui/toast.js
Normal file
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.showToast = showToast;
|
||||
exports.hideToast = hideToast;
|
||||
let currentTimeout = null;
|
||||
function showToast(message, isError = false, duration = 2500) {
|
||||
let toast = document.getElementById('toast-root');
|
||||
if (!toast) {
|
||||
toast = document.createElement('div');
|
||||
toast.id = 'toast-root';
|
||||
document.body.appendChild(toast);
|
||||
}
|
||||
toast.className = `toast ${isError ? 'error' : ''}`;
|
||||
toast.textContent = message;
|
||||
requestAnimationFrame(() => {
|
||||
toast?.classList.add('show');
|
||||
});
|
||||
if (currentTimeout)
|
||||
window.clearTimeout(currentTimeout);
|
||||
currentTimeout = window.setTimeout(() => hideToast(), duration);
|
||||
}
|
||||
function hideToast() {
|
||||
const toast = document.getElementById('toast-root');
|
||||
if (!toast)
|
||||
return;
|
||||
toast.classList.remove('show');
|
||||
}
|
||||
Reference in New Issue
Block a user