mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-31 05:03:21 +08:00
CLI/Svelte: Convert stories from svelte-native to CSF
This commit is contained in:
parent
93996983b5
commit
f1734b6d77
51
lib/cli/src/frameworks/svelte/Button.stories.js
Normal file
51
lib/cli/src/frameworks/svelte/Button.stories.js
Normal 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',
|
||||
};
|
@ -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",
|
||||
}}
|
||||
/>
|
29
lib/cli/src/frameworks/svelte/Header.stories.js
Normal file
29
lib/cli/src/frameworks/svelte/Header.stories.js
Normal 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 = {};
|
@ -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={{}} />
|
29
lib/cli/src/frameworks/svelte/Page.stories.js
Normal file
29
lib/cli/src/frameworks/svelte/Page.stories.js
Normal 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 = {};
|
@ -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={{}} />
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user