@storybook/angular-vite 0.0.0-canary-test

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,50 @@
1
+ import { CommonModule } from '@angular/common';
2
+ import { Component, Input, Output, EventEmitter } from '@angular/core';
3
+
4
+ @Component({
5
+ selector: 'storybook-button',
6
+ standalone: true,
7
+ imports: [CommonModule],
8
+ template: `
9
+ <button
10
+ type="button"
11
+ (click)="onClick.emit($event)"
12
+ [ngClass]="classes"
13
+ [ngStyle]="{ 'background-color': backgroundColor }"
14
+ >
15
+ {{ label }}
16
+ </button>
17
+ `,
18
+ styleUrls: ['./button.css'],
19
+ })
20
+ export class ButtonComponent {
21
+ /** Is this the principal call to action on the page? */
22
+ @Input()
23
+ primary = false;
24
+
25
+ /** What background color to use */
26
+ @Input()
27
+ backgroundColor?: string;
28
+
29
+ /** How large should the button be? */
30
+ @Input()
31
+ size: 'small' | 'medium' | 'large' = 'medium';
32
+
33
+ /**
34
+ * Button contents
35
+ *
36
+ * @required
37
+ */
38
+ @Input()
39
+ label = 'Button';
40
+
41
+ /** Optional click handler */
42
+ @Output()
43
+ onClick = new EventEmitter<Event>();
44
+
45
+ public get classes(): string[] {
46
+ const mode = this.primary ? 'storybook-button--primary' : 'storybook-button--secondary';
47
+
48
+ return ['storybook-button', `storybook-button--${this.size}`, mode];
49
+ }
50
+ }
@@ -0,0 +1,49 @@
1
+ import type { Meta, StoryObj } from '@storybook/angular-vite';
2
+ import { fn } from 'storybook/test';
3
+
4
+ import { ButtonComponent } from './button.component';
5
+
6
+ // More on how to set up stories at: https://storybook.js.org/docs/writing-stories
7
+ const meta: Meta<ButtonComponent> = {
8
+ title: 'Example/Button',
9
+ component: ButtonComponent,
10
+ tags: ['autodocs'],
11
+ argTypes: {
12
+ backgroundColor: {
13
+ control: 'color',
14
+ },
15
+ },
16
+ // Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#story-args
17
+ args: { onClick: fn() },
18
+ };
19
+
20
+ export default meta;
21
+ type Story = StoryObj<ButtonComponent>;
22
+
23
+ // More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
24
+ export const Primary: Story = {
25
+ args: {
26
+ primary: true,
27
+ label: 'Button',
28
+ },
29
+ };
30
+
31
+ export const Secondary: Story = {
32
+ args: {
33
+ label: 'Button',
34
+ },
35
+ };
36
+
37
+ export const Large: Story = {
38
+ args: {
39
+ size: 'large',
40
+ label: 'Button',
41
+ },
42
+ };
43
+
44
+ export const Small: Story = {
45
+ args: {
46
+ size: 'small',
47
+ label: 'Button',
48
+ },
49
+ };
@@ -0,0 +1,78 @@
1
+ import { Component, Input, Output, EventEmitter } from '@angular/core';
2
+ import { CommonModule } from '@angular/common';
3
+
4
+ import { ButtonComponent } from './button.component';
5
+ import type { User } from './user';
6
+
7
+ @Component({
8
+ selector: 'storybook-header',
9
+ standalone: true,
10
+ imports: [CommonModule, ButtonComponent],
11
+ template: `
12
+ <header>
13
+ <div class="storybook-header">
14
+ <div>
15
+ <svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
16
+ <g fill="none" fillRule="evenodd">
17
+ <path
18
+ d="M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z"
19
+ fill="#FFF"
20
+ />
21
+ <path
22
+ d="M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z"
23
+ fill="#555AB9"
24
+ />
25
+ <path d="M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z" fill="#91BAF8" />
26
+ </g>
27
+ </svg>
28
+ <h1>Acme</h1>
29
+ </div>
30
+ <div>
31
+ <div *ngIf="user">
32
+ <span class="welcome">
33
+ Welcome, <b>{{ user.name }}</b
34
+ >!
35
+ </span>
36
+ <storybook-button
37
+ *ngIf="user"
38
+ size="small"
39
+ (onClick)="onLogout.emit($event)"
40
+ label="Log out"
41
+ ></storybook-button>
42
+ </div>
43
+ <div *ngIf="!user">
44
+ <storybook-button
45
+ *ngIf="!user"
46
+ size="small"
47
+ class="margin-left"
48
+ (onClick)="onLogin.emit($event)"
49
+ label="Log in"
50
+ ></storybook-button>
51
+ <storybook-button
52
+ *ngIf="!user"
53
+ size="small"
54
+ [primary]="true"
55
+ class="margin-left"
56
+ (onClick)="onCreateAccount.emit($event)"
57
+ label="Sign up"
58
+ ></storybook-button>
59
+ </div>
60
+ </div>
61
+ </div>
62
+ </header>
63
+ `,
64
+ styleUrls: ['./header.css'],
65
+ })
66
+ export class HeaderComponent {
67
+ @Input()
68
+ user: User | null = null;
69
+
70
+ @Output()
71
+ onLogin = new EventEmitter<Event>();
72
+
73
+ @Output()
74
+ onLogout = new EventEmitter<Event>();
75
+
76
+ @Output()
77
+ onCreateAccount = new EventEmitter<Event>();
78
+ }
@@ -0,0 +1,33 @@
1
+ import type { Meta, StoryObj } from '@storybook/angular-vite';
2
+ import { fn } from 'storybook/test';
3
+
4
+ import { HeaderComponent } from './header.component';
5
+
6
+ const meta: Meta<HeaderComponent> = {
7
+ title: 'Example/Header',
8
+ component: HeaderComponent,
9
+ // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
10
+ tags: ['autodocs'],
11
+ parameters: {
12
+ // More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
13
+ layout: 'fullscreen',
14
+ },
15
+ args: {
16
+ onLogin: fn(),
17
+ onLogout: fn(),
18
+ onCreateAccount: fn(),
19
+ },
20
+ };
21
+
22
+ export default meta;
23
+ type Story = StoryObj<HeaderComponent>;
24
+
25
+ export const LoggedIn: Story = {
26
+ args: {
27
+ user: {
28
+ name: 'Jane Doe',
29
+ },
30
+ },
31
+ };
32
+
33
+ export const LoggedOut: Story = {};
@@ -0,0 +1,84 @@
1
+ import { Component } from '@angular/core';
2
+ import { CommonModule } from '@angular/common';
3
+
4
+ import { HeaderComponent } from './header.component';
5
+ import type { User } from './user';
6
+
7
+ @Component({
8
+ selector: 'storybook-page',
9
+ standalone: true,
10
+ imports: [CommonModule, HeaderComponent],
11
+ template: `
12
+ <article>
13
+ <storybook-header
14
+ [user]="user"
15
+ (onLogout)="doLogout()"
16
+ (onLogin)="doLogin()"
17
+ (onCreateAccount)="doCreateAccount()"
18
+ ></storybook-header>
19
+ <section class="storybook-page">
20
+ <h2>Pages in Storybook</h2>
21
+ <p>
22
+ We recommend building UIs with a
23
+ <a href="https://componentdriven.org" target="_blank" rel="noopener noreferrer">
24
+ <strong>component-driven</strong>
25
+ </a>
26
+ process starting with atomic components and ending with pages.
27
+ </p>
28
+ <p>
29
+ Render pages with mock data. This makes it easy to build and review page states without
30
+ needing to navigate to them in your app. Here are some handy patterns for managing page data
31
+ in Storybook:
32
+ </p>
33
+ <ul>
34
+ <li>
35
+ Use a higher-level connected component. Storybook helps you compose such data from the
36
+ "args" of child component stories
37
+ </li>
38
+ <li>
39
+ Assemble data in the page component from your services. You can mock these services out
40
+ using Storybook.
41
+ </li>
42
+ </ul>
43
+ <p>
44
+ Get a guided tutorial on component-driven development at
45
+ <a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer">
46
+ Storybook tutorials
47
+ </a>
48
+ . Read more in the
49
+ <a href="https://storybook.js.org/docs" target="_blank" rel="noopener noreferrer"> docs </a>
50
+ .
51
+ </p>
52
+ <div class="tip-wrapper">
53
+ <span class="tip">Tip</span> Adjust the width of the canvas with the
54
+ <svg width="10" height="10" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg">
55
+ <g fill="none" fillRule="evenodd">
56
+ <path
57
+ d="M1.5 5.2h4.8c.3 0 .5.2.5.4v5.1c-.1.2-.3.3-.4.3H1.4a.5.5 0 01-.5-.4V5.7c0-.3.2-.5.5-.5zm0-2.1h6.9c.3 0 .5.2.5.4v7a.5.5 0 01-1 0V4H1.5a.5.5 0 010-1zm0-2.1h9c.3 0 .5.2.5.4v9.1a.5.5 0 01-1 0V2H1.5a.5.5 0 010-1zm4.3 5.2H2V10h3.8V6.2z"
58
+ id="a"
59
+ fill="#999"
60
+ />
61
+ </g>
62
+ </svg>
63
+ Viewports addon in the toolbar
64
+ </div>
65
+ </section>
66
+ </article>
67
+ `,
68
+ styleUrls: ['./page.css'],
69
+ })
70
+ export class PageComponent {
71
+ user: User | null = null;
72
+
73
+ doLogout() {
74
+ this.user = null;
75
+ }
76
+
77
+ doLogin() {
78
+ this.user = { name: 'Jane Doe' };
79
+ }
80
+
81
+ doCreateAccount() {
82
+ this.user = { name: 'Jane Doe' };
83
+ }
84
+ }
@@ -0,0 +1,32 @@
1
+ import type { Meta, StoryObj } from '@storybook/angular-vite';
2
+ import { expect, userEvent, within } from 'storybook/test';
3
+
4
+ import { PageComponent } from './page.component';
5
+
6
+ const meta: Meta<PageComponent> = {
7
+ title: 'Example/Page',
8
+ component: PageComponent,
9
+ parameters: {
10
+ // More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
11
+ layout: 'fullscreen',
12
+ },
13
+ };
14
+
15
+ export default meta;
16
+ type Story = StoryObj<PageComponent>;
17
+
18
+ export const LoggedOut: Story = {};
19
+
20
+ // More on component testing: https://storybook.js.org/docs/writing-tests/interaction-testing
21
+ export const LoggedIn: Story = {
22
+ play: async ({ canvasElement }) => {
23
+ const canvas = within(canvasElement);
24
+ const loginButton = canvas.getByRole('button', { name: /Log in/i });
25
+ await expect(loginButton).toBeInTheDocument();
26
+ await userEvent.click(loginButton);
27
+ await expect(loginButton).not.toBeInTheDocument();
28
+
29
+ const logoutButton = canvas.getByRole('button', { name: /Log out/i });
30
+ await expect(logoutButton).toBeInTheDocument();
31
+ },
32
+ };
@@ -0,0 +1,3 @@
1
+ export interface User {
2
+ name: string;
3
+ }