Écrans : onboarding, accueil, séance guidée, minuteur, historique
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
ba08daaa89
commit
af92c021e2
@@ -0,0 +1,51 @@
|
||||
// Retours à l'utilisateur : message bref (toast) et demande de confirmation.
|
||||
|
||||
import { h } from "./dom.js";
|
||||
|
||||
/** @type {HTMLElement|null} */
|
||||
let toastNode = null;
|
||||
/** @type {ReturnType<typeof setTimeout>|null} */
|
||||
let toastTimer = null;
|
||||
|
||||
/**
|
||||
* Message bref en bas de l'écran, lu par les lecteurs d'écran.
|
||||
* @param {string} message
|
||||
*/
|
||||
export function toast(message) {
|
||||
if (!toastNode) {
|
||||
toastNode = h("div", { class: "toast", role: "status", "aria-live": "polite" });
|
||||
document.body.append(toastNode);
|
||||
}
|
||||
toastNode.textContent = message;
|
||||
toastNode.classList.add("toast--on");
|
||||
if (toastTimer) clearTimeout(toastTimer);
|
||||
toastTimer = setTimeout(() => toastNode?.classList.remove("toast--on"), 3500);
|
||||
}
|
||||
|
||||
/**
|
||||
* Demande de confirmation dans une boîte de dialogue native (<dialog>).
|
||||
* @param {{title: string, lines?: string[], confirm: string, cancel?: string, danger?: boolean}} options
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
export function confirmDialog({ title, lines = [], confirm, cancel = "Annuler", danger = false }) {
|
||||
return new Promise((resolve) => {
|
||||
const yes = h("button", { type: "button", class: `btn btn--block ${danger ? "btn--danger" : "btn--primary"}` }, confirm);
|
||||
const no = h("button", { type: "button", class: "btn btn--block btn--ghost" }, cancel);
|
||||
const dialog = h("dialog", { class: "dialog", "aria-labelledby": "dialog-title" },
|
||||
h("h2", { class: "dialog__title", id: "dialog-title" }, title),
|
||||
lines.map((l) => h("p", { class: "dialog__text" }, l)),
|
||||
h("div", { class: "dialog__actions" }, yes, no));
|
||||
/** @param {boolean} answer */
|
||||
const done = (answer) => {
|
||||
dialog.close();
|
||||
dialog.remove();
|
||||
resolve(answer);
|
||||
};
|
||||
yes.addEventListener("click", () => done(true));
|
||||
no.addEventListener("click", () => done(false));
|
||||
dialog.addEventListener("cancel", (e) => { e.preventDefault(); done(false); });
|
||||
document.body.append(dialog);
|
||||
dialog.showModal();
|
||||
no.focus();
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user