Skip to content

Commit 40517d7

Browse files
valentinpalkovicstorybook-bot
authored andcommitted
Merge pull request #25152 from Marklb/marklb/update-ng-cli-templates
Angular: Update Angular cli templates (cherry picked from commit 986f86b)
1 parent 3c54e1a commit 40517d7

File tree

9 files changed

+36
-51
lines changed

9 files changed

+36
-51
lines changed

code/e2e-tests/json-files.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test.describe('JSON files', () => {
2323
entries: expect.objectContaining({
2424
'example-button--primary': expect.objectContaining({
2525
id: 'example-button--primary',
26-
importPath: expect.stringContaining('Button.stories'),
26+
importPath: expect.stringMatching(/button\.stories/i),
2727
name: 'Primary',
2828
title: 'Example/Button',
2929
type: 'story',

code/frameworks/angular/template/cli/User.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

code/frameworks/angular/template/cli/button.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Component, Input, Output, EventEmitter } from '@angular/core';
33

44
@Component({
55
selector: 'storybook-button',
6+
standalone: true,
67
imports: [CommonModule],
78
template: ` <button
89
type="button"
@@ -14,7 +15,7 @@ import { Component, Input, Output, EventEmitter } from '@angular/core';
1415
</button>`,
1516
styleUrls: ['./button.css'],
1617
})
17-
export default class ButtonComponent {
18+
export class ButtonComponent {
1819
/**
1920
* Is this the principal call to action on the page?
2021
*/

code/frameworks/angular/template/cli/Button.stories.ts renamed to code/frameworks/angular/template/cli/button.stories.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import type { Meta, StoryObj } from '@storybook/angular';
2-
import Button from './button.component';
2+
3+
import { ButtonComponent } from './button.component';
34

45
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
5-
const meta: Meta<Button> = {
6+
const meta: Meta<ButtonComponent> = {
67
title: 'Example/Button',
7-
component: Button,
8+
component: ButtonComponent,
89
tags: ['autodocs'],
9-
render: (args: Button) => ({
10+
render: (args: ButtonComponent) => ({
1011
props: {
1112
backgroundColor: null,
1213
...args,
@@ -20,7 +21,7 @@ const meta: Meta<Button> = {
2021
};
2122

2223
export default meta;
23-
type Story = StoryObj<Button>;
24+
type Story = StoryObj<ButtonComponent>;
2425

2526
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
2627
export const Primary: Story = {

code/frameworks/angular/template/cli/header.component.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import { Component, Input, Output, EventEmitter } from '@angular/core';
2-
import type { User } from './User';
2+
import { CommonModule } from '@angular/common';
3+
4+
import { ButtonComponent } from './button.component';
5+
import type { User } from './user';
36

47
@Component({
58
selector: 'storybook-header',
9+
standalone: true,
10+
imports: [CommonModule, ButtonComponent],
611
template: `<header>
712
<div class="storybook-header">
813
<div>
@@ -47,9 +52,8 @@ import type { User } from './User';
4752
></storybook-button>
4853
<storybook-button
4954
*ngIf="!user"
50-
primary
5155
size="small"
52-
primary="true"
56+
[primary]="true"
5357
class="margin-left"
5458
(onClick)="onCreateAccount.emit($event)"
5559
label="Sign up"
@@ -60,7 +64,7 @@ import type { User } from './User';
6064
</header>`,
6165
styleUrls: ['./header.css'],
6266
})
63-
export default class HeaderComponent {
67+
export class HeaderComponent {
6468
@Input()
6569
user: User | null = null;
6670

code/frameworks/angular/template/cli/Header.stories.ts renamed to code/frameworks/angular/template/cli/header.stories.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
1-
import { moduleMetadata } from '@storybook/angular';
21
import type { Meta, StoryObj } from '@storybook/angular';
3-
import { CommonModule } from '@angular/common';
42

5-
import Button from './button.component';
6-
import Header from './header.component';
3+
import { HeaderComponent } from './header.component';
74

8-
const meta: Meta<Header> = {
5+
const meta: Meta<HeaderComponent> = {
96
title: 'Example/Header',
10-
component: Header,
7+
component: HeaderComponent,
118
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
129
tags: ['autodocs'],
13-
render: (args) => ({ props: args }),
14-
decorators: [
15-
moduleMetadata({
16-
declarations: [Button],
17-
imports: [CommonModule],
18-
}),
19-
],
2010
parameters: {
2111
// More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
2212
layout: 'fullscreen',
2313
},
2414
};
2515

2616
export default meta;
27-
type Story = StoryObj<Header>;
17+
type Story = StoryObj<HeaderComponent>;
2818

2919
export const LoggedIn: Story = {
3020
args: {

code/frameworks/angular/template/cli/page.component.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import { Component } from '@angular/core';
2-
import type { User } from './User';
2+
import { CommonModule } from '@angular/common';
3+
4+
import { HeaderComponent } from './header.component';
5+
import type { User } from './user';
36

47
@Component({
58
selector: 'storybook-page',
9+
standalone: true,
10+
imports: [CommonModule, HeaderComponent],
611
template: `<article>
712
<storybook-header
813
[user]="user"
@@ -60,7 +65,7 @@ import type { User } from './User';
6065
</article>`,
6166
styleUrls: ['./page.css'],
6267
})
63-
export default class PageComponent {
68+
export class PageComponent {
6469
user: User | null = null;
6570

6671
doLogout() {

code/frameworks/angular/template/cli/Page.stories.ts renamed to code/frameworks/angular/template/cli/page.stories.ts

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,24 @@
11
import type { Meta, StoryObj } from '@storybook/angular';
2-
import { moduleMetadata } from '@storybook/angular';
3-
import { CommonModule } from '@angular/common';
42
import { within, userEvent, expect } from '@storybook/test';
53

6-
import Button from './button.component';
7-
import Header from './header.component';
8-
import Page from './page.component';
4+
import { PageComponent } from './page.component';
95

10-
const meta: Meta<Page> = {
6+
const meta: Meta<PageComponent> = {
117
title: 'Example/Page',
12-
component: Page,
8+
component: PageComponent,
139
parameters: {
1410
// More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
1511
layout: 'fullscreen',
1612
},
17-
decorators: [
18-
moduleMetadata({
19-
declarations: [Button, Header],
20-
imports: [CommonModule],
21-
}),
22-
],
2313
};
2414

2515
export default meta;
26-
type Story = StoryObj<Page>;
16+
type Story = StoryObj<PageComponent>;
2717

28-
export const LoggedOut: Story = {
29-
render: (args: Page) => ({
30-
props: args,
31-
}),
32-
};
18+
export const LoggedOut: Story = {};
3319

3420
// More on interaction testing: https://storybook.js.org/docs/writing-tests/interaction-testing
3521
export const LoggedIn: Story = {
36-
render: (args: Page) => ({
37-
props: args,
38-
}),
3922
play: async ({ canvasElement }) => {
4023
const canvas = within(canvasElement);
4124
const loginButton = canvas.getByRole('button', { name: /Log in/i });
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface User {
2+
name: string;
3+
}

0 commit comments

Comments
 (0)