import { App, Modal, Setting } from "obsidian";
export class ConfirmationModal extends Modal {
title: string;
message: string;
onConfirm: () => void;
onCancel: () => void;
constructor(app: App, title: string, message: string, onConfirm: () => void, onCancel: () => void) {
super(app);
this.title = title;
this.message = message;
this.onConfirm = onConfirm;
this.onCancel = onCancel;
}
onOpen() {
const { contentEl } = this;
contentEl.createEl("h2", { text: this.title });
contentEl.createEl("p", { text: this.message });
new Setting(contentEl)
.addButton((btn) =>
btn
.setButtonText("Cancel")
.onClick(() => {
this.onCancel();
this.close();
})
)
.addButton((btn) =>
btn
.setButtonText("Confirm")
.setCta()
.onClick(() => {
this.onConfirm();
this.close();
})
);
}
onClose() {
const { contentEl } = this;
contentEl.empty();
}
}