CLI/Svelte: Convert stories from svelte-native to CSF

This commit is contained in:
Michael Shilman 2022-01-27 00:49:35 +08:00
parent 93996983b5
commit f1734b6d77
7 changed files with 109 additions and 122 deletions

View File

@ -0,0 +1,51 @@
import Button from './Button.svelte';
// More on default export: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
// More on argTypes: https://storybook.js.org/docs/svelte/api/argtypes
export default {
title: 'Example/Button',
component: Button,
argTypes: {
backgroundColor: { control: 'color' },
label: { control: 'text' },
onClick: { action: 'onClick' },
primary: { control: 'boolean' },
size: {
control: { type: 'select' },
options: ['small', 'medium', 'large'],
},
},
};
// More on component templates: https://storybook.js.org/docs/svelte/writing-stories/introduction#using-args
const Template = (args) => ({
Component: Button,
props: args,
on: {
click: args.onClick,
},
});
// More on args: https://storybook.js.org/docs/svelte/writing-stories/args
export const Primary = Template.bind({});
Primary.args = {
primary: true,
label: 'Button',
};
export const Secondary = Template.bind({});
Secondary.args = {
label: 'Button',
};
export const Large = Template.bind({});
Large.args = {
size: 'large',
label: 'Button',
};
export const Small = Template.bind({});
Small.args = {
size: 'small',
label: 'Button',
};

View File

@ -1,57 +0,0 @@
<script>
import { Meta, Template, Story } from "@storybook/addon-svelte-csf";
import Button from "./Button.svelte";
</script>
<!-- More on default export: https://storybook.js.org/docs/react/writing-stories/introduction#default-export -->
<!-- More on argTypes: https://storybook.js.org/docs/svelte/api/argtypes -->
<Meta
title="Example/Button"
component={Button}
argTypes={{
backgroundColor: { control: "color" },
label: { control: "text" },
onClick: { action: "onClick" },
primary: { control: "boolean" },
size: {
control: { type: 'select' },
options: ['small', 'medium', 'large'],
},
}}
/>
<!-- More on component templates: https://storybook.js.org/docs/svelte/writing-stories/introduction#using-args -->
<Template let:args>
<Button {...args} on:click={args.onClick} />
</Template>
<!-- More on args: https://storybook.js.org/docs/svelte/writing-stories/args -->
<Story
name="Primary"
args={{
primary: true,
label: "Button",
}}
/>
<Story
name="Secondary"
args={{
label: "Button",
}}
/>
<Story
name="Large"
args={{
size: "large",
label: "Button",
}}
/>
<Story
name="Small"
args={{
size: "small",
label: "Button",
}}
/>

View File

@ -0,0 +1,29 @@
import Header from './Header.svelte';
export default {
title: 'Example/Header',
component: Header,
argTypes: {
onLogin: { action: 'onLogin' },
onLogout: { action: 'onLogout' },
onCreateAccount: { action: 'onCreateAccount' },
},
};
const Template = (args) => ({
Component: Header,
props: args,
on: {
login: args.onLogin,
logout: args.onLogout,
createAccount: args.onCreateAccount,
},
});
export const LoggedIn = Template.bind({});
LoggedIn.args = {
user: {},
};
export const LoggedOut = Template.bind({});
LoggedOut.args = {};

View File

@ -1,32 +0,0 @@
<script>
import { Meta, Template, Story } from "@storybook/addon-svelte-csf";
import Header from "./Header.svelte";
</script>
<Meta
title="Example/Header"
component={Header}
argTypes={{
onLogin: { action: "onLogin" },
onLogout: { action: "onLogout" },
onCreateAccount: { action: "onCreateAccount" },
}}
/>
<Template let:args>
<Header
{...args}
on:login={args.onLogin}
on:logout={args.onLogout}
on:createAccount={args.onCreateAccount}
/>
</Template>
<Story
name="LoggedIn"
args={{
user: {},
}}
/>
<Story name="LoggedOut" args={{}} />

View File

@ -0,0 +1,29 @@
import Page from './Page.svelte';
export default {
title: 'Example/Page',
component: Page,
argTypes: {
onLogin: { action: 'onLogin' },
onLogout: { action: 'onLogout' },
onCreateAccount: { action: 'onCreateAccount' },
},
};
const Template = (args) => ({
Component: Page,
props: args,
on: {
login: args.onLogin,
logout: args.onLogout,
createAccount: args.onCreateAccount,
},
});
export const LoggedIn = Template.bind({});
LoggedIn.args = {
user: {},
};
export const LoggedOut = Template.bind({});
LoggedOut.args = {};

View File

@ -1,32 +0,0 @@
<script>
import { Meta, Template, Story } from "@storybook/addon-svelte-csf";
import Page from "./Page.svelte";
</script>
<Meta
title="Example/Page"
component={Page}
argTypes={{
onLogin: { action: "onLogin" },
onLogout: { action: "onLogout" },
onCreateAccount: { action: "onCreateAccount" },
}}
/>
<Template let:args>
<Page
{...args}
on:login={args.onLogin}
on:logout={args.onLogout}
on:createAccount={args.onCreateAccount}
/>
</Template>
<Story
name="LoggedIn"
args={{
user: {},
}}
/>
<Story name="LoggedOut" args={{}} />

View File

@ -35,7 +35,6 @@ const generator: Generator = async (packageManager, npmOptions, options) => {
await baseGenerator(packageManager, npmOptions, options, 'svelte', {
extraPackages: ['svelte', 'svelte-loader'],
extraAddons: ['@storybook/addon-svelte-csf'],
extensions: ['js', 'jsx', 'ts', 'tsx', 'svelte'],
extraMain,
commonJs,