+
+
diff --git a/libs/components/src/drawer/drawer-header.component.ts b/libs/components/src/drawer/drawer-header.component.ts
new file mode 100644
index 0000000000..73834b8487
--- /dev/null
+++ b/libs/components/src/drawer/drawer-header.component.ts
@@ -0,0 +1,34 @@
+import { CommonModule } from "@angular/common";
+import { ChangeDetectionStrategy, Component, HostBinding, input } from "@angular/core";
+
+import { IconButtonModule } from "../icon-button";
+import { I18nPipe } from "../shared/i18n.pipe";
+import { TypographyModule } from "../typography";
+
+import { DrawerCloseDirective } from "./drawer-close.directive";
+
+/**
+ * Header container for `bit-drawer`
+ **/
+@Component({
+ selector: "bit-drawer-header",
+ standalone: true,
+ changeDetection: ChangeDetectionStrategy.OnPush,
+ imports: [CommonModule, DrawerCloseDirective, TypographyModule, IconButtonModule, I18nPipe],
+ templateUrl: "drawer-header.component.html",
+ host: {
+ class: "tw-block tw-pl-4 tw-pr-2 tw-py-2",
+ },
+})
+export class DrawerHeaderComponent {
+ /**
+ * The title to display
+ */
+ title = input.required();
+
+ /** We don't want to set the HTML title attribute with `this.title` */
+ @HostBinding("attr.title")
+ protected get getTitle(): null {
+ return null;
+ }
+}
diff --git a/libs/components/src/drawer/drawer-host.directive.ts b/libs/components/src/drawer/drawer-host.directive.ts
new file mode 100644
index 0000000000..f5e3e56b09
--- /dev/null
+++ b/libs/components/src/drawer/drawer-host.directive.ts
@@ -0,0 +1,28 @@
+import { Portal } from "@angular/cdk/portal";
+import { Directive, signal } from "@angular/core";
+
+/**
+ * Host that renders a drawer
+ *
+ * @internal
+ */
+@Directive({
+ selector: "[bitDrawerHost]",
+ standalone: true,
+})
+export class DrawerHostDirective {
+ private _portal = signal | undefined>(undefined);
+
+ /** The portal to display */
+ portal = this._portal.asReadonly();
+
+ open(portal: Portal) {
+ this._portal.set(portal);
+ }
+
+ close(portal: Portal) {
+ if (portal === this.portal()) {
+ this._portal.set(undefined);
+ }
+ }
+}
diff --git a/libs/components/src/drawer/drawer.component.html b/libs/components/src/drawer/drawer.component.html
new file mode 100644
index 0000000000..fce6b3c57e
--- /dev/null
+++ b/libs/components/src/drawer/drawer.component.html
@@ -0,0 +1,8 @@
+
+
+
+
+
diff --git a/libs/components/src/drawer/drawer.component.ts b/libs/components/src/drawer/drawer.component.ts
new file mode 100644
index 0000000000..ccabb6f0b6
--- /dev/null
+++ b/libs/components/src/drawer/drawer.component.ts
@@ -0,0 +1,76 @@
+import { CdkPortal, PortalModule } from "@angular/cdk/portal";
+import { CommonModule } from "@angular/common";
+import {
+ ChangeDetectionStrategy,
+ Component,
+ effect,
+ inject,
+ input,
+ model,
+ viewChild,
+} from "@angular/core";
+
+import { DrawerHostDirective } from "./drawer-host.directive";
+
+/**
+ * A drawer is a panel of supplementary content that is adjacent to the page's main content.
+ *
+ * Drawers render in `bit-layout`. Drawers must be a descendant of `bit-layout`, but they do not need to be a direct descendant.
+ */
+@Component({
+ selector: "bit-drawer",
+ standalone: true,
+ changeDetection: ChangeDetectionStrategy.OnPush,
+ imports: [CommonModule, PortalModule],
+ templateUrl: "drawer.component.html",
+})
+export class DrawerComponent {
+ private drawerHost = inject(DrawerHostDirective);
+ private portal = viewChild.required(CdkPortal);
+
+ /**
+ * Whether or not the drawer is open.
+ *
+ * Note: Does not support implicit boolean transform due to Angular limitation. Must be bound explicitly `[open]="true"` instead of just `open`.
+ * https://github.com/angular/angular/issues/55166#issuecomment-2032150999
+ **/
+ open = model(false);
+
+ /**
+ * The ARIA role of the drawer.
+ *
+ * - [complementary](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/complementary_role)
+ * - For drawers that contain content that is complementary to the page's main content. (default)
+ * - [navigation](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/navigation_role)
+ * - For drawers that primary contain links to other content.
+ */
+ role = input<"complementary" | "navigation">("complementary");
+
+ constructor() {
+ effect(
+ () => {
+ this.open() ? this.drawerHost.open(this.portal()) : this.drawerHost.close(this.portal());
+ },
+ {
+ allowSignalWrites: true,
+ },
+ );
+
+ // Set `open` to `false` when another drawer is opened.
+ effect(
+ () => {
+ if (this.drawerHost.portal() !== this.portal()) {
+ this.open.set(false);
+ }
+ },
+ {
+ allowSignalWrites: true,
+ },
+ );
+ }
+
+ /** Toggle the drawer between open & closed */
+ toggle() {
+ this.open.update((prev) => !prev);
+ }
+}
diff --git a/libs/components/src/drawer/drawer.mdx b/libs/components/src/drawer/drawer.mdx
new file mode 100644
index 0000000000..0098ce64ea
--- /dev/null
+++ b/libs/components/src/drawer/drawer.mdx
@@ -0,0 +1,120 @@
+import { Meta, Story, Primary, Controls } from "@storybook/addon-docs";
+
+import * as stories from "./drawer.stories";
+
+import { DrawerOpen as KitchenSink } from "../stories/kitchen-sink/kitchen-sink.stories";
+
+
+
+```ts
+import { DrawerComponent } from "@bitwarden/components";
+```
+
+# Drawer
+
+A drawer is a panel of supplementary content that is adjacent to the page's main content.
+
+
+
+
+
+## Usage
+
+A `bit-drawer` in a template will not render inline, but rather will render adjacent to the main
+page content.
+
+```html
+
+
+
+
Lorem ipsum dolor...
+
+
+```
+
+`bit-drawer` must be a descendant of `bit-layout`, but it does not need to be a direct descendant.
+
+## Header and body
+
+Header and body content can be provided with the `bit-drawer-header` and `bit-drawer-body`
+components, respectively.
+
+A title can be passed to the header by input:
+``
+
+Custom content can be rendered before the title with the header's `start` slot:
+
+```html
+
+
+
+```
+
+## Opening and closing
+
+`bit-drawer` opens when its `open` input is `true`:
+
+```html
+...
+```
+
+Note: Model inputs do not support implicit boolean transformation (see Angular reasoning
+[here](https://github.com/angular/angular/issues/55166#issuecomment-2032150999)). `open` must be
+bound explicitly `` instead of just ``.
+
+Buttons can be made to open/toggle drawers by referencing a template variable, or by manipulating
+state that is bound to `open`:
+
+```html
+ ...
+```
+
+For convenience, close buttons can be created _inside_ the drawer with the `bitDrawerClose`
+directive:
+
+```html
+
+
+
+```
+
+## Multiple Drawers
+
+Only one drawer can be open at a time, and they do not stack. If a drawer is already open, opening
+another will close and replace the one already open.
+
+
+
+## Headless
+
+Omitting `bit-drawer-header` and `bit-drawer-body` allows for fully customizable content.
+
+
+
+## Accessibility
+
+- The drawer should contain an h2 element. If you are using `bit-drawer-header`, this is created for
+ you via the `title` input:
+
+```html
+
+
Hello world!
+
+
+
+
+
+
+
+```
+
+- The ARIA role of the drawer can be set with the `role` attribute:
+ - [complementary](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/complementary_role)
+ (default)
+ - For drawers that contain content that is complementary to the page's main content.
+ - [navigation](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/navigation_role)
+ - For drawers that primary contain links to other content.
+
+## Kitchen Sink
+
+
diff --git a/libs/components/src/drawer/drawer.module.ts b/libs/components/src/drawer/drawer.module.ts
new file mode 100644
index 0000000000..9f51ba06b4
--- /dev/null
+++ b/libs/components/src/drawer/drawer.module.ts
@@ -0,0 +1,12 @@
+import { NgModule } from "@angular/core";
+
+import { DrawerBodyComponent } from "./drawer-body.component";
+import { DrawerCloseDirective } from "./drawer-close.directive";
+import { DrawerHeaderComponent } from "./drawer-header.component";
+import { DrawerComponent } from "./drawer.component";
+
+@NgModule({
+ imports: [DrawerComponent, DrawerHeaderComponent, DrawerBodyComponent, DrawerCloseDirective],
+ exports: [DrawerComponent, DrawerHeaderComponent, DrawerBodyComponent, DrawerCloseDirective],
+})
+export class DrawerModule {}
diff --git a/libs/components/src/drawer/drawer.stories.ts b/libs/components/src/drawer/drawer.stories.ts
new file mode 100644
index 0000000000..54b4c89f4c
--- /dev/null
+++ b/libs/components/src/drawer/drawer.stories.ts
@@ -0,0 +1,124 @@
+// FIXME: Update this file to be type safe and remove this and next line
+// @ts-strict-ignore
+import { RouterTestingModule } from "@angular/router/testing";
+import { Meta, StoryObj, moduleMetadata } from "@storybook/angular";
+
+import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
+
+import { ButtonModule } from "../button";
+import { CalloutModule } from "../callout";
+import { LayoutComponent } from "../layout";
+import { mockLayoutI18n } from "../layout/mocks";
+import {
+ disableBothThemeDecorator,
+ positionFixedWrapperDecorator,
+} from "../stories/storybook-decorators";
+import { TypographyModule } from "../typography";
+import { I18nMockService } from "../utils";
+
+import { DrawerBodyComponent } from "./drawer-body.component";
+import { DrawerHeaderComponent } from "./drawer-header.component";
+import { DrawerComponent } from "./drawer.component";
+import { DrawerModule } from "./drawer.module";
+
+export default {
+ title: "Component Library/Drawer",
+ component: DrawerComponent,
+ subcomponents: {
+ DrawerHeaderComponent,
+ DrawerBodyComponent,
+ },
+ decorators: [
+ positionFixedWrapperDecorator(),
+ disableBothThemeDecorator,
+ moduleMetadata({
+ imports: [
+ RouterTestingModule,
+ LayoutComponent,
+ DrawerModule,
+ ButtonModule,
+ CalloutModule,
+ TypographyModule,
+ ],
+ providers: [
+ {
+ provide: I18nService,
+ useFactory: () => {
+ return new I18nMockService({
+ ...mockLayoutI18n,
+ close: "Close",
+ });
+ },
+ },
+ ],
+ }),
+ ],
+} as Meta;
+
+type Story = StoryObj;
+
+export const Default: Story = {
+ render: (args) => ({
+ props: args,
+ template: /*html*/ `
+
+
The drawer is {{ open ? "open" : "closed" }}.
+
+
+
+
+
+
+
+
+
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
+ ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
+ ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
+ reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
+ sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id
+ est laborum.
+
+
+ What did foo say to bar?
+
+
+
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
+ ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
+ ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
+ reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
+ sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id
+ est laborum.
+
+
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
+ ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
+ ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
+ reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
+ sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id
+ est laborum.
+
+
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
+ ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
+ ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
+ reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
+ sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id
+ est laborum.
+
+
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
+ ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
+ ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
+ reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
+ sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id
+ est laborum.
+
+
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
+ ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
+ ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
+ reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
+ sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id
+ est laborum.
+
+
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
+ ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
+ ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
+ reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
+ sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id
+ est laborum.
+
+
+
`,
})
export class KitchenSinkMainComponent {
constructor(public dialogService: DialogService) {}
- openDefaultDialog() {
+ protected drawerOpen = signal(false);
+
+ openDialog() {
this.dialogService.open(KitchenSinkDialog);
}
+ openDrawer() {
+ this.drawerOpen.set(true);
+ }
+
navItems = [
{ icon: "bwi-collection", name: "Password Managers", route: "/" },
{ icon: "bwi-collection", name: "Favorites", route: "/" },
diff --git a/libs/components/src/stories/kitchen-sink/kitchen-sink-shared.module.ts b/libs/components/src/stories/kitchen-sink/kitchen-sink-shared.module.ts
index 56e3a92e2a..c4fe2f9b2a 100644
--- a/libs/components/src/stories/kitchen-sink/kitchen-sink-shared.module.ts
+++ b/libs/components/src/stories/kitchen-sink/kitchen-sink-shared.module.ts
@@ -13,6 +13,7 @@ import { CalloutModule } from "../../callout";
import { CheckboxModule } from "../../checkbox";
import { ColorPasswordModule } from "../../color-password";
import { DialogModule } from "../../dialog";
+import { DrawerModule } from "../../drawer";
import { FormControlModule } from "../../form-control";
import { FormFieldModule } from "../../form-field";
import { IconModule } from "../../icon";
@@ -48,6 +49,7 @@ import { TypographyModule } from "../../typography";
ColorPasswordModule,
CommonModule,
DialogModule,
+ DrawerModule,
FormControlModule,
FormFieldModule,
FormsModule,
@@ -85,6 +87,7 @@ import { TypographyModule } from "../../typography";
ColorPasswordModule,
CommonModule,
DialogModule,
+ DrawerModule,
FormControlModule,
FormFieldModule,
FormsModule,
diff --git a/libs/components/src/stories/kitchen-sink/kitchen-sink.stories.ts b/libs/components/src/stories/kitchen-sink/kitchen-sink.stories.ts
index a90597c171..62b9398438 100644
--- a/libs/components/src/stories/kitchen-sink/kitchen-sink.stories.ts
+++ b/libs/components/src/stories/kitchen-sink/kitchen-sink.stories.ts
@@ -1,13 +1,7 @@
import { importProvidersFrom } from "@angular/core";
import { provideNoopAnimations } from "@angular/platform-browser/animations";
import { RouterModule } from "@angular/router";
-import {
- Meta,
- StoryObj,
- applicationConfig,
- componentWrapperDecorator,
- moduleMetadata,
-} from "@storybook/angular";
+import { Meta, StoryObj, applicationConfig, moduleMetadata } from "@storybook/angular";
import {
userEvent,
getAllByRole,
@@ -23,6 +17,7 @@ import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.servic
import { DialogService } from "../../dialog";
import { LayoutComponent } from "../../layout";
import { I18nMockService } from "../../utils/i18n-mock.service";
+import { disableBothThemeDecorator, positionFixedWrapperDecorator } from "../storybook-decorators";
import { DialogVirtualScrollBlockComponent } from "./components/dialog-virtual-scroll-block.component";
import { KitchenSinkForm } from "./components/kitchen-sink-form.component";
@@ -35,25 +30,8 @@ export default {
title: "Documentation / Kitchen Sink",
component: LayoutComponent,
decorators: [
- componentWrapperDecorator(
- /**
- * Applying a CSS transform makes a `position: fixed` element act like it is `position: relative`
- * https://github.com/storybookjs/storybook/issues/8011#issue-490251969
- */
- (story) => {
- return /* HTML */ `
- ${story}
-
`;
- },
- ({ globals }) => {
- /**
- * avoid a bug with the way that we render the same component twice in the same iframe and how
- * that interacts with the router-outlet
- */
- const themeOverride = globals["theme"] === "both" ? "light" : globals["theme"];
- return { theme: themeOverride };
- },
- ),
+ positionFixedWrapperDecorator(),
+ disableBothThemeDecorator,
moduleMetadata({
imports: [
KitchenSinkSharedModule,
@@ -135,7 +113,7 @@ export const MenuOpen: Story = {
},
};
-export const DefaultDialogOpen: Story = {
+export const DialogOpen: Story = {
...Default,
play: async (context) => {
const canvas = context.canvasElement;
@@ -148,6 +126,19 @@ export const DefaultDialogOpen: Story = {
},
};
+export const DrawerOpen: Story = {
+ ...Default,
+ play: async (context) => {
+ const canvas = context.canvasElement;
+ const drawerButton = getByRole(canvas, "button", {
+ name: "Open Drawer",
+ });
+
+ // workaround for userEvent not firing in FF https://github.com/testing-library/user-event/issues/1075
+ await fireEvent.click(drawerButton);
+ },
+};
+
export const PopoverOpen: Story = {
...Default,
play: async (context) => {
diff --git a/libs/components/src/utils/position-fixed-wrapper-decorator.ts b/libs/components/src/stories/storybook-decorators.ts
similarity index 50%
rename from libs/components/src/utils/position-fixed-wrapper-decorator.ts
rename to libs/components/src/stories/storybook-decorators.ts
index a3298e6ad0..d59f2dd1f3 100644
--- a/libs/components/src/utils/position-fixed-wrapper-decorator.ts
+++ b/libs/components/src/stories/storybook-decorators.ts
@@ -11,7 +11,21 @@ export const positionFixedWrapperDecorator = (wrapper?: (story: string) => strin
* https://github.com/storybookjs/storybook/issues/8011#issue-490251969
*/
(story) =>
- /* HTML */ `
+ /* HTML */ `
${wrapper ? wrapper(story) : story}
`,
);
+
+export const disableBothThemeDecorator = componentWrapperDecorator(
+ (story) => story,
+ ({ globals }) => {
+ /**
+ * avoid a bug with the way that we render the same component twice in the same iframe and how
+ * that interacts with the router-outlet
+ */
+ const themeOverride = globals["theme"] === "both" ? "light" : globals["theme"];
+ return { theme: themeOverride };
+ },
+);