Files
client/app/renderer/js/toast.js
T
2026-10-24 06:34:33 +03:00

17 lines
809 B
JavaScript

import { t } from './i18n.js';
import { $, h, icon } from './dom.js';
const MAX_TOASTS = 4;
/** Non-blocking notice in the polite live region. Errors stay longer. */
export function toast(text, kind = 'info') {
const host = $('#toasts');
const close = h('button', { class: 'icon-btn', type: 'button', 'aria-label': t('ui.dismiss.notification'), 'data-i18n-aria-label': 'ui.dismiss.notification' }, icon('x'));
const el = h('div', { class: 'toast', role: kind === 'error' ? 'alert' : 'status', dataset: { kind } }, h('span', { class: 'toast-text', text }), close);
const remove = () => el.remove();
close.addEventListener('click', remove);
host.appendChild(el);
while (host.children.length > MAX_TOASTS) host.firstElementChild.remove();
setTimeout(remove, kind === 'error' ? 10000 : 5000);
}