// hive-toast.js — , one transient notification entry // (constructed by `themedToast` in modal.js). Owns its own auto-dismiss // timer via connectedCallback/disconnectedCallback (cleared on removal so // a toast dismissed early by click doesn't leave a stray timer), rather // than a closure-captured timer handle. Callers set `._message`/`._opts` // before append — same reason as ``. The element itself is // the visible toast box (`:host` carries the styling, `:host(.error)` etc. // switch on a plain class the host carries) — the message text renders // directly in the shadow root rather than via a ``, since there's no // external light-DOM content to project. import { attachShadowCss } from "../shadow-css.js"; import toastCss from "./hive-toast.css"; class HiveToast extends HTMLElement { connectedCallback() { const { type = "info", duration } = this._opts || {}; const ms = duration != null ? duration : type === "error" ? 8000 : 4000; const root = attachShadowCss(this, toastCss); this.classList.add(type); this.setAttribute("role", type === "error" ? "alert" : "status"); root.textContent = this._message || ""; let removed = false; this._remove = () => { if (removed) return; removed = true; this.classList.add("out"); setTimeout(() => this.remove(), 200); }; this.addEventListener("click", this._remove); if (ms > 0) this._timer = setTimeout(this._remove, ms); } disconnectedCallback() { clearTimeout(this._timer); } } customElements.define("hive-toast", HiveToast);