diff --git a/code/renderers/svelte/template/cli/Button.stories.js b/code/renderers/svelte/template/cli/js/Button.stories.js similarity index 69% rename from code/renderers/svelte/template/cli/Button.stories.js rename to code/renderers/svelte/template/cli/js/Button.stories.js index 1b9408a98b22..6377b5dda3dc 100644 --- a/code/renderers/svelte/template/cli/Button.stories.js +++ b/code/renderers/svelte/template/cli/js/Button.stories.js @@ -5,22 +5,8 @@ export default { title: 'Example/Button', component: Button, tags: ['docsPage'], - render: (args) => ({ - Component: Button, - props: args, - on: { - click: args.onClick, - }, - }), argTypes: { backgroundColor: { control: 'color' }, - label: { control: 'text' }, - onClick: { action: 'onClick' }, - primary: { control: 'boolean' }, - size: { - control: { type: 'select' }, - options: ['small', 'medium', 'large'], - }, }, }; diff --git a/code/renderers/svelte/template/cli/Button.svelte b/code/renderers/svelte/template/cli/js/Button.svelte similarity index 71% rename from code/renderers/svelte/template/cli/Button.svelte rename to code/renderers/svelte/template/cli/js/Button.svelte index 5a19ed6d6814..cdf77abadac7 100644 --- a/code/renderers/svelte/template/cli/Button.svelte +++ b/code/renderers/svelte/template/cli/js/Button.svelte @@ -1,6 +1,6 @@ diff --git a/code/renderers/svelte/template/cli/Header.stories.js b/code/renderers/svelte/template/cli/js/Header.stories.js similarity index 61% rename from code/renderers/svelte/template/cli/Header.stories.js rename to code/renderers/svelte/template/cli/js/Header.stories.js index 68494a3d2c8f..19b968fca930 100644 --- a/code/renderers/svelte/template/cli/Header.stories.js +++ b/code/renderers/svelte/template/cli/js/Header.stories.js @@ -5,24 +5,10 @@ export default { component: Header, // This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/7.0/svelte/writing-docs/docs-page tags: ['docsPage'], - render: (args) => ({ - Component: Header, - props: args, - on: { - login: args.onLogin, - logout: args.onLogout, - createAccount: args.onCreateAccount, - }, - }), parameters: { // More on how to position stories at: https://storybook.js.org/docs/7.0/svelte/configure/story-layout layout: 'fullscreen', }, - argTypes: { - onLogin: { action: 'onLogin' }, - onLogout: { action: 'onLogout' }, - onCreateAccount: { action: 'onCreateAccount' }, - }, }; export const LoggedIn = { diff --git a/code/renderers/svelte/template/cli/Header.svelte b/code/renderers/svelte/template/cli/js/Header.svelte similarity index 93% rename from code/renderers/svelte/template/cli/Header.svelte rename to code/renderers/svelte/template/cli/js/Header.svelte index 77b6007946bf..8350b35fd664 100644 --- a/code/renderers/svelte/template/cli/Header.svelte +++ b/code/renderers/svelte/template/cli/js/Header.svelte @@ -26,10 +26,12 @@ + fill="#FFF" + /> + fill="#555AB9" + /> @@ -41,8 +43,7 @@ Welcome, {user.name}! diff --git a/code/renderers/svelte/template/cli/ts/Header.stories.ts b/code/renderers/svelte/template/cli/ts/Header.stories.ts new file mode 100644 index 000000000000..94fd9ef7625a --- /dev/null +++ b/code/renderers/svelte/template/cli/ts/Header.stories.ts @@ -0,0 +1,26 @@ +import type { Meta, StoryObj } from '@storybook/svelte'; +import Header from './Header.svelte'; + +const meta: Meta
= { + title: 'Example/Header', + component: Header, + // This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/7.0/react/writing-docs/docs-page + tags: ['docsPage'], + parameters: { + // More on how to position stories at: https://storybook.js.org/docs/7.0/svelte/configure/story-layout + layout: 'fullscreen', + }, +}; + +export default meta; +type Story = StoryObj
; + +export const LoggedIn: Story = { + args: { + user: { + name: 'Jane Doe', + }, + }, +}; + +export const LoggedOut: Story = {}; diff --git a/code/renderers/svelte/template/cli/ts/Header.svelte b/code/renderers/svelte/template/cli/ts/Header.svelte new file mode 100644 index 000000000000..e3b8d039f864 --- /dev/null +++ b/code/renderers/svelte/template/cli/ts/Header.svelte @@ -0,0 +1,52 @@ + + +
+
+
+ + + + + + + +

Acme

+
+
+ {#if user} + + Welcome, {user.name}! + +
+
+
diff --git a/code/renderers/svelte/template/cli/ts/Page.stories.ts b/code/renderers/svelte/template/cli/ts/Page.stories.ts new file mode 100644 index 000000000000..3ab9cc7c2ee6 --- /dev/null +++ b/code/renderers/svelte/template/cli/ts/Page.stories.ts @@ -0,0 +1,29 @@ +import type { Meta, StoryObj } from '@storybook/svelte'; +import { within, userEvent } from '@storybook/testing-library'; + +import Page from './Page.svelte'; + +const meta: Meta = { + title: 'Example/Page', + component: Page, + parameters: { + // More on how to position stories at: https://storybook.js.org/docs/7.0/svelte/configure/story-layout + layout: 'fullscreen', + }, +}; + +export default meta; +type Story = StoryObj; + +export const LoggedOut: Story = {}; + +// More on interaction testing: https://storybook.js.org/docs/7.0/svelte/writing-tests/interaction-testing +export const LoggedIn: Story = { + play: async ({ canvasElement }) => { + const canvas = within(canvasElement); + const loginButton = await canvas.getByRole('button', { + name: /Log in/i, + }); + await userEvent.click(loginButton); + }, +}; diff --git a/code/renderers/svelte/template/cli/ts/Page.svelte b/code/renderers/svelte/template/cli/ts/Page.svelte new file mode 100644 index 000000000000..c2c6369f565e --- /dev/null +++ b/code/renderers/svelte/template/cli/ts/Page.svelte @@ -0,0 +1,70 @@ + + +
+
(user = { name: 'Jane Doe' })} + on:logout={() => (user = null)} + on:createAccount={() => (user = { name: 'Jane Doe' })} + /> + +
+

Pages in Storybook

+

+ We recommend building UIs with a + + component-driven + + process starting with atomic components and ending with pages. +

+

+ Render pages with mock data. This makes it easy to build and review page states without + needing to navigate to them in your app. Here are some handy patterns for managing page data + in Storybook: +

+
    +
  • + Use a higher-level connected component. Storybook helps you compose such data from the + "args" of child component stories +
  • +
  • + Assemble data in the page component from your services. You can mock these services out + using Storybook. +
  • +
+

+ Get a guided tutorial on component-driven development at + + Storybook tutorials + + . Read more in the + docs + . +

+
+ Tip + Adjust the width of the canvas with the + + + + + + Viewports addon in the toolbar +
+
+