CLI: use CSF for svelete during initialization

This commit is contained in:
Clément DUNGLER 2021-03-27 20:50:54 +01:00
parent 6a937b6d03
commit e2fe77dff9
6 changed files with 116 additions and 107 deletions

View File

@ -1,46 +0,0 @@
import Button from './Button.svelte';
export default {
title: 'Example/Button',
component: Button,
argTypes: {
label: { control: 'text' },
primary: { control: 'boolean' },
backgroundColor: { control: 'color' },
size: {
control: { type: 'select', options: ['small', 'medium', 'large'] },
},
onClick: { action: 'onClick' },
},
};
const Template = ({ onClick, ...args }) => ({
Component: Button,
props: args,
on: {
click: onClick,
},
});
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

@ -0,0 +1,52 @@
<script>
import { Meta, Template, Story } from "@storybook/addon-svelte-csf";
import Button from "./Button.svelte";
</script>
<Meta
title="Example/Button"
component={Button}
argTypes={{
label: { control: "text" },
primary: { control: "boolean" },
backgroundColor: { control: "color" },
size: {
control: { type: "select", options: ["small", "medium", "large"] },
},
onClick: { action: "onClick" },
}}
/>
<Template let:args>
<Button {...args} on:click={args.onClick} />
</Template>
<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

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

View File

@ -0,0 +1,32 @@
<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

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

View File

@ -0,0 +1,32 @@
<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={{}} />