mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-08 01:28:15 -07:00
18 lines
483 B
JavaScript
18 lines
483 B
JavaScript
/** @param {MouseEvent} event */
|
|
function closeOnBackdrop(event) {
|
|
const dialog = /** @type {HTMLDialogElement} */ (event.currentTarget);
|
|
|
|
if (event.target === dialog) dialog.close();
|
|
}
|
|
|
|
/**
|
|
* @param {HTMLDialogElement} dialog
|
|
* @param {HTMLElement} host
|
|
*/
|
|
export function openDialog(dialog, host) {
|
|
host.append(dialog);
|
|
dialog.addEventListener("close", () => dialog.remove(), { once: true });
|
|
dialog.addEventListener("click", closeOnBackdrop);
|
|
dialog.showModal();
|
|
}
|