Skip to content

Commit

Permalink
Make startOpening/Closing abstract
Browse files Browse the repository at this point in the history
  • Loading branch information
m-akinc committed Feb 22, 2024
1 parent 2c8a82f commit 90d4cc7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
8 changes: 8 additions & 0 deletions packages/nimble-components/src/dialog/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ export class Dialog<CloseReason = void> extends Modal<CloseReason> {
): void {
this.footerIsEmpty = !next?.length;
}

protected override startOpening(): void {
this.finishOpening();
}

protected override startClosing(reason: CloseReason | UserDismissed): void {
this.finishClosing(reason);
}
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
Expand Down
2 changes: 1 addition & 1 deletion packages/nimble-components/src/drawer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class Drawer<CloseReason = void> extends Modal<CloseReason> {
}

protected override startOpening(): void {
super.startOpening();
this.finishOpening(); // has to be open before we can animate it
this.triggerAnimation();
}

Expand Down
12 changes: 2 additions & 10 deletions packages/nimble-components/src/modal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,15 @@ export abstract class Modal<CloseReason = void> extends FoundationElement {
}
}

// Derived classes can override this, but should not call it directly (except from the override).
protected startOpening(): void {
this.finishOpening();
}
protected abstract startOpening(): void;

// Overrides must call the base implementation, so that state gets updated.
protected finishOpening(): void {
this.state = ModalState.open;
this.dialogElement.showModal();
}

// Derived classes can override this, but should not call it directly (except from the override).
protected startClosing(reason: CloseReason | UserDismissed): void {
this.finishClosing(reason);
}
protected abstract startClosing(reason: CloseReason | UserDismissed): void;

// Overrides must call the base implementation, so that state gets updated.
protected finishClosing(reason: CloseReason | UserDismissed): void {
this.state = ModalState.closed;
this.dialogElement.close();
Expand Down

0 comments on commit 90d4cc7

Please sign in to comment.