Skip to content

Commit

Permalink
[CL-319] custom back action in popup header component (#9829)
Browse files Browse the repository at this point in the history
* expose FunctionReturningAwaitable from CL lib

* expose backAction as input on popup header component
  • Loading branch information
willmartian authored Jun 25, 2024
1 parent 00801f9 commit 8df054c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*ngIf="showBackButton"
[title]="'back' | i18n"
[ariaLabel]="'back' | i18n"
(click)="back()"
[bitAction]="backAction"
></button>
<h1 bitTypography="h3" class="!tw-mb-0.5 tw-text-headers">{{ pageTitle }}</h1>
</div>
Expand Down
23 changes: 17 additions & 6 deletions apps/browser/src/platform/popup/layout/popup-header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ import { CommonModule, Location } from "@angular/common";
import { Component, Input } from "@angular/core";

import { JslibModule } from "@bitwarden/angular/jslib.module";
import { IconButtonModule, TypographyModule } from "@bitwarden/components";
import {
AsyncActionsModule,
FunctionReturningAwaitable,
IconButtonModule,
TypographyModule,
} from "@bitwarden/components";

@Component({
selector: "popup-header",
templateUrl: "popup-header.component.html",
standalone: true,
imports: [TypographyModule, CommonModule, IconButtonModule, JslibModule],
imports: [TypographyModule, CommonModule, IconButtonModule, JslibModule, AsyncActionsModule],
})
export class PopupHeaderComponent {
/** Display the back button, which uses Location.back() to go back one page in history */
Expand All @@ -26,9 +31,15 @@ export class PopupHeaderComponent {
/** Title string that will be inserted as an h1 */
@Input({ required: true }) pageTitle: string;

constructor(private location: Location) {}

back() {
/**
* Async action that occurs when clicking the back button
*
* If unset, will call `location.back()`
**/
@Input()
backAction: FunctionReturningAwaitable = async () => {
this.location.back();
}
};

constructor(private location: Location) {}
}
2 changes: 1 addition & 1 deletion libs/components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ export * from "./tabs";
export * from "./toast";
export * from "./toggle-group";
export * from "./typography";
export * from "./utils/i18n-mock.service";
export * from "./utils";
2 changes: 2 additions & 0 deletions libs/components/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./function-to-observable";
export * from "./i18n-mock.service";

0 comments on commit 8df054c

Please sign in to comment.