Skip to content

Commit

Permalink
Merge pull request #25152 from Marklb/marklb/update-ng-cli-templates
Browse files Browse the repository at this point in the history
Angular: Update Angular cli templates
(cherry picked from commit 986f86b)
  • Loading branch information
valentinpalkovic authored and storybook-bot committed Dec 12, 2023
1 parent 3c54e1a commit fdb7382
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 51 deletions.
2 changes: 1 addition & 1 deletion code/e2e-tests/json-files.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test.describe('JSON files', () => {
entries: expect.objectContaining({
'example-button--primary': expect.objectContaining({
id: 'example-button--primary',
importPath: expect.stringContaining('Button.stories'),
importPath: expect.stringMatching(/button\.stories/i),
name: 'Primary',
title: 'Example/Button',
type: 'story',
Expand Down
2 changes: 0 additions & 2 deletions code/frameworks/angular/template/cli/User.ts

This file was deleted.

3 changes: 2 additions & 1 deletion code/frameworks/angular/template/cli/button.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Component, Input, Output, EventEmitter } from '@angular/core';

@Component({
selector: 'storybook-button',
standalone: true,
imports: [CommonModule],
template: ` <button
type="button"
Expand All @@ -14,7 +15,7 @@ import { Component, Input, Output, EventEmitter } from '@angular/core';
</button>`,
styleUrls: ['./button.css'],
})
export default class ButtonComponent {
export class ButtonComponent {
/**
* Is this the principal call to action on the page?
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type { Meta, StoryObj } from '@storybook/angular';
import Button from './button.component';

import { ButtonComponent } from './button.component';

// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
const meta: Meta<Button> = {
const meta: Meta<ButtonComponent> = {
title: 'Example/Button',
component: Button,
component: ButtonComponent,
tags: ['autodocs'],
render: (args: Button) => ({
render: (args: ButtonComponent) => ({
props: {
backgroundColor: null,
...args,
Expand All @@ -20,7 +21,7 @@ const meta: Meta<Button> = {
};

export default meta;
type Story = StoryObj<Button>;
type Story = StoryObj<ButtonComponent>;

// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
export const Primary: Story = {
Expand Down
12 changes: 8 additions & 4 deletions code/frameworks/angular/template/cli/header.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { Component, Input, Output, EventEmitter } from '@angular/core';
import type { User } from './User';
import { CommonModule } from '@angular/common';

import { ButtonComponent } from './button.component';
import type { User } from './user';

@Component({
selector: 'storybook-header',
standalone: true,
imports: [CommonModule, ButtonComponent],
template: `<header>
<div class="storybook-header">
<div>
Expand Down Expand Up @@ -47,9 +52,8 @@ import type { User } from './User';
></storybook-button>
<storybook-button
*ngIf="!user"
primary
size="small"
primary="true"
[primary]="true"
class="margin-left"
(onClick)="onCreateAccount.emit($event)"
label="Sign up"
Expand All @@ -60,7 +64,7 @@ import type { User } from './User';
</header>`,
styleUrls: ['./header.css'],
})
export default class HeaderComponent {
export class HeaderComponent {
@Input()
user: User | null = null;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
import { moduleMetadata } from '@storybook/angular';
import type { Meta, StoryObj } from '@storybook/angular';
import { CommonModule } from '@angular/common';

import Button from './button.component';
import Header from './header.component';
import { HeaderComponent } from './header.component';

const meta: Meta<Header> = {
const meta: Meta<HeaderComponent> = {
title: 'Example/Header',
component: Header,
component: HeaderComponent,
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
tags: ['autodocs'],
render: (args) => ({ props: args }),
decorators: [
moduleMetadata({
declarations: [Button],
imports: [CommonModule],
}),
],
parameters: {
// More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
layout: 'fullscreen',
},
};

export default meta;
type Story = StoryObj<Header>;
type Story = StoryObj<HeaderComponent>;

export const LoggedIn: Story = {
args: {
Expand Down
9 changes: 7 additions & 2 deletions code/frameworks/angular/template/cli/page.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { Component } from '@angular/core';
import type { User } from './User';
import { CommonModule } from '@angular/common';

import { HeaderComponent } from './header.component';
import type { User } from './user';

@Component({
selector: 'storybook-page',
standalone: true,
imports: [CommonModule, HeaderComponent],
template: `<article>
<storybook-header
[user]="user"
Expand Down Expand Up @@ -60,7 +65,7 @@ import type { User } from './User';
</article>`,
styleUrls: ['./page.css'],
})
export default class PageComponent {
export class PageComponent {
user: User | null = null;

doLogout() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,24 @@
import type { Meta, StoryObj } from '@storybook/angular';
import { moduleMetadata } from '@storybook/angular';
import { CommonModule } from '@angular/common';
import { within, userEvent, expect } from '@storybook/test';

import Button from './button.component';
import Header from './header.component';
import Page from './page.component';
import { PageComponent } from './page.component';

const meta: Meta<Page> = {
const meta: Meta<PageComponent> = {
title: 'Example/Page',
component: Page,
component: PageComponent,
parameters: {
// More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
layout: 'fullscreen',
},
decorators: [
moduleMetadata({
declarations: [Button, Header],
imports: [CommonModule],
}),
],
};

export default meta;
type Story = StoryObj<Page>;
type Story = StoryObj<PageComponent>;

export const LoggedOut: Story = {
render: (args: Page) => ({
props: args,
}),
};
export const LoggedOut: Story = {};

// More on interaction testing: https://storybook.js.org/docs/writing-tests/interaction-testing
export const LoggedIn: Story = {
render: (args: Page) => ({
props: args,
}),
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const loginButton = canvas.getByRole('button', { name: /Log in/i });
Expand Down
3 changes: 3 additions & 0 deletions code/frameworks/angular/template/cli/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface User {
name: string;
}

0 comments on commit fdb7382

Please sign in to comment.