Skip to content

Commit

Permalink
Modal: Improve styling of ConfirmationModal
Browse files Browse the repository at this point in the history
  • Loading branch information
liamcain committed Oct 25, 2023
1 parent aa03d6c commit 0b51839
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,35 @@ interface IConfirmationDialogParams {
export class ConfirmationModal extends Modal {
private config: IConfirmationDialogParams;
private accepted: boolean;
private buttonContainerEl: HTMLElement;

constructor(app: App, config: IConfirmationDialogParams) {
super(app);
this.config = config;

const { cta, onAccept, text, title } = config;

this.contentEl.createEl("h2", { text: title });
this.contentEl.createEl("p", { text });
this.contentEl
.createEl("button", { text: "Never mind" })
.addEventListener("click", () => {
this.close();
});
this.containerEl.addClass('mod-confirmation');
this.titleEl.setText(title);
this.contentEl.setText(text);

this.buttonContainerEl = this.modalEl.createDiv('modal-button-container');

const acceptBtnEl = this.buttonContainerEl.createEl("button", {
cls: "mod-cta",
text: cta,
});
acceptBtnEl.addEventListener("click", async (e) => {
e.preventDefault();
this.accepted = true;
this.close();
onAccept(e);
});

this.contentEl
.createEl("button", {
cls: "mod-cta",
text: cta,
})
.addEventListener("click", async (e) => {
this.accepted = true;
const cancelBtnEl = this.buttonContainerEl.createEl("button", { text: "Never mind" });
cancelBtnEl.addEventListener("click", e => {
e.preventDefault();
this.close();
setTimeout(() => onAccept(e), 20);
});
}

Expand Down

0 comments on commit 0b51839

Please sign in to comment.