Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Migrate CLI templates to CSF3 #19665

Merged
merged 4 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 36 additions & 27 deletions code/frameworks/angular/template/cli/Button.stories.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,52 @@
import type { Meta, StoryFn } from '@storybook/angular';
import type { Meta, StoryObj } from '@storybook/angular';
import Button from './button.component';

// More on default export: https://storybook.js.org/docs/angular/writing-stories/introduction#default-export
export default {
// More on how to set up stories at: https://storybook.js.org/docs/angular/writing-stories/introduction#default-export
const meta: Meta<Button> = {
title: 'Example/Button',
component: Button,
// More on component templates: https://storybook.js.org/docs/angular/writing-stories/introduction#using-args
render: (args: Button) => ({
props: {
backgroundColor: null,
...args,
},
}),
// More on argTypes: https://storybook.js.org/docs/angular/api/argtypes
argTypes: {
backgroundColor: { control: 'color' },
backgroundColor: {
control: 'color',
},
},
} as Meta;

// More on component templates: https://storybook.js.org/docs/angular/writing-stories/introduction#using-args
const Template: StoryFn<Button> = (args: Button) => {
return {
props: { backgroundColor: null, ...args },
};
};

export const Primary = Template.bind({});
// More on args: https://storybook.js.org/docs/angular/writing-stories/args
Primary.args = {
primary: true,
label: 'Button',
export default meta;
type Story = StoryObj<Button>;

// More on component templates: https://storybook.js.org/docs/angular/writing-stories/introduction#using-args
export const Primary: Story = {
args: {
primary: true,
label: 'Button',
},
};

export const Secondary = Template.bind({});
Secondary.args = {
label: 'Button',
export const Secondary: Story = {
args: {
label: 'Button',
},
};

export const Large = Template.bind({});
Large.args = {
size: 'large',
label: 'Button',
export const Large: Story = {
args: {
size: 'large',
label: 'Button',
},
};

export const Small = Template.bind({});
Small.args = {
size: 'small',
label: 'Button',
export const Small: Story = {
args: {
size: 'small',
label: 'Button',
},
};
24 changes: 12 additions & 12 deletions code/frameworks/angular/template/cli/Header.stories.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { moduleMetadata } from '@storybook/angular';
import type { Meta, StoryObj } from '@storybook/angular';
import { CommonModule } from '@angular/common';
import type { Meta, StoryFn } from '@storybook/angular';

import Button from './button.component';
import Header from './header.component';

export default {
const meta: Meta<Header> = {
title: 'Example/Header',
component: Header,
render: (args) => ({ props: args }),
decorators: [
moduleMetadata({
declarations: [Button],
Expand All @@ -18,18 +19,17 @@ export default {
// More on Story layout: https://storybook.js.org/docs/angular/configure/story-layout
layout: 'fullscreen',
},
} as Meta;
};

const Template: StoryFn<Header> = (args: Header) => ({
props: args,
});
export default meta;
type Story = StoryObj<Header>;

export const LoggedIn = Template.bind({});
LoggedIn.args = {
user: {
name: 'Jane Doe',
export const LoggedIn: Story = {
args: {
user: {
name: 'Jane Doe',
},
},
};

export const LoggedOut = Template.bind({});
LoggedOut.args = {};
export const LoggedOut: Story = {};
33 changes: 21 additions & 12 deletions code/frameworks/angular/template/cli/Page.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { StoryFn, Meta } from '@storybook/angular';
import type { Meta, StoryObj } from '@storybook/angular';
import { moduleMetadata } from '@storybook/angular';
import { within, userEvent } from '@storybook/testing-library';
import { CommonModule } from '@angular/common';
Expand All @@ -7,7 +7,7 @@ import Button from './button.component';
import Header from './header.component';
import Page from './page.component';

export default {
const meta: Meta<Page> = {
title: 'Example/Page',
component: Page,
parameters: {
Expand All @@ -20,18 +20,27 @@ export default {
imports: [CommonModule],
}),
],
} as Meta;
};

const Template: StoryFn<Page> = (args: Page) => ({
props: args,
});
export default meta;
type Story = StoryObj<Page>;

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

// More on interaction testing: https://storybook.js.org/docs/angular/writing-tests/interaction-testing
export const LoggedIn = Template.bind({});
LoggedIn.play = async ({ canvasElement }) => {
const canvas = within(canvasElement);
const loginButton = await canvas.getByRole('button', { name: /Log in/i });
await userEvent.click(loginButton);
export const LoggedIn: Story = {
render: (args: Page) => ({
props: args,
}),
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
await userEvent.click(loginButton);
},
};
62 changes: 33 additions & 29 deletions code/frameworks/ember/template/cli/1-Button.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,57 @@ import { linkTo } from '@storybook/addon-links';
// More on default export: https://storybook.js.org/docs/ember/writing-stories/introduction#default-export
export default {
title: 'Button',
render: (args) => ({
template: hbs`<button {{action onClick}}>{{label}}</button>`,
context: args,
}),
// More on argTypes: https://storybook.js.org/docs/ember/api/argtypes
argTypes: {
label: { control: 'text' },
},
};

// More on component templates: https://storybook.js.org/docs/ember/writing-stories/introduction#using-args
const Template = (args) => ({
template: hbs`<button {{action onClick}}>{{label}}</button>`,
context: args,
});

export const Text = Template.bind({});
// More on args: https://storybook.js.org/docs/ember/writing-stories/args
Text.args = {
label: 'Button',
onClick: action('onClick'),
export const Text = {
args: {
label: 'Button',
onClick: action('onClick'),
},
};

export const Emoji = Template.bind({});
Emoji.args = {
label: '😀 😎 👍 💯',
export const Emoji = {
args: {
label: '😀 😎 👍 💯',
},
};

export const TextWithAction = () => ({
template: hbs`
export const TextWithAction = {
render: () => ({
template: hbs`
<button {{action onClick}}>
Trigger Action
</button>
`,
context: {
onClick: () => action('This was clicked')(),
context: {
onClick: () => action('This was clicked')(),
},
}),
name: 'With an action',
parameters: {
notes: 'My notes on a button with emojis',
},
});

TextWithAction.storyName = 'With an action';
TextWithAction.parameters = { notes: 'My notes on a button with emojis' };
};

export const ButtonWithLinkToAnotherStory = () => ({
template: hbs`
export const ButtonWithLinkToAnotherStory = {
render: () => ({
template: hbs`
<button {{action onClick}}>
Go to Welcome Story
</button>
`,
context: {
onClick: linkTo('example-introduction--page'),
},
});

ButtonWithLinkToAnotherStory.storyName = 'button with link to another story';
context: {
onClick: linkTo('example-introduction--page'),
},
}),
name: 'button with link to another story',
};
46 changes: 46 additions & 0 deletions code/frameworks/nextjs/template/cli/ts/Button.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import type { Meta, StoryObj } from '@storybook/react';

import { Button } from './Button';

// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
const meta: Meta<typeof Button> = {
title: 'Example/Button',
component: Button,
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
argTypes: {
backgroundColor: {
control: 'color',
},
},
};

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

// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
export const Primary: Story = {
args: {
primary: true,
label: 'Button',
},
};

export const Secondary: Story = {
args: {
label: 'Button',
},
};

export const Large: Story = {
args: {
size: 'large',
label: 'Button',
},
};

export const Small: Story = {
args: {
size: 'small',
label: 'Button',
},
};
41 changes: 0 additions & 41 deletions code/frameworks/nextjs/template/cli/ts/Button.stories.tsx

This file was deleted.

24 changes: 24 additions & 0 deletions code/frameworks/nextjs/template/cli/ts/Header.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { Meta, StoryObj } from '@storybook/react';
import { Header } from './Header';

const meta: Meta<typeof Header> = {
title: 'Example/Header',
component: Header,
parameters: {
// More on Story layout: https://storybook.js.org/docs/react/configure/story-layout
layout: 'fullscreen',
},
};

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

export const LoggedIn: Story = {
args: {
user: {
name: 'Jane Doe',
},
},
};

export const LoggedOut: Story = {};
Loading