Files
Papo/public/ts-build/ui/toast.js
Pascal Prießnitz 7a296f7b4a
All checks were successful
Deploy Discord Bot / deploy (push) Successful in 38s
[deploy] Emit frontend bundle as ESM for browser
2025-12-04 17:06:27 +01:00

24 lines
766 B
JavaScript

let currentTimeout = null;
export 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);
}
export function hideToast() {
const toast = document.getElementById('toast-root');
if (!toast)
return;
toast.classList.remove('show');
}