1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-13 23:13:36 +00:00
Files
browser/libs/components/src/drawer/drawer.stories.ts
Mark Youssef ccb9a0b8a1 [CL-132] Implement resizable side nav (#16533)
Co-authored-by: Vicki League <vleague@bitwarden.com>
2025-12-29 14:08:33 -05:00

129 lines
4.2 KiB
TypeScript

import { RouterTestingModule } from "@angular/router/testing";
import { Meta, StoryObj, applicationConfig, moduleMetadata } from "@storybook/angular";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { GlobalStateProvider } from "@bitwarden/state";
import { ButtonModule } from "../button";
import { CalloutModule } from "../callout";
import { LayoutComponent } from "../layout";
import { mockLayoutI18n } from "../layout/mocks";
import { positionFixedWrapperDecorator } from "../stories/storybook-decorators";
import { TypographyModule } from "../typography";
import { I18nMockService, StorybookGlobalStateProvider } 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(),
moduleMetadata({
imports: [
RouterTestingModule,
LayoutComponent,
DrawerModule,
ButtonModule,
CalloutModule,
TypographyModule,
],
providers: [
{
provide: I18nService,
useFactory: () => {
return new I18nMockService({
...mockLayoutI18n,
close: "Close",
loading: "Loading",
});
},
},
],
}),
applicationConfig({
providers: [
{
provide: GlobalStateProvider,
useClass: StorybookGlobalStateProvider,
},
],
}),
],
} as Meta<DrawerComponent>;
type Story = StoryObj<DrawerComponent>;
export const Default: Story = {
render: (args) => ({
props: args,
template: /*html*/ `
<bit-layout class="tw-text-main">
<p>The drawer is {{ open ? "open" : "closed" }}.<p>
<button type="button" bitButton (click)="drawer.toggle()">Toggle</button>
<!-- Note: bit-drawer does *not* need to be a direct descendant of bit-layout. -->
<bit-drawer [(open)]="open" #drawer>
<bit-drawer-header title="Hello Bitwaaaaaaaaaaaaaaaaaaaaaaaaarden!">
<i slot="start" class="bwi bwi-key" aria-hidden="true"></i>
</bit-drawer-header>
<bit-drawer-body>
<p bitTypography="body1">
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.
</p>
</bit-drawer-body>
</bit-drawer>
</bit-layout>
`,
}),
args: {
open: true,
},
};
export const Headless: Story = {
render: (args) => ({
props: args,
template: /*html*/ `
<bit-layout class="tw-text-main">
<p>The drawer is {{ open ? "open" : "closed" }}.<p>
<button type="button" bitButton (click)="drawer.toggle()">Toggle</button>
<bit-drawer [(open)]="open" #drawer>
<h2 bitTypography="h2"></h2>
Hello world!
</bit-drawer>
</bit-layout>
`,
}),
args: {
open: true,
},
};
export const MultipleDrawers: Story = {
render: (args) => ({
props: args,
template: /*html*/ `
<bit-layout class="tw-text-main">
<button type="button" bitButton (click)="foo.toggle()">{{ !foo.open() ? "Open" : "Close" }} Foo</button>
<button type="button" bitButton (click)="bar.toggle()">{{ !bar.open() ? "Open" : "Close" }} Bar</button>
<bit-drawer #foo>
Foo
</bit-drawer>
<bit-drawer #bar [open]="true">
Bar
</bit-drawer>
</bit-layout>
`,
}),
};