mirror of
https://github.com/bitwarden/clients.git
synced 2026-11-16 07:03:29 +00:00
[CL-1236] Extension header changes (#22484)
This commit is contained in:
@@ -7,8 +7,8 @@ import type { Preview } from "@storybook/angular";
|
||||
import {
|
||||
featureFlagDecorator,
|
||||
FEATURE_FLAG_CATALOG,
|
||||
FEATURE_FLAGS_CATALOG_GLOBAL,
|
||||
FEATURE_FLAGS_GLOBAL,
|
||||
FEATURE_FLAGS_PARAM,
|
||||
} from "@bitwarden/storybook";
|
||||
|
||||
import docJson from "../documentation.json";
|
||||
@@ -66,13 +66,14 @@ const preview: Preview = {
|
||||
backgrounds: {
|
||||
disabled: true,
|
||||
},
|
||||
// Published here (the preview can read the enum) so the manager's Feature
|
||||
// Flags panel can render the catalog without importing `@bitwarden/*`.
|
||||
// A parameter rather than a global: parameters are never diffed or written
|
||||
// to the URL, so this array survives the boundary intact.
|
||||
[FEATURE_FLAGS_PARAM]: { catalog: FEATURE_FLAG_CATALOG },
|
||||
},
|
||||
initialGlobals: {
|
||||
[FEATURE_FLAGS_GLOBAL]: [],
|
||||
// Seeded here (preview can read the enum) so the manager panel can read the
|
||||
// catalog from globals without importing `@bitwarden/*`. Unchanged globals
|
||||
// stay out of the URL, so this large value never bloats story links.
|
||||
[FEATURE_FLAGS_CATALOG_GLOBAL]: FEATURE_FLAG_CATALOG,
|
||||
},
|
||||
tags: ["autodocs"],
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<div class="tw-me-2 tw-mt-1">
|
||||
<div [class]="wrapperClasses()">
|
||||
<button
|
||||
*ngIf="currentAccount$ | async as currentAccount; else defaultButton"
|
||||
type="button"
|
||||
@@ -6,10 +6,12 @@
|
||||
(click)="currentAccountClicked()"
|
||||
>
|
||||
<span class="tw-sr-only"> {{ "bitwardenAccount" | i18n }} {{ currentAccount.email }}</span>
|
||||
<!-- TODO: remove size binding and lock to "sm" when VFO1Foundation flag is removed -->
|
||||
<bit-avatar
|
||||
[id]="currentAccount.id"
|
||||
[text]="currentAccount.name"
|
||||
[color]="currentAccount.avatarColor"
|
||||
[size]="vfo1Enabled() ? 'sm' : 'base'"
|
||||
aria-hidden="true"
|
||||
></bit-avatar>
|
||||
</button>
|
||||
@@ -20,9 +22,11 @@
|
||||
class="tw-rounded-full hover:tw-outline hover:tw-outline-1 hover:tw-outline-offset-1"
|
||||
>
|
||||
<span class="tw-sr-only">{{ "switchAccounts" | i18n }}</span>
|
||||
<!-- TODO: remove size binding and lock to "sm" when VFO1Foundation flag is removed -->
|
||||
<bit-avatar
|
||||
[text]="'…'"
|
||||
[color]="'#6795E8'"
|
||||
[size]="vfo1Enabled() ? 'sm' : 'base'"
|
||||
aria-hidden="true"
|
||||
class="[&>img]:tw-block"
|
||||
></bit-avatar>
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
// FIXME: Update this file to be type safe and remove this and next line
|
||||
// @ts-strict-ignore
|
||||
import { CommonModule, Location } from "@angular/common";
|
||||
import { Component } from "@angular/core";
|
||||
import { Component, computed, inject } from "@angular/core";
|
||||
import { toSignal } from "@angular/core/rxjs-interop";
|
||||
import { ActivatedRoute, Router, RouterModule } from "@angular/router";
|
||||
import { Observable, combineLatest, switchMap } from "rxjs";
|
||||
import { Observable, combineLatest, of, switchMap } from "rxjs";
|
||||
|
||||
import { JslibModule } from "@bitwarden/angular/jslib.module";
|
||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
||||
import { AvatarService } from "@bitwarden/common/auth/abstractions/avatar.service";
|
||||
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
|
||||
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||
import { UserId } from "@bitwarden/common/types/guid";
|
||||
import { AvatarModule } from "@bitwarden/components";
|
||||
|
||||
@@ -31,6 +34,28 @@ export type CurrentAccount = {
|
||||
export class CurrentAccountComponent {
|
||||
currentAccount$: Observable<CurrentAccount>;
|
||||
|
||||
/**
|
||||
* TODO: remove with the VFO1Foundation flag.
|
||||
*
|
||||
* Optional so that reading the flag doesn't force a `ConfigService` stub into every spec that
|
||||
* renders a page header. Always present in the running extension.
|
||||
*/
|
||||
private readonly configService = inject(ConfigService, { optional: true });
|
||||
|
||||
/** TODO: remove with the VFO1Foundation flag. */
|
||||
protected readonly vfo1Enabled = toSignal(
|
||||
this.configService?.getFeatureFlag$(FeatureFlag.VFO1Foundation) ?? of(false),
|
||||
{ initialValue: false },
|
||||
);
|
||||
|
||||
/**
|
||||
* TODO: remove with the VFO1Foundation flag, along with the `[class]` binding it feeds.
|
||||
*
|
||||
* The legacy header under-pads its trailing edge for icon buttons; the avatar isn't one, so it
|
||||
* offsets itself. The app bar pads and centers the row itself.
|
||||
*/
|
||||
protected readonly wrapperClasses = computed(() => (this.vfo1Enabled() ? "" : "tw-me-2 tw-mt-1"));
|
||||
|
||||
constructor(
|
||||
private accountService: AccountService,
|
||||
private avatarService: AvatarService,
|
||||
|
||||
@@ -5,11 +5,17 @@
|
||||
></bit-svg>
|
||||
|
||||
<popup-page class="tw-relative tw-z-10 [&_main]:!tw-bg-transparent" [disablePadding]="true">
|
||||
<!-- The page titles itself in its own content, so the title bar would be empty. -->
|
||||
<popup-header
|
||||
slot="header"
|
||||
hideTitleBar
|
||||
background="alt"
|
||||
pageTitle=""
|
||||
class="[&_header]:!tw-bg-transparent [&_header]:!tw-px-6 bit-compact:[&_header]:!tw-px-3"
|
||||
[class]="
|
||||
vfo1Enabled()
|
||||
? ''
|
||||
: '[&_header]:!tw-bg-transparent [&_header]:!tw-px-6 bit-compact:[&_header]:!tw-px-3'
|
||||
"
|
||||
>
|
||||
<div class="tw-w-32">
|
||||
<bit-svg [content]="logo" [ariaLabel]="'appLogoLabel' | i18n"></bit-svg>
|
||||
|
||||
@@ -5,6 +5,7 @@ import { mock, MockProxy } from "jest-mock-extended";
|
||||
import { of } from "rxjs";
|
||||
|
||||
import { AbstractThemingService } from "@bitwarden/angular/platform/services/theming/theming.service.abstraction";
|
||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||
import { ThemeTypes } from "@bitwarden/common/platform/enums";
|
||||
import { DialogService } from "@bitwarden/components";
|
||||
|
||||
@@ -100,6 +101,7 @@ describe("DefaultPasswordManagerPromptComponent", () => {
|
||||
provide: AbstractThemingService,
|
||||
useValue: { theme$: of(ThemeTypes.Light) },
|
||||
},
|
||||
{ provide: ConfigService, useValue: { getFeatureFlag$: () => of(false) } },
|
||||
],
|
||||
})
|
||||
.overrideComponent(DefaultPasswordManagerPromptComponent, {
|
||||
|
||||
@@ -13,6 +13,8 @@ import { firstValueFrom, map } from "rxjs";
|
||||
import { AbstractThemingService } from "@bitwarden/angular/platform/services/theming/theming.service.abstraction";
|
||||
import { BitwardenLogo } from "@bitwarden/assets/svg";
|
||||
import { BrowserClientVendors } from "@bitwarden/common/autofill/constants";
|
||||
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||
import { ThemeTypes } from "@bitwarden/common/platform/enums";
|
||||
import {
|
||||
BaseCardComponent,
|
||||
@@ -69,6 +71,7 @@ export class DefaultPasswordManagerPromptComponent implements OnInit {
|
||||
);
|
||||
private readonly introCarouselService = inject(IntroCarouselService);
|
||||
private readonly autofillBrowserSettingsService = inject(AutofillBrowserSettingsService);
|
||||
private readonly configService = inject(ConfigService);
|
||||
|
||||
private readonly privacyPermissionIsGranted = signal(false);
|
||||
|
||||
@@ -77,6 +80,17 @@ export class DefaultPasswordManagerPromptComponent implements OnInit {
|
||||
{ initialValue: false },
|
||||
);
|
||||
|
||||
/**
|
||||
* TODO: remove with the VFO1Foundation flag, along with the header class override it gates.
|
||||
*
|
||||
* The two-bar header paints and pads its own bars, so the `[&_header]:` overrides that reach into
|
||||
* the one-bar header have nothing to correct there.
|
||||
*/
|
||||
protected readonly vfo1Enabled = toSignal(
|
||||
this.configService.getFeatureFlag$(FeatureFlag.VFO1Foundation),
|
||||
{ initialValue: false },
|
||||
);
|
||||
|
||||
protected readonly logo = BitwardenLogo;
|
||||
protected readonly backgroundIllustration = computed(() =>
|
||||
this.isDarkTheme() ? DefaultPasswordBackgroundDark : DefaultPasswordBackgroundLight,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
bitIconButton="bwi-popout"
|
||||
size="small"
|
||||
type="button"
|
||||
[buttonType]="buttonType()"
|
||||
label="{{ 'popOutNewWindow' | i18n }}"
|
||||
[title]="'popOutNewWindow' | i18n"
|
||||
(click)="expand()"
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import { CommonModule } from "@angular/common";
|
||||
import { Component, Input, OnInit } from "@angular/core";
|
||||
import { Component, Input, OnInit, computed, inject } from "@angular/core";
|
||||
import { toSignal } from "@angular/core/rxjs-interop";
|
||||
import { of } from "rxjs";
|
||||
|
||||
import { JslibModule } from "@bitwarden/angular/jslib.module";
|
||||
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||
import { IconButtonModule } from "@bitwarden/components";
|
||||
import { ButtonType, IconButtonModule } from "@bitwarden/components";
|
||||
|
||||
import BrowserPopupUtils from "../../browser/browser-popup-utils";
|
||||
|
||||
@@ -19,6 +23,28 @@ export class PopOutComponent implements OnInit {
|
||||
// eslint-disable-next-line @angular-eslint/prefer-signals
|
||||
@Input() show = true;
|
||||
|
||||
/**
|
||||
* TODO: remove with the VFO1Foundation flag.
|
||||
*
|
||||
* Optional so that reading the flag doesn't force a `ConfigService` stub into every spec that
|
||||
* renders a page header. Always present in the running extension.
|
||||
*/
|
||||
private readonly configService = inject(ConfigService, { optional: true });
|
||||
|
||||
/** TODO: remove with the VFO1Foundation flag. */
|
||||
private readonly vfo1Enabled = toSignal(
|
||||
this.configService?.getFeatureFlag$(FeatureFlag.VFO1Foundation) ?? of(false),
|
||||
{ initialValue: false },
|
||||
);
|
||||
|
||||
/**
|
||||
* Every usage projects into the header's `end` slot, which the flag moves onto the dark app bar.
|
||||
* Only `side-nav` is legible against that background.
|
||||
*/
|
||||
protected readonly buttonType = computed<ButtonType>(() =>
|
||||
this.vfo1Enabled() ? "side-nav" : "primaryGhost",
|
||||
);
|
||||
|
||||
constructor(private platformUtilsService: PlatformUtilsService) {}
|
||||
|
||||
async ngOnInit() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<footer
|
||||
class="tw-p-3 bit-compact:tw-p-2 tw-border-0 tw-border-solid tw-border-t tw-border-secondary-300 tw-bg-background"
|
||||
class="tw-p-3 bit-compact:tw-p-2 tw-border-0 tw-border-solid tw-border-t tw-border-border-base tw-bg-background"
|
||||
>
|
||||
<div class="tw-max-w-screen-sm tw-mx-auto tw-flex tw-justify-between tw-w-full tw-items-center">
|
||||
<div class="tw-flex tw-justify-start tw-gap-2">
|
||||
|
||||
@@ -1,34 +1,99 @@
|
||||
<!--
|
||||
end padding is less than start padding to prioritize visual alignment when icon buttons are used at the end of the end slot.
|
||||
other elements used at the end of the end slot may need to add their own margin/padding to achieve visual alignment.
|
||||
<!--
|
||||
`end` is the trailing edge of the topmost bar, so it renders into the app bar when that bar exists
|
||||
and into the title bar otherwise. Declaring the slot once and rendering the template into whichever
|
||||
branch is live is the only way to move it: a `select` repeated across both branches would bind all
|
||||
matching content to whichever copy comes first, leaving the other empty.
|
||||
-->
|
||||
<header
|
||||
class="tw-py-3 bit-compact:tw-py-2 tw-pe-1 bit-compact:tw-pe-0.5 tw-transition-colors tw-duration-200 tw-border-0 tw-border-b tw-border-solid"
|
||||
[ngClass]="{
|
||||
'tw-bg-background-alt tw-border-transparent':
|
||||
this.background === 'alt' && !pageContentScrolled(),
|
||||
'tw-bg-background tw-border-secondary-300':
|
||||
(this.background === 'alt' && pageContentScrolled()) || this.background === 'default',
|
||||
'tw-ps-4 bit-compact:tw-ps-3': !showBackButton,
|
||||
'tw-ps-1 bit-compact:tw-ps-0': showBackButton,
|
||||
}"
|
||||
>
|
||||
<div class="tw-max-w-screen-sm tw-mx-auto tw-flex tw-justify-between tw-w-full">
|
||||
<div class="tw-inline-flex tw-items-center tw-gap-2 tw-h-9">
|
||||
<button
|
||||
bitIconButton="bwi-angle-left"
|
||||
type="button"
|
||||
*ngIf="showBackButton"
|
||||
[label]="'back' | i18n"
|
||||
[bitAction]="backAction"
|
||||
></button>
|
||||
<h1 *ngIf="pageTitle" bitTypography="h3" class="!tw-mb-0.5">
|
||||
{{ pageTitle }}
|
||||
</h1>
|
||||
<ng-content></ng-content>
|
||||
<ng-template #endSlot>
|
||||
<ng-content select="[slot=end]"></ng-content>
|
||||
</ng-template>
|
||||
|
||||
<!-- Declared once and rendered into whichever bar is live, same as `endSlot` above. -->
|
||||
<ng-template #backButtonSlot>
|
||||
@if (showBackButton()) {
|
||||
<button
|
||||
bitIconButton="bwi-angle-left"
|
||||
type="button"
|
||||
[buttonType]="backButtonType()"
|
||||
[label]="'back' | i18n"
|
||||
[bitAction]="backAction()"
|
||||
[size]="vfo1Enabled() ? 'small' : 'default'"
|
||||
></button>
|
||||
}
|
||||
</ng-template>
|
||||
|
||||
<!--
|
||||
One `header` around both bars, so the banner landmark covers the whole region. The bars themselves
|
||||
are plain containers: the app bar is chrome belonging to the extension, the title bar belongs to the
|
||||
page, and neither is a landmark on its own.
|
||||
-->
|
||||
<header [class]="headerClasses()">
|
||||
@if (vfo1Enabled()) {
|
||||
<div
|
||||
data-testid="app-bar"
|
||||
class="tw-bg-bg-nav tw-text-fg-nav tw-py-2 bit-compact:tw-py-1.5 tw-px-4 bit-compact:tw-px-3"
|
||||
>
|
||||
<div
|
||||
class="tw-max-w-screen-sm tw-mx-auto tw-flex tw-w-full tw-items-center tw-justify-between tw-gap-2"
|
||||
>
|
||||
<div class="tw-inline-flex tw-items-center tw-gap-2">
|
||||
@if (titleBarSuppressed()) {
|
||||
<ng-container *ngTemplateOutlet="backButtonSlot"></ng-container>
|
||||
}
|
||||
<bit-svg
|
||||
class="tw-block tw-w-[120px] [&_path]:tw-fill-fg-nav"
|
||||
[content]="logo"
|
||||
[ariaLabel]="'appLogoLabel' | i18n"
|
||||
></bit-svg>
|
||||
</div>
|
||||
<div class="tw-inline-flex tw-items-center tw-gap-2">
|
||||
<ng-container *ngTemplateOutlet="endSlot"></ng-container>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tw-inline-flex tw-items-center tw-gap-2 tw-h-9">
|
||||
<ng-content select="[slot=end]"></ng-content>
|
||||
}
|
||||
|
||||
<div data-testid="title-bar" [attr.data-state]="titleBarState()" [class]="titleBarClasses()">
|
||||
<!-- `tw-min-h-0` lets the grid row shrink past this row's content height as the bar collapses. -->
|
||||
<div class="tw-max-w-screen-sm tw-mx-auto tw-flex tw-justify-between tw-w-full tw-min-h-0">
|
||||
<!--
|
||||
TODO: remove the `tw-h-9` bindings with the VFO1Foundation flag.
|
||||
The one-bar header pins its content rows to a fixed 36px; the title bar sizes to its content.
|
||||
-->
|
||||
<div class="tw-inline-flex tw-items-center tw-gap-2" [class.tw-h-9]="!vfo1Enabled()">
|
||||
@if (!titleBarSuppressed()) {
|
||||
<ng-container *ngTemplateOutlet="backButtonSlot"></ng-container>
|
||||
}
|
||||
@if (vfo1Enabled()) {
|
||||
<ng-content select="[slot=title-start]"></ng-content>
|
||||
}
|
||||
@if (pageTitle()) {
|
||||
<div class="tw-inline-flex tw-items-center tw-gap-1">
|
||||
<h1
|
||||
[bitTypography]="vfo1Enabled() ? 'h5' : 'h3'"
|
||||
[class]="vfo1Enabled() ? '!tw-mb-0' : '!tw-mb-0.5'"
|
||||
>
|
||||
{{ pageTitle() }}
|
||||
</h1>
|
||||
<ng-content select="[slot=title-suffix]"></ng-content>
|
||||
</div>
|
||||
}
|
||||
<!--
|
||||
TODO: remove with the VFO1Foundation flag.
|
||||
The app bar owns the extension's branding, so the default slot's only consumers — which
|
||||
project a Bitwarden logo — would otherwise render it twice.
|
||||
-->
|
||||
@if (!vfo1Enabled()) {
|
||||
<ng-content></ng-content>
|
||||
}
|
||||
</div>
|
||||
<div class="tw-inline-flex tw-items-center tw-gap-2" [class.tw-h-9]="!vfo1Enabled()">
|
||||
@if (vfo1Enabled()) {
|
||||
<ng-content select="[slot=title-end]"></ng-content>
|
||||
} @else {
|
||||
<ng-container *ngTemplateOutlet="endSlot"></ng-container>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
@@ -0,0 +1,365 @@
|
||||
import { ChangeDetectionStrategy, Component, ElementRef, signal } from "@angular/core";
|
||||
import { ComponentFixture, TestBed } from "@angular/core/testing";
|
||||
import { By } from "@angular/platform-browser";
|
||||
import { BehaviorSubject } from "rxjs";
|
||||
|
||||
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import {
|
||||
BitIconButtonComponent,
|
||||
I18nMockService,
|
||||
ScrollLayoutService,
|
||||
} from "@bitwarden/components";
|
||||
|
||||
import { PopupRouterCacheService } from "../view-cache/popup-router-cache.service";
|
||||
|
||||
import { PopupHeaderComponent } from "./popup-header.component";
|
||||
import { PopupPageComponent } from "./popup-page.component";
|
||||
|
||||
@Component({
|
||||
template: `
|
||||
<popup-header
|
||||
[pageTitle]="pageTitle()"
|
||||
[showBackButton]="showBackButton()"
|
||||
[hideTitleBar]="hideTitleBar()"
|
||||
>
|
||||
<span data-testid="default">Default content</span>
|
||||
<span slot="title-start" data-testid="title-start">Icon tile</span>
|
||||
<span slot="end" data-testid="end">Pop out</span>
|
||||
<span slot="title-end" data-testid="title-end">3 Sends</span>
|
||||
<span slot="title-suffix" data-testid="title-suffix">Switch vault</span>
|
||||
</popup-header>
|
||||
`,
|
||||
imports: [PopupHeaderComponent],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
class TestHostComponent {
|
||||
readonly pageTitle = signal("Send");
|
||||
readonly showBackButton = signal(false);
|
||||
readonly hideTitleBar = signal(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stands in for the scroll region that `popup-page` marks with `bitScrollLayoutHost`. jsdom reports
|
||||
* `0` for every layout measurement, so the scroll geometry has to be stubbed.
|
||||
*/
|
||||
const createScrollable = (scrollHeight = 1000, clientHeight = 500) => {
|
||||
const element = document.createElement("div");
|
||||
|
||||
Object.defineProperty(element, "scrollHeight", { value: scrollHeight, configurable: true });
|
||||
Object.defineProperty(element, "clientHeight", { value: clientHeight, configurable: true });
|
||||
|
||||
return element;
|
||||
};
|
||||
|
||||
describe("PopupHeaderComponent", () => {
|
||||
let fixture: ComponentFixture<TestHostComponent>;
|
||||
let scrollable: HTMLElement;
|
||||
const vfo1Enabled = new BehaviorSubject<boolean>(false);
|
||||
|
||||
/** The branded app bar only exists in the v2 template. */
|
||||
const appBar = () => fixture.nativeElement.querySelector("[data-testid=app-bar]");
|
||||
const titleBar = (): HTMLElement =>
|
||||
fixture.nativeElement.querySelector("[data-testid=title-bar]");
|
||||
const banners = (): HTMLElement[] => Array.from(fixture.nativeElement.querySelectorAll("header"));
|
||||
const slot = (testId: string) => fixture.nativeElement.querySelector(`[data-testid=${testId}]`);
|
||||
|
||||
/** Scrolls the region and settles the resulting signal update, which arrives a frame later. */
|
||||
const scrollTo = async (top: number) => {
|
||||
scrollable.scrollTop = top;
|
||||
scrollable.dispatchEvent(new Event("scroll"));
|
||||
|
||||
await new Promise((resolve) => requestAnimationFrame(resolve));
|
||||
fixture.detectChanges();
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
vfo1Enabled.next(false);
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [TestHostComponent],
|
||||
providers: [
|
||||
{ provide: ConfigService, useValue: { getFeatureFlag$: () => vfo1Enabled } },
|
||||
{ provide: PopupPageComponent, useValue: { isScrolled: signal(false) } },
|
||||
{ provide: PopupRouterCacheService, useValue: { back: jest.fn() } },
|
||||
{
|
||||
provide: I18nService,
|
||||
useValue: new I18nMockService({ back: "Back", appLogoLabel: "Bitwarden" }),
|
||||
},
|
||||
],
|
||||
}).compileComponents();
|
||||
|
||||
scrollable = createScrollable();
|
||||
TestBed.inject(ScrollLayoutService).scrollableRef.set(new ElementRef(scrollable));
|
||||
|
||||
fixture = TestBed.createComponent(TestHostComponent);
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
/**
|
||||
* The bars are containers, not landmarks. A second `header` would announce a second banner, and
|
||||
* moving the landmark onto a bar would lose it entirely in whichever flag state omits that bar.
|
||||
*/
|
||||
it.each([false, true])(
|
||||
"exposes one banner landmark around both bars (flag on: %s)",
|
||||
(enabled) => {
|
||||
vfo1Enabled.next(enabled);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(banners()).toHaveLength(1);
|
||||
expect(banners()[0].contains(titleBar())).toBe(true);
|
||||
|
||||
if (enabled) {
|
||||
expect(banners()[0].contains(appBar())).toBe(true);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it("reads the VFO1 flag", () => {
|
||||
const configService = TestBed.inject(ConfigService);
|
||||
const getFeatureFlag$ = jest.spyOn(configService, "getFeatureFlag$");
|
||||
|
||||
TestBed.createComponent(TestHostComponent).detectChanges();
|
||||
|
||||
expect(getFeatureFlag$).toHaveBeenCalledWith(FeatureFlag.VFO1Foundation);
|
||||
});
|
||||
|
||||
describe("when the flag is off", () => {
|
||||
it("renders a single bar with no logo", () => {
|
||||
expect(appBar()).toBeNull();
|
||||
expect(fixture.nativeElement.querySelector("bit-svg")).toBeNull();
|
||||
});
|
||||
|
||||
it("renders the title", () => {
|
||||
expect(fixture.nativeElement.querySelector("h1").textContent).toContain("Send");
|
||||
});
|
||||
|
||||
it("drops title bar content that only the v2 template renders", () => {
|
||||
expect(slot("title-end")).toBeNull();
|
||||
});
|
||||
|
||||
it("renders default content alongside the title", () => {
|
||||
expect(slot("default")).not.toBeNull();
|
||||
});
|
||||
|
||||
it("renders the end slot in the title bar, the only bar there is", () => {
|
||||
expect(titleBar().contains(slot("end"))).toBe(true);
|
||||
});
|
||||
|
||||
it("renders the title-suffix slot, which the flag does not gate", () => {
|
||||
expect(titleBar().contains(slot("title-suffix"))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when the flag is on", () => {
|
||||
beforeEach(() => {
|
||||
vfo1Enabled.next(true);
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it("renders the logo in the app bar", () => {
|
||||
expect(appBar()).not.toBeNull();
|
||||
expect(appBar().querySelector("bit-svg")).not.toBeNull();
|
||||
});
|
||||
|
||||
it("moves the end slot to the app bar", () => {
|
||||
expect(appBar().contains(slot("end"))).toBe(true);
|
||||
expect(titleBar().contains(slot("end"))).toBe(false);
|
||||
});
|
||||
|
||||
it("renders the title-start, title-end, and title-suffix slots in the title bar", () => {
|
||||
expect(titleBar().contains(slot("title-start"))).toBe(true);
|
||||
expect(titleBar().contains(slot("title-end"))).toBe(true);
|
||||
expect(titleBar().contains(slot("title-suffix"))).toBe(true);
|
||||
});
|
||||
|
||||
/**
|
||||
* Both slots have to resolve at once. Relocating `end` with a second
|
||||
* `<ng-content select="[slot=end]">` instead of a template outlet would leave one of them empty.
|
||||
*/
|
||||
it("renders the end and title-end slots simultaneously", () => {
|
||||
expect(slot("end")).not.toBeNull();
|
||||
expect(slot("title-end")).not.toBeNull();
|
||||
});
|
||||
|
||||
it("renders the title instead of default content", () => {
|
||||
expect(fixture.nativeElement.querySelector("h1").textContent).toContain("Send");
|
||||
expect(slot("default")).toBeNull();
|
||||
});
|
||||
|
||||
/**
|
||||
* The app bar owns the branding, so a page that used the default slot to project its own logo
|
||||
* would render it twice. Dropping the slot outright is what keeps that from happening.
|
||||
*/
|
||||
it("drops default content even when there is no title", () => {
|
||||
fixture.componentInstance.pageTitle.set("");
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(fixture.nativeElement.querySelector("h1")).toBeNull();
|
||||
expect(slot("default")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* The bar publishes its own state on `data-state`, so these specs never read the classes that
|
||||
* implement it. The collapse itself is CSS — a `focus-within` reveal and a transition — and jsdom
|
||||
* computes no styles, so that part is left to manual verification.
|
||||
*/
|
||||
describe("title bar visibility", () => {
|
||||
const collapsed = () => titleBar().dataset.state === "collapsed";
|
||||
|
||||
describe("when the flag is on", () => {
|
||||
beforeEach(() => {
|
||||
vfo1Enabled.next(true);
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it("shows the title bar before any scrolling", () => {
|
||||
expect(collapsed()).toBe(false);
|
||||
});
|
||||
|
||||
it("hides the title bar when scrolling down", async () => {
|
||||
await scrollTo(200);
|
||||
|
||||
expect(collapsed()).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps the app bar while the title bar collapses", async () => {
|
||||
await scrollTo(200);
|
||||
|
||||
expect(collapsed()).toBe(true);
|
||||
expect(appBar()).not.toBeNull();
|
||||
});
|
||||
|
||||
it("shows the title bar again when scrolling back up", async () => {
|
||||
await scrollTo(200);
|
||||
expect(collapsed()).toBe(true);
|
||||
|
||||
await scrollTo(150);
|
||||
|
||||
expect(collapsed()).toBe(false);
|
||||
});
|
||||
|
||||
it("shows the title bar when there is no scroll host", async () => {
|
||||
TestBed.inject(ScrollLayoutService).scrollableRef.set(null);
|
||||
|
||||
await scrollTo(200);
|
||||
|
||||
expect(collapsed()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
it("does not hide the title bar when the flag is off", async () => {
|
||||
await scrollTo(200);
|
||||
|
||||
expect(collapsed()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("back button", () => {
|
||||
it.each([false, true])("is hidden without showBackButton (flag on: %s)", (enabled) => {
|
||||
vfo1Enabled.next(enabled);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(fixture.nativeElement.querySelector("button[bitIconButton]")).toBeNull();
|
||||
});
|
||||
|
||||
it.each([false, true])("is shown with showBackButton (flag on: %s)", (enabled) => {
|
||||
vfo1Enabled.next(enabled);
|
||||
fixture.componentInstance.showBackButton.set(true);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(fixture.nativeElement.querySelector("button[bitIconButton]")).not.toBeNull();
|
||||
});
|
||||
|
||||
/** The one-bar header keeps `main`'s default button; the two-bar header sizes it down. */
|
||||
it.each<[boolean, string]>([
|
||||
[false, "default"],
|
||||
[true, "small"],
|
||||
])("sizes the button for the bar it sits in (flag on: %s)", (enabled, size) => {
|
||||
vfo1Enabled.next(enabled);
|
||||
fixture.componentInstance.showBackButton.set(true);
|
||||
fixture.detectChanges();
|
||||
|
||||
const button = fixture.debugElement
|
||||
.query(By.directive(BitIconButtonComponent))
|
||||
.injector.get(BitIconButtonComponent);
|
||||
|
||||
expect(button.size()).toBe(size);
|
||||
});
|
||||
});
|
||||
|
||||
describe("hideTitleBar", () => {
|
||||
const backButtons = (): HTMLElement[] =>
|
||||
Array.from(fixture.nativeElement.querySelectorAll("button[bitIconButton]"));
|
||||
|
||||
/** The variant asked of the component, rather than the classes it resolves that variant into. */
|
||||
const backButtonType = () =>
|
||||
fixture.debugElement
|
||||
.query(By.directive(BitIconButtonComponent))
|
||||
.injector.get(BitIconButtonComponent)
|
||||
.buttonType();
|
||||
|
||||
/**
|
||||
* The bar keeps its element so the `end` slot's projected content survives — destroying it
|
||||
* would take that content with it — so "hidden" here means hidden, not absent.
|
||||
*/
|
||||
const suppressed = () => titleBar().dataset.state === "suppressed";
|
||||
|
||||
describe("when the flag is on", () => {
|
||||
beforeEach(() => {
|
||||
vfo1Enabled.next(true);
|
||||
fixture.componentInstance.hideTitleBar.set(true);
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it("hides the title bar and keeps the app bar", () => {
|
||||
expect(suppressed()).toBe(true);
|
||||
expect(appBar()).not.toBeNull();
|
||||
expect(banners()).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("renders the back button once, in the app bar", () => {
|
||||
fixture.componentInstance.showBackButton.set(true);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(backButtons()).toHaveLength(1);
|
||||
expect(appBar().contains(backButtons()[0])).toBe(true);
|
||||
});
|
||||
|
||||
/** The default ghost styling is illegible against the app bar's nav background. */
|
||||
it("styles the back button for the nav background", () => {
|
||||
fixture.componentInstance.showBackButton.set(true);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(backButtonType()).toBe("side-nav");
|
||||
});
|
||||
|
||||
it("renders no back button without showBackButton", () => {
|
||||
expect(backButtons()).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("keeps the end slot in the app bar", () => {
|
||||
expect(appBar().contains(slot("end"))).toBe(true);
|
||||
});
|
||||
|
||||
/** `data-state` holds one value, so staying `suppressed` is also proof it never collapsed. */
|
||||
it("stays hidden through a scroll that would otherwise collapse the bar", async () => {
|
||||
await scrollTo(200);
|
||||
|
||||
expect(suppressed()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it("does nothing when the flag is off", () => {
|
||||
fixture.componentInstance.hideTitleBar.set(true);
|
||||
fixture.componentInstance.showBackButton.set(true);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(suppressed()).toBe(false);
|
||||
expect(titleBar().contains(backButtons()[0])).toBe(true);
|
||||
expect(backButtonType()).toBe("primaryGhost");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,14 +1,28 @@
|
||||
// FIXME: Update this file to be type safe and remove this and next line
|
||||
// @ts-strict-ignore
|
||||
import { BooleanInput, coerceBooleanProperty } from "@angular/cdk/coercion";
|
||||
import { CommonModule } from "@angular/common";
|
||||
import { Component, Input, Signal, inject } from "@angular/core";
|
||||
import { NgTemplateOutlet } from "@angular/common";
|
||||
import {
|
||||
ChangeDetectionStrategy,
|
||||
Component,
|
||||
booleanAttribute,
|
||||
computed,
|
||||
inject,
|
||||
input,
|
||||
linkedSignal,
|
||||
} from "@angular/core";
|
||||
import { toSignal } from "@angular/core/rxjs-interop";
|
||||
import { of } from "rxjs";
|
||||
|
||||
import { JslibModule } from "@bitwarden/angular/jslib.module";
|
||||
import { BitwardenLogo } from "@bitwarden/assets/svg";
|
||||
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||
import {
|
||||
AsyncActionsModule,
|
||||
ButtonType,
|
||||
FunctionReturningAwaitable,
|
||||
IconButtonModule,
|
||||
ScrollLayoutService,
|
||||
scrollDirection,
|
||||
SvgModule,
|
||||
TypographyModule,
|
||||
} from "@bitwarden/components";
|
||||
|
||||
@@ -16,52 +30,230 @@ import { PopupRouterCacheService } from "../view-cache/popup-router-cache.servic
|
||||
|
||||
import { PopupPageComponent } from "./popup-page.component";
|
||||
|
||||
// FIXME(https://bitwarden.atlassian.net/browse/CL-764): Migrate to OnPush
|
||||
// eslint-disable-next-line @angular-eslint/prefer-on-push-component-change-detection
|
||||
@Component({
|
||||
selector: "popup-header",
|
||||
templateUrl: "popup-header.component.html",
|
||||
imports: [TypographyModule, CommonModule, IconButtonModule, JslibModule, AsyncActionsModule],
|
||||
imports: [
|
||||
NgTemplateOutlet,
|
||||
TypographyModule,
|
||||
IconButtonModule,
|
||||
JslibModule,
|
||||
AsyncActionsModule,
|
||||
SvgModule,
|
||||
],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class PopupHeaderComponent {
|
||||
private popupRouterCacheService = inject(PopupRouterCacheService);
|
||||
// FIXME(https://bitwarden.atlassian.net/browse/CL-903): Migrate to Signals
|
||||
// eslint-disable-next-line @angular-eslint/prefer-signals
|
||||
protected pageContentScrolled: Signal<boolean> = inject(PopupPageComponent).isScrolled;
|
||||
private readonly popupRouterCacheService = inject(PopupRouterCacheService);
|
||||
private readonly scrollLayout = inject(ScrollLayoutService);
|
||||
|
||||
/** Background color */
|
||||
// FIXME(https://bitwarden.atlassian.net/browse/CL-903): Migrate to Signals
|
||||
// eslint-disable-next-line @angular-eslint/prefer-signals
|
||||
@Input()
|
||||
background: "default" | "alt" = "default";
|
||||
/**
|
||||
* TODO: remove with the VFO1Foundation flag.
|
||||
*
|
||||
* Optional so that reading the flag doesn't force a `ConfigService` stub into every spec that
|
||||
* happens to render a page header. Always present in the running extension.
|
||||
*/
|
||||
private readonly configService = inject(ConfigService, { optional: true });
|
||||
|
||||
/**
|
||||
* TODO: remove with the VFO1Foundation flag.
|
||||
*
|
||||
* Optional so that a spec can render a bare `popup-header` without standing up the page it is
|
||||
* normally projected into.
|
||||
*/
|
||||
private readonly page = inject(PopupPageComponent, { optional: true });
|
||||
|
||||
/** TODO: remove with the VFO1Foundation flag. Renders the two-bar header. */
|
||||
protected readonly vfo1Enabled = toSignal(
|
||||
this.configService?.getFeatureFlag$(FeatureFlag.VFO1Foundation) ?? of(false),
|
||||
{ initialValue: false },
|
||||
);
|
||||
|
||||
protected readonly logo = BitwardenLogo;
|
||||
|
||||
/**
|
||||
* Background treatment of the page title bar.
|
||||
*
|
||||
* - `"default"` sits on an opaque background with a bottom border
|
||||
* - `"alt"` is transparent and borderless, for pages that paint their own background
|
||||
*/
|
||||
readonly background = input<"default" | "alt">("default");
|
||||
|
||||
/** Display the back button, which uses Location.back() to go back one page in history */
|
||||
// FIXME(https://bitwarden.atlassian.net/browse/CL-903): Migrate to Signals
|
||||
// eslint-disable-next-line @angular-eslint/prefer-signals
|
||||
@Input()
|
||||
get showBackButton() {
|
||||
return this._showBackButton;
|
||||
}
|
||||
set showBackButton(value: BooleanInput) {
|
||||
this._showBackButton = coerceBooleanProperty(value);
|
||||
}
|
||||
readonly showBackButton = input(false, { transform: booleanAttribute });
|
||||
|
||||
private _showBackButton = false;
|
||||
/**
|
||||
* Hide the page title bar for pages that title themselves in their own content. The back button
|
||||
* moves into the app bar. VFO1 only — the one-bar header has no bar to fall back to.
|
||||
*/
|
||||
readonly hideTitleBar = input(false, { transform: booleanAttribute });
|
||||
|
||||
/** Title string that will be inserted as an h1 */
|
||||
// FIXME(https://bitwarden.atlassian.net/browse/CL-903): Migrate to Signals
|
||||
// eslint-disable-next-line @angular-eslint/prefer-signals
|
||||
@Input({ required: true }) pageTitle: string;
|
||||
readonly pageTitle = input.required<string>();
|
||||
|
||||
/**
|
||||
* Async action that occurs when clicking the back button
|
||||
*
|
||||
* If unset, will call `location.back()`
|
||||
**/
|
||||
// FIXME(https://bitwarden.atlassian.net/browse/CL-903): Migrate to Signals
|
||||
// eslint-disable-next-line @angular-eslint/prefer-signals
|
||||
@Input()
|
||||
backAction: FunctionReturningAwaitable = async () => {
|
||||
readonly backAction = input<FunctionReturningAwaitable>(async () => {
|
||||
return this.popupRouterCacheService.back();
|
||||
};
|
||||
});
|
||||
|
||||
/**
|
||||
* The popup viewport is short, so the title bar gets out of the way while the user reads down the
|
||||
* page. The app bar stays pinned.
|
||||
*/
|
||||
private readonly scrollDirection = scrollDirection(this.scrollLayout.scrollableRef);
|
||||
|
||||
/**
|
||||
* TODO: remove with the VFO1Foundation flag. Grows a border under an `alt` bar once the page
|
||||
* moves.
|
||||
*/
|
||||
private readonly pageScrolled = computed(() => this.page?.isScrolled() ?? false);
|
||||
|
||||
/** The title bar is gone for the life of the page, so the back button moves to the app bar. */
|
||||
protected readonly titleBarSuppressed = computed(() => this.vfo1Enabled() && this.hideTitleBar());
|
||||
|
||||
/** The app bar sits on the nav background, which only `side-nav` is legible against. */
|
||||
protected readonly backButtonType = computed<ButtonType>(() =>
|
||||
this.titleBarSuppressed() ? "side-nav" : "primaryGhost",
|
||||
);
|
||||
|
||||
/** Collapsed by scroll, unlike `titleBarSuppressed` — the bar is still there and focusable. */
|
||||
protected readonly titleBarHidden = computed(
|
||||
() => this.vfo1Enabled() && !this.hideTitleBar() && this.scrollDirection() === "down",
|
||||
);
|
||||
|
||||
/**
|
||||
* The bar's own account of where it is, published on `data-state` so anything watching the bar
|
||||
* reads the state rather than inferring it from the classes that happen to implement it.
|
||||
*/
|
||||
protected readonly titleBarState = computed(() => {
|
||||
if (this.titleBarSuppressed()) {
|
||||
return "suppressed";
|
||||
}
|
||||
|
||||
return this.titleBarHidden() ? "collapsed" : "expanded";
|
||||
});
|
||||
|
||||
/**
|
||||
* TODO: remove with the VFO1Foundation flag, along with the gate in `titleBarClasses`. Once the bar
|
||||
* is styled on its first render, the transition classes go back in the base list unconditionally —
|
||||
* an element never transitions on its first style resolution.
|
||||
*
|
||||
* True once the bar has collapsed at least once. `vfo1Enabled` resolves after the first paint, and
|
||||
* CSS transitions from the after-change style alone, so a transition declared in that pass animates
|
||||
* the arriving padding and border instead of a collapse.
|
||||
*/
|
||||
private readonly titleBarAnimated = linkedSignal<boolean, boolean>({
|
||||
source: this.titleBarHidden,
|
||||
computation: (hidden, previous) => hidden || (previous?.value ?? false),
|
||||
});
|
||||
|
||||
/**
|
||||
* TODO: remove with the VFO1Foundation flag, along with the `header` class binding it feeds.
|
||||
*
|
||||
* The one-bar header paints `header` itself rather than a descendant, which is what keeps it
|
||||
* reachable by the `[&_header]:` overrides the default password manager prompt relies on.
|
||||
*/
|
||||
protected readonly headerClasses = computed(() => {
|
||||
if (this.vfo1Enabled()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const classes = [
|
||||
"tw-py-3",
|
||||
"bit-compact:tw-py-2",
|
||||
// End padding is less than start padding to prioritize visual alignment when icon buttons are
|
||||
// used at the end of the `end` slot. Other elements used there may need their own margin or
|
||||
// padding to achieve visual alignment.
|
||||
"tw-pe-1",
|
||||
"bit-compact:tw-pe-0.5",
|
||||
"tw-transition-colors",
|
||||
"tw-duration-200",
|
||||
"tw-border-0",
|
||||
"tw-border-b",
|
||||
"tw-border-solid",
|
||||
];
|
||||
|
||||
if (this.background() === "alt" && !this.pageScrolled()) {
|
||||
classes.push("tw-bg-background-alt", "tw-border-transparent");
|
||||
} else {
|
||||
classes.push("tw-bg-background", "tw-border-border-base");
|
||||
}
|
||||
|
||||
/** The back button's own padding stands in for the bar's start padding. */
|
||||
classes.push(
|
||||
...(this.showBackButton()
|
||||
? ["tw-ps-1", "bit-compact:tw-ps-0"]
|
||||
: ["tw-ps-4", "bit-compact:tw-ps-3"]),
|
||||
);
|
||||
|
||||
return classes.join(" ");
|
||||
});
|
||||
|
||||
protected readonly titleBarClasses = computed(() => {
|
||||
if (!this.vfo1Enabled()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// `display: none` rather than an `@if`: destroying the bar would take the `end` slot's
|
||||
// projected content with it, since the same `ng-content` serves both bars.
|
||||
if (this.titleBarSuppressed()) {
|
||||
return "tw-hidden";
|
||||
}
|
||||
|
||||
// The bar is a single-row grid, collapsed by animating that row between `1fr` and `0fr`. There
|
||||
// is no height ceiling to guess: the expanded bar is whatever height its content needs.
|
||||
const classes = [
|
||||
"tw-grid",
|
||||
"tw-overflow-hidden",
|
||||
"tw-border-0",
|
||||
"tw-border-b",
|
||||
"tw-border-solid",
|
||||
];
|
||||
|
||||
// TODO: remove with the VFO1Foundation flag — move these three back into the base list above.
|
||||
// See `titleBarAnimated`: declaring the transition before the bar collapses would animate the
|
||||
// padding and border that arrive with the flag rather than the collapse.
|
||||
if (this.titleBarAnimated()) {
|
||||
classes.push(
|
||||
"motion-safe:tw-transition-[grid-template-rows,padding]",
|
||||
"tw-duration-200",
|
||||
"tw-ease-out",
|
||||
);
|
||||
}
|
||||
|
||||
// The transparent bar keeps the border box so both treatments collapse to the same height.
|
||||
classes.push(
|
||||
...(this.background() === "alt"
|
||||
? ["tw-bg-transparent", "tw-border-transparent"]
|
||||
: ["tw-bg-bg-tertiary", "tw-border-border-base"]),
|
||||
);
|
||||
|
||||
/** The back button's own padding stands in for the title bar's start padding. */
|
||||
if (this.showBackButton()) {
|
||||
classes.push("tw-ps-1", "bit-compact:tw-ps-0");
|
||||
}
|
||||
|
||||
if (this.titleBarHidden()) {
|
||||
// The block padding collapses alongside the row so visible motion starts on the first frame.
|
||||
// `focus-within` keeps the collapsed bar reachable, and visible, by Shift+Tab — its extra
|
||||
// pseudo-class outweighs the collapsed values, so no `!` is needed.
|
||||
classes.push(
|
||||
"tw-grid-rows-[0fr]",
|
||||
"tw-px-3",
|
||||
"bit-compact:tw-px-2",
|
||||
"tw-py-0",
|
||||
"focus-within:tw-grid-rows-[1fr]",
|
||||
"focus-within:tw-py-3",
|
||||
"bit-compact:focus-within:tw-py-2",
|
||||
);
|
||||
} else {
|
||||
classes.push("tw-grid-rows-[1fr]", "tw-p-3", "bit-compact:tw-p-2");
|
||||
}
|
||||
|
||||
return classes.join(" ");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -44,6 +44,8 @@ page looks nice when the extension is popped out.
|
||||
- `full-width-notice`
|
||||
- Similar to `above-scroll-area`, this content will display before `above-scroll-area` without
|
||||
container margin or padding.
|
||||
- `floating-action`
|
||||
- A single action pinned to the bottom of the page. See [Floating action](#floating-action) below.
|
||||
- default
|
||||
- Whatever content you want in `main`.
|
||||
|
||||
@@ -77,15 +79,27 @@ Basic usage example:
|
||||
- `showBackButton`: optional, defaults to `false`
|
||||
- Toggles the back button to appear. The back button uses `Location.back()` to navigate back one
|
||||
page in history.
|
||||
- `background`: optional
|
||||
- `"default"` uses a white background
|
||||
- `"alt"` uses a transparent background
|
||||
- `hideTitleBar`: optional, defaults to `false`
|
||||
- Hides the page title bar, leaving only the app bar. For a page that titles itself in its own
|
||||
content — an anon layout page, say — where the title bar would otherwise be empty. The back
|
||||
button moves to the leading edge of the app bar, so `showBackButton` keeps working. Has no
|
||||
effect without the `vfo1-foundation` flag: the one-bar header has no second bar to fall back to,
|
||||
and hiding it would take the logo and `end` slot with it.
|
||||
- `background`: optional, defaults to `"default"`
|
||||
- `"default"` sits on an opaque background with a bottom border.
|
||||
- `"alt"` is transparent and borderless, for a page that paints its own background — an
|
||||
illustration, say. This arg is not flag-gated: a page that owns its background owns it in the
|
||||
two-bar header too, where it applies to the page title bar and leaves the app bar alone.
|
||||
|
||||
**Slots**
|
||||
|
||||
- `end`
|
||||
- Use to insert one or more interactive elements.
|
||||
- Use to insert one or more interactive elements on the trailing edge of the topmost bar.
|
||||
- The header handles the spacing between elements passed to the `end` slot.
|
||||
- `title-suffix`
|
||||
- A control belonging to the title itself — a vault switcher, say — rendered inline right after
|
||||
the `h1`, closer to it than the rest of the row. Keep using `pageTitle` for the title; this slot
|
||||
is only for what sits beside it, and renders only when `pageTitle` is set.
|
||||
|
||||
Usage example:
|
||||
|
||||
@@ -98,6 +112,75 @@ Usage example:
|
||||
</popup-header>
|
||||
```
|
||||
|
||||
### Two-bar header (`vfo1-foundation`)
|
||||
|
||||
Behind the `vfo1-foundation` feature flag, `popup-header` renders two stacked bars inside its banner
|
||||
landmark instead of one:
|
||||
|
||||
- an **app bar** — dark, branded, carrying the Bitwarden logo plus the chrome that belongs to the
|
||||
extension rather than the page (pop out button, account switcher)
|
||||
- a **page title bar** — the familiar header, carrying the back button, a leading icon tile, the
|
||||
title, and an item count
|
||||
|
||||
The app bar is extension chrome rather than page content, so it renders on every screen that uses
|
||||
`popup-header` — dialogs and onboarding pages included. Because it owns the branding, the legacy
|
||||
default slot is dropped while the flag is on: a page that used it to project its own logo would
|
||||
otherwise render the logo twice. Content that still belongs in the title bar goes in `title-start`,
|
||||
`title-end`, or `title-suffix`.
|
||||
|
||||
Toggle the flag in the **Feature Flags** addon panel to compare the two.
|
||||
|
||||
<Canvas of={stories.HeaderV2} />
|
||||
|
||||
**Where `end` renders**
|
||||
|
||||
`end` is always the trailing edge of the topmost bar, so the flag moves it: with the flag on it
|
||||
renders in the app bar, where it stays pinned while the title bar collapses on scroll; with the flag
|
||||
off it renders in the title bar. Nothing changes on the calling side — the pop out button and
|
||||
account switcher belong to the extension rather than the page, so the app bar is where they were
|
||||
headed.
|
||||
|
||||
Because the app bar is dark, buttons projected into `end` need `buttonType="side-nav"` to be legible
|
||||
against it once the flag is on.
|
||||
|
||||
**Additional slots, both title bar only**
|
||||
|
||||
- `title-start`
|
||||
- A leading element before the title, typically a `bit-icon-tile`. Named for the bar it lands in
|
||||
rather than `start`, so it reads as the counterpart of `title-end` — `end` belongs to the
|
||||
topmost bar, which is a different row once the app bar exists.
|
||||
- `title-end`
|
||||
- One or more elements on the trailing edge of the title bar — content belonging to the page
|
||||
rather than the extension, such as an item count, an "Add" button, or a status chip.
|
||||
|
||||
These two slots render only while the flag is on; with the flag off, content passed to them is
|
||||
dropped.
|
||||
|
||||
#### Scrolling
|
||||
|
||||
The popup viewport is short, so the page title bar collapses while the user scrolls the page content
|
||||
down and returns as soon as they scroll back up. The app bar stays pinned throughout.
|
||||
|
||||
The title bar is always visible at the top of the page, and while it contains focus — so tabbing
|
||||
back into the back button or the `title-end` slot brings it into view rather than leaving the focus
|
||||
ring clipped. It is only ever visually clipped, never removed from the accessibility tree. Under
|
||||
`prefers-reduced-motion: reduce` the collapse is instant rather than animated.
|
||||
|
||||
The behavior comes from the `scrollDirection` util reading `ScrollLayoutService`, so a page whose
|
||||
content sits outside a `bitScrollLayoutHost` region simply never collapses its title bar.
|
||||
|
||||
<Canvas of={stories.HeaderV2ScrollingTitleBar} />
|
||||
|
||||
#### Controls alongside the title
|
||||
|
||||
A page that needs a control next to its title keeps `pageTitle` and projects the control into
|
||||
`title-suffix`, so every page renders the same `h1`. The suffix sits in its own group with a tighter
|
||||
gap than the rest of the row, so it reads as part of the title rather than as another item beside
|
||||
it. Unlike `title-start` and `title-end`, this slot is not flag-gated — it renders in the one-bar
|
||||
header too.
|
||||
|
||||
<Canvas of={stories.HeaderV2TitleSuffix} />
|
||||
|
||||
### Transparent header
|
||||
|
||||
<Canvas of={stories.TransparentHeader} />
|
||||
@@ -106,8 +189,10 @@ Common interactive elements to insert into the `end` slot are:
|
||||
|
||||
- `app-current-account`: shows current account and switcher
|
||||
- `app-pop-out`: shows popout button when the extension is not already popped out
|
||||
- "Add" button: this can be accomplished with the Button component and any custom functionality for
|
||||
that particular page
|
||||
|
||||
An "Add" button belongs to the page rather than the extension, so it goes in `end` today and moves
|
||||
to `title-end` once the two-bar header ships. Either can be accomplished with the Button component
|
||||
and any custom functionality for that particular page.
|
||||
|
||||
### Notice
|
||||
|
||||
@@ -146,6 +231,46 @@ Usage example:
|
||||
</popup-footer>
|
||||
```
|
||||
|
||||
## Floating action
|
||||
|
||||
The `floating-action` slot pins a single action to the bottom-trailing corner of the page content —
|
||||
typically a page's primary "create" action. It is anchored to the scroll viewport rather than the
|
||||
scrolled content, so it stays in place while the page scrolls, and the scroll region gains extra
|
||||
bottom padding so the last row is never permanently occluded.
|
||||
|
||||
Because it is anchored to the page content area, it automatically sits above `popup-footer` and the
|
||||
bottom tab navigation. Pages configure nothing.
|
||||
|
||||
<Canvas of={stories.WithFloatingAction} />
|
||||
|
||||
<Canvas of={stories.WithFloatingActionAndFooter} />
|
||||
|
||||
Usage example:
|
||||
|
||||
```html
|
||||
<popup-page>
|
||||
<popup-header slot="header" [pageTitle]="'vault' | i18n"></popup-header>
|
||||
<app-vault-list></app-vault-list>
|
||||
<button slot="floating-action" bitButton buttonType="primary" type="button" startIcon="bwi-plus">
|
||||
{{ "new" | i18n }}
|
||||
</button>
|
||||
</popup-page>
|
||||
```
|
||||
|
||||
### Accessibility
|
||||
|
||||
- **The slot renders before the scroll region in DOM and tab order.** Keyboard and screen reader
|
||||
users reach the action right after the `above-scroll-area` controls (search, filters) rather than
|
||||
after every row in the list. The mismatch between visual position and DOM order is intentional and
|
||||
remains meaningful under
|
||||
[WCAG 2.4.3 Focus Order](https://www.w3.org/WAI/WCAG22/Understanding/focus-order.html), since a
|
||||
"create" action logically follows the filter controls.
|
||||
- **The projected element must supply its own accessible name.** Use `bitButton` with visible text,
|
||||
or `bitIconButton` with `[label]`. `popup-page` adds no labeling of its own.
|
||||
- The slot is a positioning wrapper, not a landmark or focus scope — project exactly one interactive
|
||||
element into it.
|
||||
- The floating action is hidden while `loading` is `true`.
|
||||
|
||||
# Page types
|
||||
|
||||
There are a few types of pages that are used in the browser extension.
|
||||
|
||||
@@ -5,11 +5,14 @@ import {
|
||||
Component,
|
||||
computed,
|
||||
importProvidersFrom,
|
||||
inject,
|
||||
input,
|
||||
signal,
|
||||
} from "@angular/core";
|
||||
import { toSignal } from "@angular/core/rxjs-interop";
|
||||
import { RouterModule } from "@angular/router";
|
||||
import { Meta, StoryObj, applicationConfig, moduleMetadata } from "@storybook/angular";
|
||||
import { of } from "rxjs";
|
||||
|
||||
import {
|
||||
GeneratorActive,
|
||||
@@ -23,6 +26,8 @@ import {
|
||||
VaultInactive,
|
||||
} from "@bitwarden/assets/svg";
|
||||
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
||||
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { SendService } from "@bitwarden/common/tools/send/services/send.service.abstraction";
|
||||
import {
|
||||
@@ -37,6 +42,7 @@ import {
|
||||
BitTableV2Component,
|
||||
ChipActionComponent,
|
||||
ButtonModule,
|
||||
type ButtonType,
|
||||
type ColumnName,
|
||||
defineTable,
|
||||
FilterMenuModule,
|
||||
@@ -48,7 +54,11 @@ import {
|
||||
SectionComponent,
|
||||
ScrollLayoutDirective,
|
||||
SvgComponent,
|
||||
IconTileComponent,
|
||||
TypographyModule,
|
||||
} from "@bitwarden/components";
|
||||
import { enabledFlags } from "@bitwarden/storybook";
|
||||
import { I18nPipe } from "@bitwarden/ui-common";
|
||||
|
||||
import { VaultLoadingSkeletonComponent } from "../../../vault/popup/components/vault-loading-skeleton/vault-loading-skeleton.component";
|
||||
import { PopupRouterCacheService } from "../view-cache/popup-router-cache.service";
|
||||
@@ -58,10 +68,9 @@ import { PopupHeaderComponent } from "./popup-header.component";
|
||||
import { PopupPageComponent } from "./popup-page.component";
|
||||
import { PopupTabNavigationComponent } from "./popup-tab-navigation.component";
|
||||
|
||||
// FIXME(https://bitwarden.atlassian.net/browse/CL-764): Migrate to OnPush
|
||||
// eslint-disable-next-line @angular-eslint/prefer-on-push-component-change-detection
|
||||
@Component({
|
||||
selector: "extension-container",
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
template: `
|
||||
<div class="tw-h-[640px] tw-w-[480px] tw-border tw-border-solid tw-border-secondary-300">
|
||||
<ng-content></ng-content>
|
||||
@@ -70,10 +79,9 @@ import { PopupTabNavigationComponent } from "./popup-tab-navigation.component";
|
||||
})
|
||||
class ExtensionContainerComponent {}
|
||||
|
||||
// FIXME(https://bitwarden.atlassian.net/browse/CL-764): Migrate to OnPush
|
||||
// eslint-disable-next-line @angular-eslint/prefer-on-push-component-change-detection
|
||||
@Component({
|
||||
selector: "extension-popped-container",
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
template: `
|
||||
<div class="tw-h-[640px] tw-w-[900px] tw-border tw-border-solid tw-border-secondary-300">
|
||||
<ng-content></ng-content>
|
||||
@@ -83,10 +91,9 @@ class ExtensionContainerComponent {}
|
||||
})
|
||||
class ExtensionPoppedContainerComponent {}
|
||||
|
||||
// FIXME(https://bitwarden.atlassian.net/browse/CL-764): Migrate to OnPush
|
||||
// eslint-disable-next-line @angular-eslint/prefer-on-push-component-change-detection
|
||||
@Component({
|
||||
selector: "vault-placeholder",
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
template: /*html*/ `
|
||||
<bit-section>
|
||||
<bit-item-group>
|
||||
@@ -118,10 +125,9 @@ class VaultComponent {
|
||||
protected data = Array.from(Array(20).keys());
|
||||
}
|
||||
|
||||
// FIXME(https://bitwarden.atlassian.net/browse/CL-764): Migrate to OnPush
|
||||
// eslint-disable-next-line @angular-eslint/prefer-on-push-component-change-detection
|
||||
@Component({
|
||||
selector: "mock-add-button",
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
template: `
|
||||
<button bitButton size="small" buttonType="primary" type="button">
|
||||
<i class="bwi bwi-plus" aria-hidden="true"></i>
|
||||
@@ -132,43 +138,78 @@ class VaultComponent {
|
||||
})
|
||||
class MockAddButtonComponent {}
|
||||
|
||||
// FIXME(https://bitwarden.atlassian.net/browse/CL-764): Migrate to OnPush
|
||||
// eslint-disable-next-line @angular-eslint/prefer-on-push-component-change-detection
|
||||
/** Mirrors the real `app-pop-out` styling and label; the click is inert in Storybook. */
|
||||
@Component({
|
||||
selector: "mock-popout-button",
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
template: `
|
||||
<button bitIconButton="bwi-popout" size="small" type="button" label="Pop out"></button>
|
||||
<button
|
||||
bitIconButton="bwi-popout"
|
||||
size="small"
|
||||
type="button"
|
||||
[buttonType]="buttonType()"
|
||||
label="{{ 'popOutNewWindow' | i18n }}"
|
||||
[title]="'popOutNewWindow' | i18n"
|
||||
></button>
|
||||
`,
|
||||
imports: [IconButtonModule],
|
||||
imports: [I18nPipe, IconButtonModule],
|
||||
})
|
||||
class MockPopoutButtonComponent {}
|
||||
class MockPopoutButtonComponent {
|
||||
/** Optional so the mock still renders if a story runs without the feature-flag addon. */
|
||||
private readonly configService = inject(ConfigService, { optional: true });
|
||||
|
||||
private readonly vfo1Enabled = toSignal(
|
||||
this.configService?.getFeatureFlag$(FeatureFlag.VFO1Foundation) ?? of(false),
|
||||
{ initialValue: false },
|
||||
);
|
||||
|
||||
protected readonly buttonType = computed<ButtonType>(() =>
|
||||
this.vfo1Enabled() ? "side-nav" : "primaryGhost",
|
||||
);
|
||||
}
|
||||
|
||||
// FIXME(https://bitwarden.atlassian.net/browse/CL-764): Migrate to OnPush
|
||||
// eslint-disable-next-line @angular-eslint/prefer-on-push-component-change-detection
|
||||
@Component({
|
||||
selector: "mock-current-account",
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
template: `
|
||||
<button class="tw-bg-transparent tw-border-none tw-p-0 tw-me-1 tw-align-middle" type="button">
|
||||
<bit-avatar text="Ash Ketchum"></bit-avatar>
|
||||
<!-- TODO: remove [class] binding and wrapperClasses when VFO1Foundation flag is removed -->
|
||||
<button
|
||||
[class]="wrapperClasses()"
|
||||
class="tw-bg-transparent tw-border-none tw-p-0 tw-align-middle"
|
||||
type="button"
|
||||
>
|
||||
<!-- TODO: remove size binding and lock to "sm" when VFO1Foundation flag is removed -->
|
||||
<bit-avatar text="Ash Ketchum" [size]="avatarSize()"></bit-avatar>
|
||||
</button>
|
||||
`,
|
||||
imports: [AvatarModule],
|
||||
})
|
||||
class MockCurrentAccountComponent {}
|
||||
class MockCurrentAccountComponent {
|
||||
/** Optional so the mock still renders if a story runs without the feature-flag addon. */
|
||||
private readonly configService = inject(ConfigService, { optional: true });
|
||||
|
||||
private readonly vfo1Enabled = toSignal(
|
||||
this.configService?.getFeatureFlag$(FeatureFlag.VFO1Foundation) ?? of(false),
|
||||
{ initialValue: false },
|
||||
);
|
||||
|
||||
protected readonly avatarSize = computed(() => (this.vfo1Enabled() ? "sm" : "base"));
|
||||
|
||||
/** TODO: remove with the VFO1Foundation flag. Mirrors CurrentAccountComponent.wrapperClasses. */
|
||||
protected readonly wrapperClasses = computed(() => (this.vfo1Enabled() ? "" : "tw-me-2 tw-mt-1"));
|
||||
}
|
||||
|
||||
// FIXME(https://bitwarden.atlassian.net/browse/CL-764): Migrate to OnPush
|
||||
// eslint-disable-next-line @angular-eslint/prefer-on-push-component-change-detection
|
||||
@Component({
|
||||
selector: "mock-search",
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
template: ` <bit-search placeholder="Search"> </bit-search> `,
|
||||
imports: [SearchModule],
|
||||
})
|
||||
class MockSearchComponent {}
|
||||
|
||||
// FIXME(https://bitwarden.atlassian.net/browse/CL-764): Migrate to OnPush
|
||||
// eslint-disable-next-line @angular-eslint/prefer-on-push-component-change-detection
|
||||
@Component({
|
||||
selector: "mock-banner",
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
template: `
|
||||
<bit-banner variant="primary"> This is an important note about these ciphers </bit-banner>
|
||||
`,
|
||||
@@ -176,10 +217,9 @@ class MockSearchComponent {}
|
||||
})
|
||||
class MockBannerComponent {}
|
||||
|
||||
// FIXME(https://bitwarden.atlassian.net/browse/CL-764): Migrate to OnPush
|
||||
// eslint-disable-next-line @angular-eslint/prefer-on-push-component-change-detection
|
||||
@Component({
|
||||
selector: "mock-vault-page",
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
template: `
|
||||
<popup-page>
|
||||
<popup-header slot="header" pageTitle="Test">
|
||||
@@ -205,10 +245,9 @@ class MockBannerComponent {}
|
||||
})
|
||||
class MockVaultPageComponent {}
|
||||
|
||||
// FIXME(https://bitwarden.atlassian.net/browse/CL-764): Migrate to OnPush
|
||||
// eslint-disable-next-line @angular-eslint/prefer-on-push-component-change-detection
|
||||
@Component({
|
||||
selector: "mock-vault-page-popped",
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
template: `
|
||||
<popup-page>
|
||||
<popup-header slot="header" pageTitle="Test">
|
||||
@@ -230,10 +269,9 @@ class MockVaultPageComponent {}
|
||||
})
|
||||
class MockVaultPagePoppedComponent {}
|
||||
|
||||
// FIXME(https://bitwarden.atlassian.net/browse/CL-764): Migrate to OnPush
|
||||
// eslint-disable-next-line @angular-eslint/prefer-on-push-component-change-detection
|
||||
@Component({
|
||||
selector: "mock-generator-page",
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
template: `
|
||||
<popup-page>
|
||||
<popup-header slot="header" pageTitle="Test">
|
||||
@@ -256,10 +294,9 @@ class MockVaultPagePoppedComponent {}
|
||||
})
|
||||
class MockGeneratorPageComponent {}
|
||||
|
||||
// FIXME(https://bitwarden.atlassian.net/browse/CL-764): Migrate to OnPush
|
||||
// eslint-disable-next-line @angular-eslint/prefer-on-push-component-change-detection
|
||||
@Component({
|
||||
selector: "mock-send-page",
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
template: `
|
||||
<popup-page>
|
||||
<popup-header slot="header" pageTitle="Test">
|
||||
@@ -282,10 +319,9 @@ class MockGeneratorPageComponent {}
|
||||
})
|
||||
class MockSendPageComponent {}
|
||||
|
||||
// FIXME(https://bitwarden.atlassian.net/browse/CL-764): Migrate to OnPush
|
||||
// eslint-disable-next-line @angular-eslint/prefer-on-push-component-change-detection
|
||||
@Component({
|
||||
selector: "mock-settings-page",
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
template: `
|
||||
<popup-page>
|
||||
<popup-header slot="header" pageTitle="Test">
|
||||
@@ -308,10 +344,9 @@ class MockSendPageComponent {}
|
||||
})
|
||||
class MockSettingsPageComponent {}
|
||||
|
||||
// FIXME(https://bitwarden.atlassian.net/browse/CL-764): Migrate to OnPush
|
||||
// eslint-disable-next-line @angular-eslint/prefer-on-push-component-change-detection
|
||||
@Component({
|
||||
selector: "mock-vault-subpage",
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
template: `
|
||||
<popup-page>
|
||||
<popup-header slot="header" pageTitle="Test" showBackButton>
|
||||
@@ -345,6 +380,81 @@ class MockSettingsPageComponent {}
|
||||
})
|
||||
class MockVaultSubpageComponent {}
|
||||
|
||||
@Component({
|
||||
selector: "mock-vault-page-floating-action",
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
template: `
|
||||
<popup-page [loading]="loading()">
|
||||
<popup-header slot="header" pageTitle="Test">
|
||||
<ng-container slot="end">
|
||||
<mock-popout-button></mock-popout-button>
|
||||
<mock-current-account></mock-current-account>
|
||||
</ng-container>
|
||||
</popup-header>
|
||||
<mock-search slot="above-scroll-area"></mock-search>
|
||||
<vault-placeholder></vault-placeholder>
|
||||
<button
|
||||
slot="floating-action"
|
||||
bitButton
|
||||
buttonType="primary"
|
||||
type="button"
|
||||
startIcon="bwi-plus"
|
||||
>
|
||||
Add
|
||||
</button>
|
||||
</popup-page>
|
||||
`,
|
||||
imports: [
|
||||
PopupPageComponent,
|
||||
PopupHeaderComponent,
|
||||
ButtonModule,
|
||||
MockPopoutButtonComponent,
|
||||
MockCurrentAccountComponent,
|
||||
MockSearchComponent,
|
||||
VaultComponent,
|
||||
],
|
||||
})
|
||||
class MockVaultPageFloatingActionComponent {
|
||||
readonly loading = input(false);
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: "mock-vault-subpage-floating-action",
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
template: `
|
||||
<popup-page>
|
||||
<popup-header slot="header" pageTitle="Test" showBackButton>
|
||||
<ng-container slot="end">
|
||||
<mock-popout-button></mock-popout-button>
|
||||
</ng-container>
|
||||
</popup-header>
|
||||
<vault-placeholder></vault-placeholder>
|
||||
<button
|
||||
slot="floating-action"
|
||||
bitButton
|
||||
buttonType="primary"
|
||||
type="button"
|
||||
startIcon="bwi-plus"
|
||||
>
|
||||
Add
|
||||
</button>
|
||||
<popup-footer slot="footer">
|
||||
<button type="button" bitButton buttonType="primary">Save</button>
|
||||
<button type="button" bitButton buttonType="secondary">Cancel</button>
|
||||
</popup-footer>
|
||||
</popup-page>
|
||||
`,
|
||||
imports: [
|
||||
PopupPageComponent,
|
||||
PopupHeaderComponent,
|
||||
PopupFooterComponent,
|
||||
ButtonModule,
|
||||
MockPopoutButtonComponent,
|
||||
VaultComponent,
|
||||
],
|
||||
})
|
||||
class MockVaultSubpageFloatingActionComponent {}
|
||||
|
||||
// --- Table V2 list-presentation exploration -------------------------------------
|
||||
// Duplicated from libs/components Table V2 "Filterable" story so we can iterate on
|
||||
// the responsive table/list presentation inside the real extension popup chrome.
|
||||
@@ -658,6 +768,141 @@ class MockVaultTablePageComponent {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The VFO1 two-bar header: a branded app bar carrying the pop out button and account switcher, above
|
||||
* a page title bar carrying the leading icon tile, title, and item count.
|
||||
*/
|
||||
@Component({
|
||||
selector: "mock-send-page-v2",
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
template: `
|
||||
<popup-page>
|
||||
<popup-header slot="header" pageTitle="Send">
|
||||
<ng-container slot="end">
|
||||
<mock-popout-button></mock-popout-button>
|
||||
<mock-current-account></mock-current-account>
|
||||
</ng-container>
|
||||
<bit-icon-tile slot="title-start" icon="bwi-send" variant="brand" size="sm"></bit-icon-tile>
|
||||
<span slot="title-end" bitTypography="body2" class="tw-text-muted">3 Sends</span>
|
||||
</popup-header>
|
||||
<mock-search slot="above-scroll-area"></mock-search>
|
||||
<div class="tw-text-main">Send content here</div>
|
||||
</popup-page>
|
||||
`,
|
||||
imports: [
|
||||
PopupPageComponent,
|
||||
PopupHeaderComponent,
|
||||
MockPopoutButtonComponent,
|
||||
MockCurrentAccountComponent,
|
||||
MockSearchComponent,
|
||||
IconTileComponent,
|
||||
TypographyModule,
|
||||
],
|
||||
})
|
||||
class MockSendPageV2Component {}
|
||||
|
||||
/**
|
||||
* The two-bar header over enough content to overflow the popup, so the title bar's collapse-on-scroll
|
||||
* behavior is actually reachable.
|
||||
*/
|
||||
@Component({
|
||||
selector: "mock-scrolling-page-v2",
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
template: `
|
||||
<popup-page>
|
||||
<popup-header slot="header" pageTitle="Vault">
|
||||
<ng-container slot="end">
|
||||
<mock-popout-button></mock-popout-button>
|
||||
<mock-current-account></mock-current-account>
|
||||
</ng-container>
|
||||
<bit-icon-tile slot="title-start" icon="bwi-lock" variant="brand" size="sm"></bit-icon-tile>
|
||||
<span slot="title-end" bitTypography="body2" class="tw-text-muted">20 items</span>
|
||||
</popup-header>
|
||||
<mock-search slot="above-scroll-area"></mock-search>
|
||||
<vault-placeholder></vault-placeholder>
|
||||
</popup-page>
|
||||
`,
|
||||
imports: [
|
||||
PopupPageComponent,
|
||||
PopupHeaderComponent,
|
||||
MockPopoutButtonComponent,
|
||||
MockCurrentAccountComponent,
|
||||
MockSearchComponent,
|
||||
IconTileComponent,
|
||||
TypographyModule,
|
||||
VaultComponent,
|
||||
],
|
||||
})
|
||||
class MockScrollingPageV2Component {}
|
||||
|
||||
/**
|
||||
* The standard title plus a control that belongs to it — the vault switcher — projected into
|
||||
* `title-suffix`.
|
||||
*/
|
||||
@Component({
|
||||
selector: "mock-vault-page-v2",
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
template: `
|
||||
<popup-page>
|
||||
<popup-header slot="header" pageTitle="My vault">
|
||||
<ng-container slot="end">
|
||||
<mock-popout-button></mock-popout-button>
|
||||
<mock-current-account></mock-current-account>
|
||||
</ng-container>
|
||||
<bit-icon-tile
|
||||
slot="title-start"
|
||||
icon="bwi-vault"
|
||||
variant="brand"
|
||||
size="sm"
|
||||
></bit-icon-tile>
|
||||
<button
|
||||
slot="title-suffix"
|
||||
type="button"
|
||||
bitIconButton="bwi-angle-down"
|
||||
size="xsmall"
|
||||
label="Switch vault"
|
||||
></button>
|
||||
</popup-header>
|
||||
<vault-placeholder></vault-placeholder>
|
||||
</popup-page>
|
||||
`,
|
||||
imports: [
|
||||
PopupPageComponent,
|
||||
PopupHeaderComponent,
|
||||
MockPopoutButtonComponent,
|
||||
MockCurrentAccountComponent,
|
||||
VaultComponent,
|
||||
IconButtonModule,
|
||||
IconTileComponent,
|
||||
],
|
||||
})
|
||||
class MockVaultPageV2Component {}
|
||||
|
||||
/** A subpage, where the back button sits at the leading edge of the title bar. */
|
||||
@Component({
|
||||
selector: "mock-back-page-v2",
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
template: `
|
||||
<popup-page>
|
||||
<popup-header slot="header" pageTitle="Item details" showBackButton>
|
||||
<ng-container slot="end">
|
||||
<mock-popout-button></mock-popout-button>
|
||||
<mock-current-account></mock-current-account>
|
||||
</ng-container>
|
||||
</popup-header>
|
||||
<vault-placeholder></vault-placeholder>
|
||||
</popup-page>
|
||||
`,
|
||||
imports: [
|
||||
PopupPageComponent,
|
||||
PopupHeaderComponent,
|
||||
MockPopoutButtonComponent,
|
||||
MockCurrentAccountComponent,
|
||||
VaultComponent,
|
||||
],
|
||||
})
|
||||
class MockBackPageV2Component {}
|
||||
|
||||
// Shared so it can be provided at BOTH the module level (page content) and the
|
||||
// application level — the responsive filter dialog opened via DialogService roots
|
||||
// its injector at the app injector, so it needs I18nService provided there too.
|
||||
@@ -668,6 +913,8 @@ const popupLayoutI18nProvider = {
|
||||
back: "Back",
|
||||
loading: "Loading",
|
||||
search: "Search",
|
||||
appLogoLabel: "Bitwarden",
|
||||
popOutNewWindow: "Pop out to a new window",
|
||||
vault: "Vault",
|
||||
generator: "Generator",
|
||||
send: "Send",
|
||||
@@ -719,12 +966,18 @@ export default {
|
||||
MockBannerComponent,
|
||||
MockSearchComponent,
|
||||
MockVaultSubpageComponent,
|
||||
MockVaultPageFloatingActionComponent,
|
||||
MockVaultSubpageFloatingActionComponent,
|
||||
MockVaultPageComponent,
|
||||
MockSendPageComponent,
|
||||
MockGeneratorPageComponent,
|
||||
MockSettingsPageComponent,
|
||||
MockVaultPagePoppedComponent,
|
||||
MockVaultTablePageComponent,
|
||||
MockSendPageV2Component,
|
||||
MockScrollingPageV2Component,
|
||||
MockVaultPageV2Component,
|
||||
MockBackPageV2Component,
|
||||
StatusLockupComponent,
|
||||
VaultComponent,
|
||||
ScrollingModule,
|
||||
@@ -897,6 +1150,44 @@ export const PopupPageWithFooter: Story = {
|
||||
}),
|
||||
};
|
||||
|
||||
/**
|
||||
* The `floating-action` slot pins a single action to the bottom of the content area. It is anchored to
|
||||
* the scroll viewport rather than the scrolled content, so it stays in place while the list scrolls,
|
||||
* and the scroll region gains extra bottom padding so the last row is never occluded.
|
||||
*
|
||||
* The slot is projected *before* the scroll region in DOM order, so keyboard and screen reader users
|
||||
* reach it right after the `above-scroll-area` controls instead of after every row. Tab from the top of
|
||||
* the page to verify.
|
||||
*/
|
||||
export const WithFloatingAction: StoryObj = {
|
||||
render: (args) => ({
|
||||
props: args,
|
||||
template: /* HTML */ `
|
||||
<extension-container>
|
||||
<popup-tab-navigation [navButtons]="navButtons">
|
||||
<mock-vault-page-floating-action [loading]="loading"></mock-vault-page-floating-action>
|
||||
</popup-tab-navigation>
|
||||
</extension-container>
|
||||
`,
|
||||
}),
|
||||
args: { loading: false, navButtons: navButtons() },
|
||||
};
|
||||
|
||||
/**
|
||||
* The floating action is anchored to the page content area, so it automatically clears
|
||||
* `popup-footer` and the bottom tab navigation. Pages configure nothing.
|
||||
*/
|
||||
export const WithFloatingActionAndFooter: Story = {
|
||||
render: (args) => ({
|
||||
props: args,
|
||||
template: /* HTML */ `
|
||||
<extension-container>
|
||||
<mock-vault-subpage-floating-action></mock-vault-subpage-floating-action>
|
||||
</extension-container>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const RegularMode: Story = {
|
||||
render: (args) => ({
|
||||
props: args,
|
||||
@@ -1054,7 +1345,7 @@ export const TransparentHeader: Story = {
|
||||
template: /* HTML */ `
|
||||
<extension-container>
|
||||
<popup-page>
|
||||
<popup-header slot="header" background="alt">
|
||||
<popup-header slot="header" background="alt" pageTitle="">
|
||||
<span class="tw-italic tw-text-main">🤠 Custom Content</span>
|
||||
</popup-header>
|
||||
<vault-placeholder></vault-placeholder>
|
||||
@@ -1064,6 +1355,70 @@ export const TransparentHeader: Story = {
|
||||
}),
|
||||
};
|
||||
|
||||
/**
|
||||
* Under the `vfo1-foundation` flag, `popup-header` renders two bars: a branded app bar carrying the
|
||||
* pop out button and account switcher, and a page title bar carrying the leading icon tile, title,
|
||||
* and item count. Toggle the flag in the Feature Flags addon panel to compare against v1.
|
||||
*/
|
||||
export const HeaderV2: Story = {
|
||||
globals: enabledFlags(FeatureFlag.VFO1Foundation),
|
||||
render: (args) => ({
|
||||
props: args,
|
||||
template: /* HTML */ `
|
||||
<extension-container>
|
||||
<mock-send-page-v2></mock-send-page-v2>
|
||||
</extension-container>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
/**
|
||||
* The popup viewport is short, so the page title bar collapses while the user scrolls down and
|
||||
* returns as soon as they scroll back up. The app bar stays pinned. Scroll the list to see it — the
|
||||
* collapsed state can't be reached without interacting, so this story is excluded from snapshots.
|
||||
*/
|
||||
export const HeaderV2ScrollingTitleBar: Story = {
|
||||
globals: enabledFlags(FeatureFlag.VFO1Foundation),
|
||||
parameters: { chromatic: { disableSnapshot: true } },
|
||||
render: (args) => ({
|
||||
props: args,
|
||||
template: /* HTML */ `
|
||||
<extension-container>
|
||||
<mock-scrolling-page-v2></mock-scrolling-page-v2>
|
||||
</extension-container>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
/**
|
||||
* A control that belongs to the title itself — the vault switcher — goes in `title-suffix`, so the
|
||||
* page keeps the standard `pageTitle` rather than rebuilding the title region.
|
||||
*/
|
||||
export const HeaderV2TitleSuffix: Story = {
|
||||
globals: enabledFlags(FeatureFlag.VFO1Foundation),
|
||||
render: (args) => ({
|
||||
props: args,
|
||||
template: /* HTML */ `
|
||||
<extension-container>
|
||||
<mock-vault-page-v2></mock-vault-page-v2>
|
||||
</extension-container>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
/** A subpage keeps its title bar, so the back button renders there, beside the title. */
|
||||
export const HeaderV2BackButton: Story = {
|
||||
globals: enabledFlags(FeatureFlag.VFO1Foundation),
|
||||
render: (args) => ({
|
||||
props: args,
|
||||
template: /* HTML */ `
|
||||
<extension-container>
|
||||
<mock-back-page-v2></mock-back-page-v2>
|
||||
</extension-container>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const Notice: Story = {
|
||||
render: (args) => ({
|
||||
props: args,
|
||||
|
||||
@@ -6,17 +6,29 @@
|
||||
to tailwind's tw-px-2) in compact mode, but stretch to fill the remainder of the container when the content reaches a maximum of
|
||||
640px in width (equivalent to tailwind's `sm` breakpoint)
|
||||
-->
|
||||
@let hideNonScrollable = loading() || nonScrollable.childElementCount === 0;
|
||||
<div
|
||||
#nonScrollable
|
||||
class="tw-transition-colors tw-duration-200 tw-border-0 tw-border-b tw-border-solid tw-py-3 bit-compact:tw-py-2 tw-px-[max(0.75rem,calc((100%-(var(--tw-sm-breakpoint)))/2))] bit-compact:tw-px-[max(0.5rem,calc((100%-(var(--tw-sm-breakpoint)))/2))]"
|
||||
[ngClass]="{
|
||||
'tw-invisible !tw-p-0 !tw-border-none': loading() || nonScrollable.childElementCount === 0,
|
||||
'tw-border-secondary-300': scrolled(),
|
||||
'tw-border-transparent': !scrolled(),
|
||||
}"
|
||||
class="tw-transition-colors tw-duration-200 tw-border-0 tw-border-b tw-border-solid tw-border-transparent tw-py-3 bit-compact:tw-py-2 tw-px-[max(0.75rem,calc((100%-(var(--tw-sm-breakpoint)))/2))] bit-compact:tw-px-[max(0.5rem,calc((100%-(var(--tw-sm-breakpoint)))/2))]"
|
||||
[class.tw-invisible]="hideNonScrollable"
|
||||
[class.!tw-p-0]="hideNonScrollable"
|
||||
[class.!tw-border-none]="hideNonScrollable"
|
||||
[class.!tw-border-border-base]="scrolled()"
|
||||
>
|
||||
<ng-content select="[slot=above-scroll-area]"></ng-content>
|
||||
</div>
|
||||
<!--
|
||||
Declared before the scroll region so keyboard users reach it without tabbing through every row.
|
||||
The scroll region's clearance uses `:has()` because a bound class would go stale under OnPush.
|
||||
-->
|
||||
<div
|
||||
class="tw-absolute tw-inset-x-0 tw-bottom-0 tw-z-10 tw-p-3 bit-compact:tw-p-2 tw-pointer-events-none [&:has([slot=floating-action])~div]:!tw-pb-20"
|
||||
[class.tw-invisible]="loading()"
|
||||
>
|
||||
<div class="tw-max-w-screen-sm tw-mx-auto tw-flex tw-justify-end [&>*]:tw-pointer-events-auto">
|
||||
<ng-content select="[slot=floating-action]"></ng-content>
|
||||
</div>
|
||||
</div>
|
||||
<!--
|
||||
x padding on this container is designed to always be a minimum of 0.75rem (equivalent to tailwind's tw-px-3), or 0.5rem (equivalent
|
||||
to tailwind's tw-px-2) in compact mode, but stretch to fill the remainder of the container when the content reaches a maximum of
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
import { ChangeDetectionStrategy, Component, signal } from "@angular/core";
|
||||
import { ComponentFixture, TestBed } from "@angular/core/testing";
|
||||
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { I18nMockService } from "@bitwarden/components";
|
||||
|
||||
import { PopupPageComponent } from "./popup-page.component";
|
||||
|
||||
@Component({
|
||||
template: `
|
||||
<popup-page [loading]="loading()">
|
||||
<span data-testid="content">Page content</span>
|
||||
@if (showFloatingAction()) {
|
||||
<button slot="floating-action" type="button" data-testid="floating-action">Add</button>
|
||||
}
|
||||
</popup-page>
|
||||
`,
|
||||
imports: [PopupPageComponent],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
class TestHostComponent {
|
||||
readonly loading = signal(false);
|
||||
readonly showFloatingAction = signal(true);
|
||||
}
|
||||
|
||||
describe("PopupPageComponent", () => {
|
||||
let fixture: ComponentFixture<TestHostComponent>;
|
||||
let host: TestHostComponent;
|
||||
|
||||
const scrollRegion = (): HTMLElement =>
|
||||
fixture.nativeElement.querySelector("[data-testid=popup-layout-scroll-region]");
|
||||
const floatingAction = (): HTMLElement | null =>
|
||||
fixture.nativeElement.querySelector("[data-testid=floating-action]");
|
||||
/** The positioning wrapper `popup-page` puts around the projected action. */
|
||||
const floatingActionWrapper = (): HTMLElement =>
|
||||
floatingAction()!.closest(".tw-absolute") as HTMLElement;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [TestHostComponent],
|
||||
providers: [
|
||||
{
|
||||
provide: I18nService,
|
||||
useValue: new I18nMockService({ loading: "Loading" }),
|
||||
},
|
||||
],
|
||||
}).compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(TestHostComponent);
|
||||
host = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it("projects content into the floating action slot", () => {
|
||||
expect(floatingAction()).not.toBeNull();
|
||||
});
|
||||
|
||||
/**
|
||||
* The action is visually pinned to the bottom of the page, but rendering it last would force
|
||||
* keyboard and screen reader users through every row of the list to reach it.
|
||||
*/
|
||||
it("renders the floating action before the scroll region in tab order", () => {
|
||||
const position = floatingAction()!.compareDocumentPosition(scrollRegion());
|
||||
|
||||
expect(position & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
||||
});
|
||||
|
||||
/**
|
||||
* The scroll region's extra bottom padding is applied by a `:has()` rule on the wrapper rather than
|
||||
* a class binding, because whether the slot received content is not reactively observable. Asserting
|
||||
* the selector matches is what proves the rule fires — jsdom computes no layout.
|
||||
*/
|
||||
it("pads the scroll region so the floating action does not occlude the last row", () => {
|
||||
const wrapper = floatingActionWrapper();
|
||||
|
||||
expect(wrapper.classList).toContain("[&:has([slot=floating-action])~div]:!tw-pb-20");
|
||||
expect(wrapper.matches(":has([slot=floating-action])")).toBe(true);
|
||||
expect(wrapper.nextElementSibling).toBe(scrollRegion());
|
||||
|
||||
host.showFloatingAction.set(false);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(wrapper.matches(":has([slot=floating-action])")).toBe(false);
|
||||
});
|
||||
|
||||
/** The loading spinner carries no z-index, so the action has to step aside for it. */
|
||||
it("hides the floating action while loading", () => {
|
||||
expect(floatingActionWrapper().classList).not.toContain("tw-invisible");
|
||||
|
||||
host.loading.set(true);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(floatingActionWrapper().classList).toContain("tw-invisible");
|
||||
});
|
||||
});
|
||||
@@ -37,6 +37,8 @@ export class PopupPageComponent {
|
||||
readonly hideOverflow = input(false, { transform: booleanAttribute });
|
||||
|
||||
protected readonly scrolled = signal(false);
|
||||
|
||||
/** Whether the page content has been scrolled away from the top. Read by `popup-header`. */
|
||||
readonly isScrolled = this.scrolled.asReadonly();
|
||||
|
||||
constructor() {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<popup-page [disablePadding]="true">
|
||||
<!-- The hero titles these pages, so the title bar would be empty. -->
|
||||
<popup-header
|
||||
slot="header"
|
||||
hideTitleBar
|
||||
[background]="'alt'"
|
||||
[showBackButton]="showBackButton"
|
||||
[pageTitle]="''"
|
||||
|
||||
@@ -16,7 +16,6 @@ import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
||||
import { AvatarService } from "@bitwarden/common/auth/abstractions/avatar.service";
|
||||
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
|
||||
import { ClientType } from "@bitwarden/common/enums";
|
||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||
import {
|
||||
EnvironmentService,
|
||||
Environment,
|
||||
@@ -107,12 +106,6 @@ const decorators = (options: {
|
||||
avatarColor$: of("#ab134a"),
|
||||
} as Partial<AvatarService>,
|
||||
},
|
||||
{
|
||||
provide: ConfigService,
|
||||
useValue: {
|
||||
getFeatureFlag: () => true,
|
||||
},
|
||||
},
|
||||
{
|
||||
provide: EnvironmentService,
|
||||
useValue: {
|
||||
|
||||
@@ -73,7 +73,7 @@ describe("VaultGeneratorDialogComponent", () => {
|
||||
|
||||
it("should show password generator title", () => {
|
||||
const header = fixture.debugElement.query(By.css("popup-header")).componentInstance;
|
||||
expect(header.pageTitle).toBe("passwordGenerator");
|
||||
expect(header.pageTitle()).toBe("passwordGenerator");
|
||||
});
|
||||
|
||||
it("should pass type to cipher form generator", () => {
|
||||
@@ -140,7 +140,7 @@ describe("VaultGeneratorDialogComponent", () => {
|
||||
});
|
||||
|
||||
it("should close with canceled action when dismissed", () => {
|
||||
fixture.debugElement.query(By.css("popup-header")).componentInstance.backAction();
|
||||
fixture.debugElement.query(By.css("popup-header")).componentInstance.backAction()();
|
||||
expect(mockDialogRef.close).toHaveBeenCalledWith({
|
||||
action: GeneratorDialogAction.Canceled,
|
||||
});
|
||||
|
||||
@@ -35,13 +35,17 @@ export class ScrollLayoutService {
|
||||
export class ScrollLayoutHostDirective implements OnDestroy {
|
||||
private ref = inject(ElementRef);
|
||||
private service = inject(ScrollLayoutService);
|
||||
private previousRef = this.service.scrollableRef();
|
||||
|
||||
constructor() {
|
||||
this.service.scrollableRef.set(this.ref as ElementRef<HTMLElement>);
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.service.scrollableRef.set(null);
|
||||
// Only restore if this host is still the active one; out-of-order destruction must not clobber a live host.
|
||||
if (this.service.scrollableRef() === this.ref) {
|
||||
this.service.scrollableRef.set(this.previousRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,4 +3,5 @@ export * from "./function-to-observable";
|
||||
export * from "./has-scrollable-content";
|
||||
export * from "./i18n-mock.service";
|
||||
export * from "./query-param-store";
|
||||
export * from "./scroll-direction";
|
||||
export * from "./state-mock";
|
||||
|
||||
176
libs/components/src/utils/scroll-direction.spec.ts
Normal file
176
libs/components/src/utils/scroll-direction.spec.ts
Normal file
@@ -0,0 +1,176 @@
|
||||
import { ElementRef, Signal, signal } from "@angular/core";
|
||||
import { TestBed } from "@angular/core/testing";
|
||||
|
||||
import { ScrollDirection, scrollDirection } from "./scroll-direction";
|
||||
|
||||
/**
|
||||
* jsdom reports `0` for every layout measurement, so the scroll geometry has to be stubbed for the
|
||||
* element to look scrollable at all.
|
||||
*/
|
||||
const createScrollable = (scrollHeight = 1000, clientHeight = 500) => {
|
||||
const element = document.createElement("div");
|
||||
|
||||
Object.defineProperty(element, "scrollHeight", { value: scrollHeight, configurable: true });
|
||||
Object.defineProperty(element, "clientHeight", { value: clientHeight, configurable: true });
|
||||
|
||||
return element;
|
||||
};
|
||||
|
||||
/** Flushes `auditTime(0, animationFrameScheduler)`. */
|
||||
const nextFrame = () => new Promise((resolve) => requestAnimationFrame(resolve));
|
||||
|
||||
const scrollTo = async (element: HTMLElement, top: number) => {
|
||||
element.scrollTop = top;
|
||||
element.dispatchEvent(new Event("scroll"));
|
||||
|
||||
await nextFrame();
|
||||
};
|
||||
|
||||
describe("scrollDirection", () => {
|
||||
const create = (
|
||||
scrollable: Signal<ElementRef<HTMLElement> | HTMLElement | null>,
|
||||
options?: Parameters<typeof scrollDirection>[1],
|
||||
): Signal<ScrollDirection> =>
|
||||
TestBed.runInInjectionContext(() => scrollDirection(scrollable, options));
|
||||
|
||||
it("starts out scrolling up", () => {
|
||||
expect(create(signal(createScrollable()))()).toBe("up");
|
||||
});
|
||||
|
||||
it("accepts an ElementRef", async () => {
|
||||
const element = createScrollable();
|
||||
const direction = create(signal(new ElementRef(element)));
|
||||
|
||||
await scrollTo(element, 200);
|
||||
|
||||
expect(direction()).toBe("down");
|
||||
});
|
||||
|
||||
it("reports up while there is no element", async () => {
|
||||
const scrollable = signal<HTMLElement | null>(null);
|
||||
const direction = create(scrollable);
|
||||
|
||||
await nextFrame();
|
||||
expect(direction()).toBe("up");
|
||||
|
||||
const element = createScrollable();
|
||||
scrollable.set(element);
|
||||
await scrollTo(element, 200);
|
||||
|
||||
expect(direction()).toBe("down");
|
||||
});
|
||||
|
||||
it("reports up when the element cannot scroll", async () => {
|
||||
const element = createScrollable(500, 500);
|
||||
const direction = create(signal(element));
|
||||
|
||||
await scrollTo(element, 200);
|
||||
|
||||
expect(direction()).toBe("up");
|
||||
});
|
||||
|
||||
it("reports down once the threshold is passed", async () => {
|
||||
const element = createScrollable();
|
||||
const direction = create(signal(element), { threshold: 16 });
|
||||
|
||||
await scrollTo(element, 17);
|
||||
|
||||
expect(direction()).toBe("down");
|
||||
});
|
||||
|
||||
it("holds direction below the threshold", async () => {
|
||||
const element = createScrollable();
|
||||
const direction = create(signal(element), { threshold: 16 });
|
||||
|
||||
await scrollTo(element, 8);
|
||||
|
||||
expect(direction()).toBe("up");
|
||||
});
|
||||
|
||||
it("ignores jitter that alternates below the threshold", async () => {
|
||||
const element = createScrollable();
|
||||
const direction = create(signal(element), { threshold: 16 });
|
||||
|
||||
for (const top of [8, 1, 9, 2, 10, 3]) {
|
||||
await scrollTo(element, top);
|
||||
expect(direction()).toBe("up");
|
||||
}
|
||||
});
|
||||
|
||||
it("flips once sub-threshold steps accumulate past the threshold", async () => {
|
||||
const element = createScrollable();
|
||||
const direction = create(signal(element), { threshold: 16 });
|
||||
|
||||
await scrollTo(element, 8);
|
||||
expect(direction()).toBe("up");
|
||||
|
||||
await scrollTo(element, 16);
|
||||
expect(direction()).toBe("up");
|
||||
|
||||
await scrollTo(element, 24);
|
||||
expect(direction()).toBe("down");
|
||||
});
|
||||
|
||||
it("reports up again when scrolling back up past the threshold", async () => {
|
||||
const element = createScrollable();
|
||||
const direction = create(signal(element), { threshold: 16 });
|
||||
|
||||
await scrollTo(element, 200);
|
||||
expect(direction()).toBe("down");
|
||||
|
||||
await scrollTo(element, 150);
|
||||
expect(direction()).toBe("up");
|
||||
});
|
||||
|
||||
it("reports up at the top of the element", async () => {
|
||||
const element = createScrollable();
|
||||
const direction = create(signal(element));
|
||||
|
||||
await scrollTo(element, 200);
|
||||
expect(direction()).toBe("down");
|
||||
|
||||
await scrollTo(element, 0);
|
||||
expect(direction()).toBe("up");
|
||||
});
|
||||
|
||||
it("holds down near the bottom, where collapsing chrome clamps the offset", async () => {
|
||||
const element = createScrollable();
|
||||
const direction = create(signal(element), { bottomOffset: 24 });
|
||||
|
||||
// maxTop is 500, so anything at or past 476 is "near the bottom".
|
||||
await scrollTo(element, 500);
|
||||
expect(direction()).toBe("down");
|
||||
|
||||
// The consumer collapsed its header, the viewport grew, and the browser clamped `scrollTop`.
|
||||
await scrollTo(element, 480);
|
||||
expect(direction()).toBe("down");
|
||||
});
|
||||
|
||||
it("does not flip on a viewport-sized jump", async () => {
|
||||
const element = createScrollable(2000, 500);
|
||||
const direction = create(signal(element));
|
||||
|
||||
// A scroll position restore, rather than the user scrolling.
|
||||
await scrollTo(element, 500);
|
||||
expect(direction()).toBe("up");
|
||||
|
||||
await scrollTo(element, 600);
|
||||
expect(direction()).toBe("down");
|
||||
});
|
||||
|
||||
it("stops listening to an element once it is replaced", async () => {
|
||||
const first = createScrollable();
|
||||
const second = createScrollable();
|
||||
const scrollable = signal<HTMLElement | null>(first);
|
||||
const direction = create(scrollable);
|
||||
|
||||
scrollable.set(second);
|
||||
await nextFrame();
|
||||
|
||||
await scrollTo(first, 200);
|
||||
expect(direction()).toBe("up");
|
||||
|
||||
await scrollTo(second, 200);
|
||||
expect(direction()).toBe("down");
|
||||
});
|
||||
});
|
||||
112
libs/components/src/utils/scroll-direction.ts
Normal file
112
libs/components/src/utils/scroll-direction.ts
Normal file
@@ -0,0 +1,112 @@
|
||||
import { ElementRef, Signal } from "@angular/core";
|
||||
import { toObservable, toSignal } from "@angular/core/rxjs-interop";
|
||||
import { animationFrameScheduler, fromEvent, of } from "rxjs";
|
||||
import { auditTime, distinctUntilChanged, map, scan, startWith, switchMap } from "rxjs/operators";
|
||||
|
||||
/** Which way the user is currently moving through a scrollable region. */
|
||||
export type ScrollDirection = "up" | "down";
|
||||
|
||||
export type ScrollDirectionOptions = {
|
||||
/**
|
||||
* Pixels of travel required to flip direction. Filters out the sub-pixel and trackpad jitter that
|
||||
* would otherwise make the reported direction thrash.
|
||||
*/
|
||||
threshold?: number;
|
||||
|
||||
/** Within this many pixels of the top, always report `"up"`. */
|
||||
topOffset?: number;
|
||||
|
||||
/**
|
||||
* Within this many pixels of the bottom, hold `"down"`. Prevents an oscillation loop when a
|
||||
* consumer collapses chrome in response to `"down"`: the collapse grows the viewport, the browser
|
||||
* clamps `scrollTop`, and the smaller offset would otherwise read as `"up"`.
|
||||
*/
|
||||
bottomOffset?: number;
|
||||
};
|
||||
|
||||
type ScrollDirectionState = {
|
||||
direction: ScrollDirection;
|
||||
|
||||
/** The offset at which the current direction was committed. */
|
||||
anchor: number;
|
||||
};
|
||||
|
||||
const initialState: ScrollDirectionState = { direction: "up", anchor: 0 };
|
||||
|
||||
const nativeElement = (
|
||||
scrollable: ElementRef<HTMLElement> | HTMLElement | null | undefined,
|
||||
): HTMLElement | null => {
|
||||
if (scrollable instanceof ElementRef) {
|
||||
return scrollable.nativeElement;
|
||||
}
|
||||
|
||||
return scrollable ?? null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Track the direction a scrollable element is being scrolled.
|
||||
*
|
||||
* Takes an element rather than a `CdkScrollable` so that it also works with regions marked by
|
||||
* `bitScrollLayoutHost`, which is not a `CdkScrollable`.
|
||||
*
|
||||
* @param scrollable The element to observe. Reports `"up"` while it is nullish or not scrollable.
|
||||
* @param options See {@link ScrollDirectionOptions}
|
||||
* @returns {Signal<ScrollDirection>} `"up"` until the element is scrolled down.
|
||||
*/
|
||||
export const scrollDirection = (
|
||||
scrollable: Signal<ElementRef<HTMLElement> | HTMLElement | null | undefined>,
|
||||
{ threshold = 16, topOffset = 0, bottomOffset = 24 }: ScrollDirectionOptions = {},
|
||||
): Signal<ScrollDirection> => {
|
||||
const element$ = toObservable(scrollable).pipe(map(nativeElement));
|
||||
|
||||
const direction$ = element$.pipe(
|
||||
switchMap((element) => {
|
||||
if (!element) {
|
||||
return of<ScrollDirection>("up");
|
||||
}
|
||||
|
||||
return fromEvent(element, "scroll").pipe(
|
||||
auditTime(0, animationFrameScheduler),
|
||||
startWith(null),
|
||||
map(() => ({
|
||||
top: element.scrollTop,
|
||||
maxTop: element.scrollHeight - element.clientHeight,
|
||||
viewport: element.clientHeight,
|
||||
})),
|
||||
scan((state: ScrollDirectionState, { top, maxTop, viewport }): ScrollDirectionState => {
|
||||
if (maxTop <= 0 || top <= topOffset) {
|
||||
return { direction: "up", anchor: top };
|
||||
}
|
||||
|
||||
if (top >= maxTop - bottomOffset) {
|
||||
return { direction: "down", anchor: top };
|
||||
}
|
||||
|
||||
const delta = top - state.anchor;
|
||||
|
||||
// A viewport-sized jump is programmatic — a scroll position restore, `scrollIntoView`,
|
||||
// or the browser clamping the offset. Re-anchor without reading it as user intent.
|
||||
if (Math.abs(delta) >= viewport) {
|
||||
return { direction: state.direction, anchor: top };
|
||||
}
|
||||
|
||||
if (Math.abs(delta) <= threshold) {
|
||||
// Track the extreme so that jitter can't accumulate into a flip.
|
||||
const anchor =
|
||||
state.direction === "down"
|
||||
? Math.max(state.anchor, top)
|
||||
: Math.min(state.anchor, top);
|
||||
|
||||
return { direction: state.direction, anchor };
|
||||
}
|
||||
|
||||
return { direction: delta > 0 ? "down" : "up", anchor: top };
|
||||
}, initialState),
|
||||
map(({ direction }) => direction),
|
||||
);
|
||||
}),
|
||||
distinctUntilChanged(),
|
||||
);
|
||||
|
||||
return toSignal(direction$, { initialValue: "up" });
|
||||
};
|
||||
@@ -10,19 +10,32 @@
|
||||
export const ADDON_ID = "bitwarden/feature-flags";
|
||||
export const PANEL_ID = `${ADDON_ID}/panel`;
|
||||
|
||||
/** Global holding the list of currently-enabled feature flag keys. */
|
||||
/**
|
||||
* Global holding the list of currently-enabled feature flag keys.
|
||||
*
|
||||
* Globals are user state: Storybook diffs them, array-merges them and round-trips
|
||||
* them through the `?globals=` query param. Only URL-safe primitives (and flat
|
||||
* arrays of them that start out empty) survive that intact — a structured value
|
||||
* comes back as a sparse array once it drifts from `initialGlobals`. Keep
|
||||
* anything richer out of globals; see `FEATURE_FLAGS_PARAM`.
|
||||
*/
|
||||
export const FEATURE_FLAGS_GLOBAL = "bwEnabledFeatureFlags";
|
||||
|
||||
/**
|
||||
* Global holding the full catalog of toggleable flags. Seeded by the preview
|
||||
* (which can read the enum) via `initialGlobals` and read by the manager panel.
|
||||
* Globals sync across the preview/manager boundary, so the panel never needs to
|
||||
* import the flag enum itself.
|
||||
* Parameter holding the full catalog of toggleable flags. Set project-wide by the
|
||||
* preview (which can read the enum) and read by the manager panel via
|
||||
* `useParameter`, so the panel never needs to import the flag enum itself.
|
||||
*
|
||||
* Parameters rather than globals because parameters are never diffed or
|
||||
* URL-serialized, so an array of objects crosses the preview/manager boundary
|
||||
* unchanged.
|
||||
*/
|
||||
export const FEATURE_FLAGS_CATALOG_GLOBAL = "bwFeatureFlagCatalog";
|
||||
export const FEATURE_FLAGS_PARAM = "bwFeatureFlags";
|
||||
|
||||
export type FeatureFlagOption = { name: string; value: string };
|
||||
|
||||
export type FeatureFlagsParameter = { catalog: FeatureFlagOption[] };
|
||||
|
||||
/**
|
||||
* Builds a story-level `globals` override that enables the given flag(s) (and
|
||||
* only those) for a single story. Use it to define distinct stories with
|
||||
|
||||
@@ -1,31 +1,43 @@
|
||||
/**
|
||||
* Manager-side (Storybook UI) "Feature Flags" panel.
|
||||
*
|
||||
* Renders a checkbox per flag from the catalog seeded into globals by the
|
||||
* preview, and writes the enabled set back to the `FEATURE_FLAGS_GLOBAL` global.
|
||||
* The preview's mock `ConfigService` reads that global. This file must not
|
||||
* import from `@bitwarden/*` — the manager bundle can't resolve those aliases,
|
||||
* which is why the catalog arrives via globals rather than a direct import. It
|
||||
* is imported directly (relatively) by `.storybook/manager.js` as a manager
|
||||
* entry, so it is intentionally not re-exported from the addon barrel.
|
||||
* Renders a checkbox per flag from the catalog the preview publishes as a
|
||||
* parameter, and writes the enabled set back to the `FEATURE_FLAGS_GLOBAL`
|
||||
* global. The preview's mock `ConfigService` reads that global. This file must
|
||||
* not import from `@bitwarden/*` — the manager bundle can't resolve those
|
||||
* aliases, which is why the catalog arrives over the preview/manager boundary
|
||||
* rather than via a direct import. It is imported directly (relatively) by
|
||||
* `.storybook/manager.js` as a manager entry, so it is intentionally not
|
||||
* re-exported from the addon barrel.
|
||||
*/
|
||||
import React, { useMemo, useState } from "react";
|
||||
import { addons, types, useGlobals } from "storybook/manager-api";
|
||||
import { addons, types, useGlobals, useParameter } from "storybook/manager-api";
|
||||
|
||||
import {
|
||||
ADDON_ID,
|
||||
FEATURE_FLAGS_CATALOG_GLOBAL,
|
||||
FEATURE_FLAGS_GLOBAL,
|
||||
FEATURE_FLAGS_PARAM,
|
||||
FeatureFlagOption,
|
||||
FeatureFlagsParameter,
|
||||
PANEL_ID,
|
||||
} from "./constants";
|
||||
|
||||
/**
|
||||
* Reads an array off cross-boundary state, discarding anything malformed.
|
||||
* Storybook can hand back a sparse array when a value it persists drifts from
|
||||
* its initial value, and a bad entry here takes down the whole manager UI.
|
||||
*/
|
||||
function toArray<T>(value: unknown): T[] {
|
||||
return Array.isArray(value) ? value.filter((entry) => entry != null) : [];
|
||||
}
|
||||
|
||||
function FeatureFlagsPanel() {
|
||||
const [globals, updateGlobals] = useGlobals();
|
||||
const parameter = useParameter<FeatureFlagsParameter | undefined>(FEATURE_FLAGS_PARAM, undefined);
|
||||
const [filter, setFilter] = useState("");
|
||||
|
||||
const catalog = (globals[FEATURE_FLAGS_CATALOG_GLOBAL] ?? []) as FeatureFlagOption[];
|
||||
const enabled = (globals[FEATURE_FLAGS_GLOBAL] ?? []) as string[];
|
||||
const catalog = useMemo(() => toArray<FeatureFlagOption>(parameter?.catalog), [parameter]);
|
||||
const enabled = toArray<string>(globals[FEATURE_FLAGS_GLOBAL]);
|
||||
const enabledSet = useMemo(() => new Set(enabled), [enabled]);
|
||||
|
||||
const visible = useMemo(() => {
|
||||
@@ -66,7 +78,11 @@ function FeatureFlagsPanel() {
|
||||
<button onClick={() => setEnabled([])}>Clear all</button>
|
||||
</div>
|
||||
<div style={{ marginBottom: 8, opacity: 0.7 }}>
|
||||
{enabledSet.size} of {catalog.length} enabled
|
||||
{/* The panel is pre-rendered before a story is prepared, so an empty
|
||||
catalog is a normal transient state rather than a failure. */}
|
||||
{catalog.length === 0
|
||||
? "No feature flags available"
|
||||
: `${enabledSet.size} of ${catalog.length} enabled`}
|
||||
</div>
|
||||
<ul
|
||||
style={{
|
||||
|
||||
Reference in New Issue
Block a user