Modal · dialogs

Dialogs that rise in and sink out, stack when one opens another, scroll their body under a fixed header and footer, refuse to close when they must, guard unsaved changes — and promise-based confirm, alert and prompt.

A dialog · sizes

Confirm · alert · prompt — they return promises

Stacked · scrolling · must choose · unsaved changes

Usage

JavaScript
import { signal } from "./index.js";import { Modal } from "./components/modal.js";import { confirmDialog, alertDialog, promptDialog, ConfirmHost } from "./components/confirm.js"; const open = signal(false);Modal({ open, title: "Subscribe", description: "One email a month.", size: "sm" | "md" | "lg" | "xl" | "full",  children: html`…`, footer: html`${Button({ label: "Subscribe", onClick: () => open.set(false) })}` }) // no way out but the buttons (the backdrop and Esc make it nod)Modal({ open, closable: false, variant: "alert", icon: true, tone: "warning", title: "…" })// keep it open while there are unsaved changesModal({ open, beforeClose: () => !dirty() || confirmDialog("Discard changes?", { tone: "danger" }) }) // promise dialogs — render ConfirmHost() once, next to Toaster()if (await confirmDialog("3 files will be deleted.", { tone: "danger", okLabel: "Delete" })) …await confirmDialog("…", { requireText: "kartex" })                 // type the name to enable itawait confirmDialog("…", { onConfirm: () => api.publish() })        // the button spins until it's doneawait alertDialog("Export complete", { tone: "success" })const name = await promptDialog("Rename file", { defaultValue, validate: (v) => !v && "Required" })