Neale Pickett
·
2024-12-20
toast.mjs
1const Millisecond = 1
2const Second = 1000 * Millisecond
3
4/**
5 * Display a transient message to the user.
6 *
7 * @param {String} message Message to display
8 * @param {Number} timeout How long before removing this message
9 */
10function Toast(message, timeout=5*Second) {
11 console.info(message)
12 for (let toasts of document.querySelectorAll(".toasts")) {
13 let p = toasts.appendChild(document.createElement("p"))
14 p.classList.add("toast")
15 p.textContent = message
16 setTimeout(() => p.remove(), timeout)
17 }
18}
19
20export {
21 Toast,
22}