mirror of
https://github.com/deunix-educ/PyQuest.git
synced 2026-11-25 08:19:44 +01:00
Add UI components, i18n, settings store and base styles
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
// Notifications éphémères (badges, XP). Région role="status" : annoncée sans voler le focus.
|
||||
|
||||
import { el } from './dom.js';
|
||||
|
||||
const DISPLAY_MS = 7000;
|
||||
|
||||
export class BadgeToast {
|
||||
#i18n;
|
||||
#root;
|
||||
|
||||
constructor(i18n) {
|
||||
this.#i18n = i18n;
|
||||
this.#root = el('div', { class: 'toast-region', role: 'status', 'aria-live': 'polite' });
|
||||
}
|
||||
|
||||
get element() {
|
||||
return this.#root;
|
||||
}
|
||||
|
||||
/** Affiche un message ; se ferme seul après quelques secondes ou au clic sur « Fermer ». */
|
||||
show(message) {
|
||||
const toast = el(
|
||||
'div',
|
||||
{ class: 'toast' },
|
||||
el('span', { text: message }),
|
||||
el('button', { type: 'button', class: 'btn', text: this.#i18n.t('toast.close'), onclick: () => toast.remove() }),
|
||||
);
|
||||
this.#root.append(toast);
|
||||
setTimeout(() => toast.remove(), DISPLAY_MS);
|
||||
}
|
||||
|
||||
showBadge(badgeId) {
|
||||
this.show(this.#i18n.t('badge.earned', { name: this.#i18n.t(`badge.${badgeId}`) }));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user