Open Merge and Discard confirmations beside their buttons
This commit is contained in:
Vendored
+9
-3
@@ -42,9 +42,15 @@ export function ago(iso) {
|
||||
export function errorText(err) {
|
||||
return err instanceof Error ? err.message : String(err);
|
||||
}
|
||||
function modal(text, buttons) {
|
||||
function modal(text, buttons, anchor = null) {
|
||||
const actions = buttons.map((b) => h("button", { type: "submit", value: b.value, class: b.class ?? "" }, b.label));
|
||||
const dialog = h("dialog", { class: "modal" }, h("form", { method: "dialog" }, h("p", { class: "modal-text" }, text), h("div", { class: "modal-actions" }, ...actions)));
|
||||
if (anchor) {
|
||||
const rect = anchor.getBoundingClientRect();
|
||||
dialog.classList.add("anchored");
|
||||
dialog.style.top = `${rect.bottom + 4}px`;
|
||||
dialog.style.right = `${document.documentElement.clientWidth - rect.right}px`;
|
||||
}
|
||||
document.body.append(dialog);
|
||||
return new Promise((resolve) => {
|
||||
dialog.onclose = () => {
|
||||
@@ -79,11 +85,11 @@ export function openPanel(title, mount) {
|
||||
export async function showAlert(text) {
|
||||
await modal(text, [{ label: "OK", value: "ok", class: "primary" }]);
|
||||
}
|
||||
export async function showConfirm(text, action, danger = false) {
|
||||
export async function showConfirm(text, action, danger = false, anchor = null) {
|
||||
const value = await modal(text, [
|
||||
{ label: "Cancel", value: "cancel" },
|
||||
{ label: action, value: "ok", class: danger ? "danger-primary" : "primary" },
|
||||
]);
|
||||
], anchor);
|
||||
return value === "ok";
|
||||
}
|
||||
//# sourceMappingURL=dom.js.map
|
||||
Reference in New Issue
Block a user