@storybook/svelte 9.0.0-alpha.13 → 9.0.0-alpha.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-2IXN2SLZ.mjs +11 -0
- package/dist/components/AddStorybookIdDecorator.svelte +3 -3
- package/dist/components/DecoratorHandler.svelte +20 -0
- package/dist/components/PreviewRender.svelte +14 -41
- package/dist/{createSvelte5Props.svelte.js → createReactiveProps.svelte.js} +1 -1
- package/dist/entry-preview-docs.js +1 -1
- package/dist/entry-preview-docs.mjs +3 -3
- package/dist/entry-preview.d.ts +1 -1
- package/dist/entry-preview.js +1 -1
- package/dist/entry-preview.mjs +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +3 -3
- package/package.json +6 -6
- package/template/cli/{svelte-5-ts-4-9 → js}/Button.stories.svelte +1 -1
- package/template/cli/js/Button.svelte +11 -20
- package/template/cli/js/Header.svelte +12 -17
- package/template/cli/js/Page.svelte +4 -4
- package/template/cli/{svelte-5-js → ts-4-9}/Button.stories.svelte +1 -1
- package/template/cli/ts-4-9/Button.svelte +17 -21
- package/template/cli/ts-4-9/Header.svelte +10 -17
- package/template/cli/ts-4-9/Page.svelte +4 -4
- package/template/stories/args.stories.js +21 -10
- package/template/stories/{slot-decorators.stories.js → decorators.stories.js} +21 -8
- package/dist/chunk-XMMNDRKT.mjs +0 -12
- package/dist/components/SlotDecorator.svelte +0 -50
- package/template/cli/js/Button.stories.js +0 -43
- package/template/cli/js/Header.stories.js +0 -22
- package/template/cli/js/Page.stories.js +0 -28
- package/template/cli/svelte-5-js/Button.svelte +0 -26
- package/template/cli/svelte-5-js/Header.svelte +0 -47
- package/template/cli/svelte-5-js/Page.svelte +0 -70
- package/template/cli/svelte-5-ts-3-8/Button.stories.svelte +0 -31
- package/template/cli/svelte-5-ts-3-8/Button.svelte +0 -29
- package/template/cli/svelte-5-ts-3-8/Header.svelte +0 -45
- package/template/cli/svelte-5-ts-3-8/Page.svelte +0 -70
- package/template/cli/svelte-5-ts-4-9/Button.svelte +0 -29
- package/template/cli/svelte-5-ts-4-9/Header.stories.svelte +0 -26
- package/template/cli/svelte-5-ts-4-9/Header.svelte +0 -45
- package/template/cli/svelte-5-ts-4-9/Page.stories.svelte +0 -30
- package/template/cli/svelte-5-ts-4-9/Page.svelte +0 -70
- package/template/cli/ts-4-9/Button.stories.ts +0 -48
- package/template/cli/ts-4-9/Header.stories.ts +0 -27
- package/template/cli/ts-4-9/Page.stories.ts +0 -33
- package/template/stories/decorators-runs-once.stories.js +0 -16
- package/template/stories/docs-jsdoc.stories.js +0 -9
- /package/template/cli/{svelte-5-js → js}/Header.stories.svelte +0 -0
- /package/template/cli/{svelte-5-js → js}/Page.stories.svelte +0 -0
- /package/template/cli/{svelte-5-ts-3-8 → ts-4-9}/Header.stories.svelte +0 -0
- /package/template/cli/{svelte-5-ts-3-8 → ts-4-9}/Page.stories.svelte +0 -0
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { expect, fn } from 'storybook/test';
|
|
2
|
+
|
|
3
|
+
import BorderDecoratorBlue from './BorderDecoratorBlue.svelte';
|
|
4
|
+
import BorderDecoratorProps from './BorderDecoratorProps.svelte';
|
|
5
|
+
import BorderDecoratorRed from './BorderDecoratorRed.svelte';
|
|
6
|
+
import Button from './Button.svelte';
|
|
5
7
|
|
|
6
8
|
export default {
|
|
7
|
-
component:
|
|
9
|
+
component: Button,
|
|
8
10
|
decorators: [() => BorderDecoratorRed],
|
|
9
|
-
args: {
|
|
10
|
-
primary: true,
|
|
11
|
-
},
|
|
12
11
|
tags: ['autodocs'],
|
|
13
12
|
};
|
|
14
13
|
|
|
@@ -41,3 +40,17 @@ export const WithArgsBasedBorder = {
|
|
|
41
40
|
...WithArgsBasedBorderUnset,
|
|
42
41
|
args: { color: 'lightblue' },
|
|
43
42
|
};
|
|
43
|
+
|
|
44
|
+
const decoratorCalled = fn();
|
|
45
|
+
|
|
46
|
+
export const DecoratorsRunOnce = {
|
|
47
|
+
decorators: [
|
|
48
|
+
(Story) => {
|
|
49
|
+
decoratorCalled();
|
|
50
|
+
return Story();
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
play: async () => {
|
|
54
|
+
expect(decoratorCalled).toHaveBeenCalledTimes(1);
|
|
55
|
+
},
|
|
56
|
+
};
|
package/dist/chunk-XMMNDRKT.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { __export } from './chunk-CEH6MNVV.mjs';
|
|
2
|
-
import { RESET_STORY_ARGS } from 'storybook/internal/core-events';
|
|
3
|
-
import PreviewRender from '@storybook/svelte/internal/PreviewRender.svelte';
|
|
4
|
-
import { createSvelte5Props } from '@storybook/svelte/internal/createSvelte5Props';
|
|
5
|
-
import { addons, sanitizeStoryContextUpdate } from 'storybook/preview-api';
|
|
6
|
-
import * as svelte from 'svelte';
|
|
7
|
-
import { VERSION } from 'svelte/compiler';
|
|
8
|
-
import SlotDecorator from '@storybook/svelte/internal/SlotDecorator.svelte';
|
|
9
|
-
|
|
10
|
-
var entry_preview_exports={};__export(entry_preview_exports,{applyDecorators:()=>decorateStory,mount:()=>mount2,parameters:()=>parameters,render:()=>render,renderToCanvas:()=>renderToCanvas});var IS_SVELTE_V4=Number(VERSION[0])<=4;function renderToCanvas(renderContext,canvasElement){return IS_SVELTE_V4?renderToCanvasV4(renderContext,canvasElement):renderToCanvasV5(renderContext,canvasElement)}var storyIdsToRemountFromResetArgsEvent=new Set;addons.getChannel().on(RESET_STORY_ARGS,({storyId})=>{storyIdsToRemountFromResetArgsEvent.add(storyId);});var componentsByDomElementV4=new Map;function renderToCanvasV4({storyFn,title,name,showMain,showError,storyContext,forceRemount},canvasElement){function unmount2(canvasElementToUnmount){componentsByDomElementV4.has(canvasElementToUnmount)&&(componentsByDomElementV4.get(canvasElementToUnmount).$destroy(),componentsByDomElementV4.delete(canvasElementToUnmount),canvasElementToUnmount.innerHTML="");}let existingComponent=componentsByDomElementV4.get(canvasElement),remount=forceRemount;if(storyIdsToRemountFromResetArgsEvent.has(storyContext.id)&&(remount=!0,storyIdsToRemountFromResetArgsEvent.delete(storyContext.id)),remount&&unmount2(canvasElement),!existingComponent||remount){let mountedComponent=new PreviewRender({target:canvasElement,props:{storyFn,storyContext,name,title,showError}});componentsByDomElementV4.set(canvasElement,mountedComponent);}else existingComponent.$set({storyFn,storyContext,name,title,showError});return showMain(),()=>{unmount2(canvasElement);}}var componentsByDomElementV5=new Map;function renderToCanvasV5({storyFn,title,name,showMain,showError,storyContext,forceRemount},canvasElement){function unmount2(canvasElementToUnmount){let{mountedComponent}=componentsByDomElementV5.get(canvasElementToUnmount)??{};mountedComponent&&(svelte.unmount(mountedComponent),componentsByDomElementV5.delete(canvasElementToUnmount));}let existingComponent=componentsByDomElementV5.get(canvasElement),remount=forceRemount;if(storyIdsToRemountFromResetArgsEvent.has(storyContext.id)&&(remount=!0,storyIdsToRemountFromResetArgsEvent.delete(storyContext.id)),remount&&unmount2(canvasElement),!existingComponent||remount){let props=createSvelte5Props({storyFn,storyContext,name,title,showError}),mountedComponent=svelte.mount(PreviewRender,{target:canvasElement,props});componentsByDomElementV5.set(canvasElement,{mountedComponent,props});}else Object.assign(existingComponent.props,{storyFn,storyContext,name,title,showError});return showMain(),()=>{unmount2(canvasElement);}}var render=(args,context)=>{let{id,component:Component}=context;if(!Component)throw new Error(`Unable to render story ${id} as the component annotation is missing from the default export`);return {Component,props:args}};function unWrap(obj){return obj&&typeof obj=="object"&&"default"in obj?obj.default:obj}function prepareStory(context,rawStory,rawInnerStory){let story=unWrap(rawStory),innerStory=rawInnerStory&&unWrap(rawInnerStory),preparedStory;return !story||Object.keys(story).length===0?preparedStory={Component:context.component}:story.Component?preparedStory=story:preparedStory={Component:story},innerStory?{Component:SlotDecorator,props:{...innerStory,decorator:preparedStory}}:{...preparedStory,argTypes:context.argTypes}}function decorateStory(storyFn,decorators){return decorators.reduce((decorated,decorator)=>context=>{let story,decoratedStory=decorator(update=>(story=decorated({...context,...sanitizeStoryContextUpdate(update)}),story),context);return story||(story=decorated(context)),decoratedStory===story?story:prepareStory(context,decoratedStory,story)},context=>prepareStory(context,storyFn(context)))}var mount2=context=>async(Component,options)=>(Component&&(context.originalStoryFn=()=>({Component,props:options&&"props"in options?options?.props:options})),await context.renderToCanvas(),context.canvas);var parameters={renderer:"svelte"};
|
|
11
|
-
|
|
12
|
-
export { IS_SVELTE_V4, decorateStory, entry_preview_exports, mount2 as mount, parameters, render, renderToCanvas };
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { onMount } from 'svelte';
|
|
3
|
-
import { VERSION } from 'svelte/compiler';
|
|
4
|
-
|
|
5
|
-
export let decorator = undefined;
|
|
6
|
-
export let Component;
|
|
7
|
-
export let props = {};
|
|
8
|
-
export let on = undefined;
|
|
9
|
-
export let argTypes = undefined;
|
|
10
|
-
|
|
11
|
-
let instance;
|
|
12
|
-
let decoratorInstance;
|
|
13
|
-
|
|
14
|
-
const svelteVersion = VERSION[0];
|
|
15
|
-
|
|
16
|
-
/*
|
|
17
|
-
Svelte Docgen will create argTypes for events with the name 'event_eventName'
|
|
18
|
-
The Actions addon will convert these to args because they are type: 'action'
|
|
19
|
-
We need to filter these args out so they are not passed to the component
|
|
20
|
-
*/
|
|
21
|
-
let propsWithoutDocgenEvents;
|
|
22
|
-
$: propsWithoutDocgenEvents = Object.fromEntries(
|
|
23
|
-
Object.entries(props).filter(([key]) => !key.startsWith('event_'))
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
if (argTypes && svelteVersion < 5) {
|
|
27
|
-
const eventsFromArgTypes = Object.fromEntries(
|
|
28
|
-
Object.entries(argTypes)
|
|
29
|
-
.filter(([key, value]) => value.action && props[key] != null)
|
|
30
|
-
.map(([key, value]) => [value.action, props[key]])
|
|
31
|
-
);
|
|
32
|
-
// Attach Svelte event listeners in Svelte v4
|
|
33
|
-
// In Svelte v5 this is not possible anymore as instances are no longer classes with $on() properties, so it will be a no-op
|
|
34
|
-
onMount(() => {
|
|
35
|
-
Object.entries({ ...eventsFromArgTypes, ...on }).forEach(([eventName, eventCallback]) => {
|
|
36
|
-
// instance can be undefined if a decorator doesn't have a <slot/>
|
|
37
|
-
const inst = instance ?? decoratorInstance;
|
|
38
|
-
inst?.$on?.(eventName, eventCallback);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
</script>
|
|
43
|
-
|
|
44
|
-
{#if decorator}
|
|
45
|
-
<svelte:component this={decorator.Component} {...decorator.props} bind:this={decoratorInstance}>
|
|
46
|
-
<svelte:component this={Component} {...propsWithoutDocgenEvents} bind:this={instance} />
|
|
47
|
-
</svelte:component>
|
|
48
|
-
{:else}
|
|
49
|
-
<svelte:component this={Component} {...propsWithoutDocgenEvents} bind:this={instance} />
|
|
50
|
-
{/if}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import Button from './Button.svelte';
|
|
2
|
-
|
|
3
|
-
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
|
|
4
|
-
export default {
|
|
5
|
-
title: 'Example/Button',
|
|
6
|
-
component: Button,
|
|
7
|
-
tags: ['autodocs'],
|
|
8
|
-
argTypes: {
|
|
9
|
-
backgroundColor: { control: 'color' },
|
|
10
|
-
size: {
|
|
11
|
-
control: { type: 'select' },
|
|
12
|
-
options: ['small', 'medium', 'large'],
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
|
|
18
|
-
export const Primary = {
|
|
19
|
-
args: {
|
|
20
|
-
primary: true,
|
|
21
|
-
label: 'Button',
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const Secondary = {
|
|
26
|
-
args: {
|
|
27
|
-
label: 'Button',
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export const Large = {
|
|
32
|
-
args: {
|
|
33
|
-
size: 'large',
|
|
34
|
-
label: 'Button',
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export const Small = {
|
|
39
|
-
args: {
|
|
40
|
-
size: 'small',
|
|
41
|
-
label: 'Button',
|
|
42
|
-
},
|
|
43
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import Header from './Header.svelte';
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
title: 'Example/Header',
|
|
5
|
-
component: Header,
|
|
6
|
-
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
|
|
7
|
-
tags: ['autodocs'],
|
|
8
|
-
parameters: {
|
|
9
|
-
// More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
|
|
10
|
-
layout: 'fullscreen',
|
|
11
|
-
},
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export const LoggedIn = {
|
|
15
|
-
args: {
|
|
16
|
-
user: {
|
|
17
|
-
name: 'Jane Doe',
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export const LoggedOut = {};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { expect, userEvent, waitFor, within } from 'storybook/test';
|
|
2
|
-
|
|
3
|
-
import Page from './Page.svelte';
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
title: 'Example/Page',
|
|
7
|
-
component: Page,
|
|
8
|
-
parameters: {
|
|
9
|
-
// More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
|
|
10
|
-
layout: 'fullscreen',
|
|
11
|
-
},
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export const LoggedOut = {};
|
|
15
|
-
|
|
16
|
-
// More on component testing: https://storybook.js.org/docs/writing-tests/component-testing
|
|
17
|
-
export const LoggedIn = {
|
|
18
|
-
play: async ({ canvasElement }) => {
|
|
19
|
-
const canvas = within(canvasElement);
|
|
20
|
-
const loginButton = canvas.getByRole('button', { name: /Log in/i });
|
|
21
|
-
await expect(loginButton).toBeInTheDocument();
|
|
22
|
-
await userEvent.click(loginButton);
|
|
23
|
-
await waitFor(() => expect(loginButton).not.toBeInTheDocument());
|
|
24
|
-
|
|
25
|
-
const logoutButton = canvas.getByRole('button', { name: /Log out/i });
|
|
26
|
-
await expect(logoutButton).toBeInTheDocument();
|
|
27
|
-
},
|
|
28
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import './button.css';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @typedef {Object} Props
|
|
6
|
-
* @property {boolean} [primary] Is this the principal call to action on the page?
|
|
7
|
-
* @property {string} [backgroundColor] What background color to use
|
|
8
|
-
* @property {'small' | 'medium' | 'large'} [size] How large should the button be?
|
|
9
|
-
* @property {string} label Button contents
|
|
10
|
-
* @property {() => void} [onClick] The onclick event handler
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/** @type {Props} */
|
|
14
|
-
const { primary = false, backgroundColor, size = 'medium', label, onClick } = $props();
|
|
15
|
-
</script>
|
|
16
|
-
|
|
17
|
-
<button
|
|
18
|
-
type="button"
|
|
19
|
-
class={['storybook-button', `storybook-button--${size}`].join(' ')}
|
|
20
|
-
class:storybook-button--primary={primary}
|
|
21
|
-
class:storybook-button--secondary={!primary}
|
|
22
|
-
style:background-color={backgroundColor}
|
|
23
|
-
onclick={onClick}
|
|
24
|
-
>
|
|
25
|
-
{label}
|
|
26
|
-
</button>
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import './header.css';
|
|
3
|
-
import Button from './Button.svelte';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @typedef {Object} Props
|
|
7
|
-
* @property {{name: string}} [user] The user object
|
|
8
|
-
* @property {() => void} [onLogin] The login event handler
|
|
9
|
-
* @property {() => void} [onLogout] The logout event handler
|
|
10
|
-
* @property {() => void} [onCreateAccount] The account creation event handler
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/** @type {Props} */
|
|
14
|
-
const { user, onLogin, onLogout, onCreateAccount } = $props();
|
|
15
|
-
</script>
|
|
16
|
-
|
|
17
|
-
<header>
|
|
18
|
-
<div class="storybook-header">
|
|
19
|
-
<div>
|
|
20
|
-
<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
|
|
21
|
-
<g fill="none" fill-rule="evenodd">
|
|
22
|
-
<path
|
|
23
|
-
d="M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z"
|
|
24
|
-
fill="#FFF"
|
|
25
|
-
/>
|
|
26
|
-
<path
|
|
27
|
-
d="M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z"
|
|
28
|
-
fill="#555AB9"
|
|
29
|
-
/>
|
|
30
|
-
<path d="M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z" fill="#91BAF8" />
|
|
31
|
-
</g>
|
|
32
|
-
</svg>
|
|
33
|
-
<h1>Acme</h1>
|
|
34
|
-
</div>
|
|
35
|
-
<div>
|
|
36
|
-
{#if user}
|
|
37
|
-
<span class="welcome">
|
|
38
|
-
Welcome, <b>{user.name}</b>!
|
|
39
|
-
</span>
|
|
40
|
-
<Button size="small" onClick={onLogout} label="Log out" />
|
|
41
|
-
{:else}
|
|
42
|
-
<Button size="small" onClick={onLogin} label="Log in" />
|
|
43
|
-
<Button primary size="small" onClick={onCreateAccount} label="Sign up" />
|
|
44
|
-
{/if}
|
|
45
|
-
</div>
|
|
46
|
-
</div>
|
|
47
|
-
</header>
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import './page.css';
|
|
3
|
-
import Header from './Header.svelte';
|
|
4
|
-
|
|
5
|
-
let user = $state(null);
|
|
6
|
-
</script>
|
|
7
|
-
|
|
8
|
-
<article>
|
|
9
|
-
<Header
|
|
10
|
-
{user}
|
|
11
|
-
onLogin={() => (user = { name: 'Jane Doe' })}
|
|
12
|
-
onLogout={() => (user = null)}
|
|
13
|
-
onCreateAccount={() => (user = { name: 'Jane Doe' })}
|
|
14
|
-
/>
|
|
15
|
-
|
|
16
|
-
<section class="storybook-page">
|
|
17
|
-
<h2>Pages in Storybook</h2>
|
|
18
|
-
<p>
|
|
19
|
-
We recommend building UIs with a
|
|
20
|
-
<a
|
|
21
|
-
href="https://blog.hichroma.com/component-driven-development-ce1109d56c8e"
|
|
22
|
-
target="_blank"
|
|
23
|
-
rel="noopener noreferrer"
|
|
24
|
-
>
|
|
25
|
-
<strong>component-driven</strong>
|
|
26
|
-
</a>
|
|
27
|
-
process starting with atomic components and ending with pages.
|
|
28
|
-
</p>
|
|
29
|
-
<p>
|
|
30
|
-
Render pages with mock data. This makes it easy to build and review page states without
|
|
31
|
-
needing to navigate to them in your app. Here are some handy patterns for managing page data
|
|
32
|
-
in Storybook:
|
|
33
|
-
</p>
|
|
34
|
-
<ul>
|
|
35
|
-
<li>
|
|
36
|
-
Use a higher-level connected component. Storybook helps you compose such data from the
|
|
37
|
-
"args" of child component stories
|
|
38
|
-
</li>
|
|
39
|
-
<li>
|
|
40
|
-
Assemble data in the page component from your services. You can mock these services out
|
|
41
|
-
using Storybook.
|
|
42
|
-
</li>
|
|
43
|
-
</ul>
|
|
44
|
-
<p>
|
|
45
|
-
Get a guided tutorial on component-driven development at
|
|
46
|
-
<a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer">
|
|
47
|
-
Storybook tutorials
|
|
48
|
-
</a>
|
|
49
|
-
. Read more in the
|
|
50
|
-
<a href="https://storybook.js.org/docs" target="_blank" rel="noopener noreferrer">docs</a>
|
|
51
|
-
.
|
|
52
|
-
</p>
|
|
53
|
-
<div class="tip-wrapper">
|
|
54
|
-
<span class="tip">Tip</span>
|
|
55
|
-
Adjust the width of the canvas with the
|
|
56
|
-
<svg width="10" height="10" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg">
|
|
57
|
-
<g fill="none" fill-rule="evenodd">
|
|
58
|
-
<path
|
|
59
|
-
d="M1.5 5.2h4.8c.3 0 .5.2.5.4v5.1c-.1.2-.3.3-.4.3H1.4a.5.5 0
|
|
60
|
-
01-.5-.4V5.7c0-.3.2-.5.5-.5zm0-2.1h6.9c.3 0 .5.2.5.4v7a.5.5 0 01-1 0V4H1.5a.5.5 0
|
|
61
|
-
010-1zm0-2.1h9c.3 0 .5.2.5.4v9.1a.5.5 0 01-1 0V2H1.5a.5.5 0 010-1zm4.3 5.2H2V10h3.8V6.2z"
|
|
62
|
-
id="a"
|
|
63
|
-
fill="#999"
|
|
64
|
-
/>
|
|
65
|
-
</g>
|
|
66
|
-
</svg>
|
|
67
|
-
Viewports addon in the toolbar
|
|
68
|
-
</div>
|
|
69
|
-
</section>
|
|
70
|
-
</article>
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
<script module>
|
|
2
|
-
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
-
import Button from './Button.svelte';
|
|
4
|
-
import { fn } from 'storybook/test';
|
|
5
|
-
|
|
6
|
-
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
|
|
7
|
-
const { Story } = defineMeta({
|
|
8
|
-
title: 'Example/Button',
|
|
9
|
-
component: Button,
|
|
10
|
-
tags: ['autodocs'],
|
|
11
|
-
argTypes: {
|
|
12
|
-
backgroundColor: { control: 'color' },
|
|
13
|
-
size: {
|
|
14
|
-
control: { type: 'select' },
|
|
15
|
-
options: ['small', 'medium', 'large'],
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
args: {
|
|
19
|
-
onClick: fn(),
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
</script>
|
|
23
|
-
|
|
24
|
-
<!-- More on writing stories with args: https://storybook.js.org/docs/writing-stories/args -->
|
|
25
|
-
<Story name="Primary" args={{ primary: true, label: 'Button' }} />
|
|
26
|
-
|
|
27
|
-
<Story name="Secondary" args={{ label: 'Button' }} />
|
|
28
|
-
|
|
29
|
-
<Story name="Large" args={{ size: 'large', label: 'Button' }} />
|
|
30
|
-
|
|
31
|
-
<Story name="Small" args={{ size: 'small', label: 'Button' }} />
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import './button.css';
|
|
3
|
-
|
|
4
|
-
interface Props {
|
|
5
|
-
/** Is this the principal call to action on the page? */
|
|
6
|
-
primary?: boolean;
|
|
7
|
-
/** What background color to use */
|
|
8
|
-
backgroundColor?: string;
|
|
9
|
-
/** How large should the button be? */
|
|
10
|
-
size?: 'small' | 'medium' | 'large';
|
|
11
|
-
/** Button contents */
|
|
12
|
-
label: string;
|
|
13
|
-
/** The onclick event handler */
|
|
14
|
-
onClick?: () => void;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const { primary = false, backgroundColor, size = 'medium', label, onClick }: Props = $props();
|
|
18
|
-
</script>
|
|
19
|
-
|
|
20
|
-
<button
|
|
21
|
-
type="button"
|
|
22
|
-
class={['storybook-button', `storybook-button--${size}`].join(' ')}
|
|
23
|
-
class:storybook-button--primary={primary}
|
|
24
|
-
class:storybook-button--secondary={!primary}
|
|
25
|
-
style:background-color={backgroundColor}
|
|
26
|
-
onclick={onClick}
|
|
27
|
-
>
|
|
28
|
-
{label}
|
|
29
|
-
</button>
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import './header.css';
|
|
3
|
-
import Button from './Button.svelte';
|
|
4
|
-
|
|
5
|
-
interface Props {
|
|
6
|
-
user?: { name: string };
|
|
7
|
-
onLogin?: () => void;
|
|
8
|
-
onLogout?: () => void;
|
|
9
|
-
onCreateAccount?: () => void;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const { user, onLogin, onLogout, onCreateAccount }: Props = $props();
|
|
13
|
-
</script>
|
|
14
|
-
|
|
15
|
-
<header>
|
|
16
|
-
<div class="storybook-header">
|
|
17
|
-
<div>
|
|
18
|
-
<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
|
|
19
|
-
<g fill="none" fill-rule="evenodd">
|
|
20
|
-
<path
|
|
21
|
-
d="M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z"
|
|
22
|
-
fill="#FFF"
|
|
23
|
-
/>
|
|
24
|
-
<path
|
|
25
|
-
d="M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z"
|
|
26
|
-
fill="#555AB9"
|
|
27
|
-
/>
|
|
28
|
-
<path d="M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z" fill="#91BAF8" />
|
|
29
|
-
</g>
|
|
30
|
-
</svg>
|
|
31
|
-
<h1>Acme</h1>
|
|
32
|
-
</div>
|
|
33
|
-
<div>
|
|
34
|
-
{#if user}
|
|
35
|
-
<span class="welcome">
|
|
36
|
-
Welcome, <b>{user.name}</b>!
|
|
37
|
-
</span>
|
|
38
|
-
<Button size="small" onClick={onLogout} label="Log out" />
|
|
39
|
-
{:else}
|
|
40
|
-
<Button size="small" onClick={onLogin} label="Log in" />
|
|
41
|
-
<Button primary size="small" onClick={onCreateAccount} label="Sign up" />
|
|
42
|
-
{/if}
|
|
43
|
-
</div>
|
|
44
|
-
</div>
|
|
45
|
-
</header>
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import './page.css';
|
|
3
|
-
import Header from './Header.svelte';
|
|
4
|
-
|
|
5
|
-
let user = $state<{ name: string }>();
|
|
6
|
-
</script>
|
|
7
|
-
|
|
8
|
-
<article>
|
|
9
|
-
<Header
|
|
10
|
-
{user}
|
|
11
|
-
onLogin={() => (user = { name: 'Jane Doe' })}
|
|
12
|
-
onLogout={() => (user = undefined)}
|
|
13
|
-
onCreateAccount={() => (user = { name: 'Jane Doe' })}
|
|
14
|
-
/>
|
|
15
|
-
|
|
16
|
-
<section class="storybook-page">
|
|
17
|
-
<h2>Pages in Storybook</h2>
|
|
18
|
-
<p>
|
|
19
|
-
We recommend building UIs with a
|
|
20
|
-
<a
|
|
21
|
-
href="https://blog.hichroma.com/component-driven-development-ce1109d56c8e"
|
|
22
|
-
target="_blank"
|
|
23
|
-
rel="noopener noreferrer"
|
|
24
|
-
>
|
|
25
|
-
<strong>component-driven</strong>
|
|
26
|
-
</a>
|
|
27
|
-
process starting with atomic components and ending with pages.
|
|
28
|
-
</p>
|
|
29
|
-
<p>
|
|
30
|
-
Render pages with mock data. This makes it easy to build and review page states without
|
|
31
|
-
needing to navigate to them in your app. Here are some handy patterns for managing page data
|
|
32
|
-
in Storybook:
|
|
33
|
-
</p>
|
|
34
|
-
<ul>
|
|
35
|
-
<li>
|
|
36
|
-
Use a higher-level connected component. Storybook helps you compose such data from the
|
|
37
|
-
"args" of child component stories
|
|
38
|
-
</li>
|
|
39
|
-
<li>
|
|
40
|
-
Assemble data in the page component from your services. You can mock these services out
|
|
41
|
-
using Storybook.
|
|
42
|
-
</li>
|
|
43
|
-
</ul>
|
|
44
|
-
<p>
|
|
45
|
-
Get a guided tutorial on component-driven development at
|
|
46
|
-
<a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer">
|
|
47
|
-
Storybook tutorials
|
|
48
|
-
</a>
|
|
49
|
-
. Read more in the
|
|
50
|
-
<a href="https://storybook.js.org/docs" target="_blank" rel="noopener noreferrer">docs</a>
|
|
51
|
-
.
|
|
52
|
-
</p>
|
|
53
|
-
<div class="tip-wrapper">
|
|
54
|
-
<span class="tip">Tip</span>
|
|
55
|
-
Adjust the width of the canvas with the
|
|
56
|
-
<svg width="10" height="10" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg">
|
|
57
|
-
<g fill="none" fill-rule="evenodd">
|
|
58
|
-
<path
|
|
59
|
-
d="M1.5 5.2h4.8c.3 0 .5.2.5.4v5.1c-.1.2-.3.3-.4.3H1.4a.5.5 0
|
|
60
|
-
01-.5-.4V5.7c0-.3.2-.5.5-.5zm0-2.1h6.9c.3 0 .5.2.5.4v7a.5.5 0 01-1 0V4H1.5a.5.5 0
|
|
61
|
-
010-1zm0-2.1h9c.3 0 .5.2.5.4v9.1a.5.5 0 01-1 0V2H1.5a.5.5 0 010-1zm4.3 5.2H2V10h3.8V6.2z"
|
|
62
|
-
id="a"
|
|
63
|
-
fill="#999"
|
|
64
|
-
/>
|
|
65
|
-
</g>
|
|
66
|
-
</svg>
|
|
67
|
-
Viewports addon in the toolbar
|
|
68
|
-
</div>
|
|
69
|
-
</section>
|
|
70
|
-
</article>
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import './button.css';
|
|
3
|
-
|
|
4
|
-
interface Props {
|
|
5
|
-
/** Is this the principal call to action on the page? */
|
|
6
|
-
primary?: boolean;
|
|
7
|
-
/** What background color to use */
|
|
8
|
-
backgroundColor?: string;
|
|
9
|
-
/** How large should the button be? */
|
|
10
|
-
size?: 'small' | 'medium' | 'large';
|
|
11
|
-
/** Button contents */
|
|
12
|
-
label: string;
|
|
13
|
-
/** The onclick event handler */
|
|
14
|
-
onClick?: () => void;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const { primary = false, backgroundColor, size = 'medium', label, onClick }: Props = $props();
|
|
18
|
-
</script>
|
|
19
|
-
|
|
20
|
-
<button
|
|
21
|
-
type="button"
|
|
22
|
-
class={['storybook-button', `storybook-button--${size}`].join(' ')}
|
|
23
|
-
class:storybook-button--primary={primary}
|
|
24
|
-
class:storybook-button--secondary={!primary}
|
|
25
|
-
style:background-color={backgroundColor}
|
|
26
|
-
onclick={onClick}
|
|
27
|
-
>
|
|
28
|
-
{label}
|
|
29
|
-
</button>
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
<script module>
|
|
2
|
-
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
-
import Header from './Header.svelte';
|
|
4
|
-
import { fn } from 'storybook/test';
|
|
5
|
-
|
|
6
|
-
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
|
|
7
|
-
const { Story } = defineMeta({
|
|
8
|
-
title: 'Example/Header',
|
|
9
|
-
component: Header,
|
|
10
|
-
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
|
|
11
|
-
tags: ['autodocs'],
|
|
12
|
-
parameters: {
|
|
13
|
-
// More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
|
|
14
|
-
layout: 'fullscreen',
|
|
15
|
-
},
|
|
16
|
-
args: {
|
|
17
|
-
onLogin: fn(),
|
|
18
|
-
onLogout: fn(),
|
|
19
|
-
onCreateAccount: fn(),
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
</script>
|
|
23
|
-
|
|
24
|
-
<Story name="Logged In" args={{ user: { name: 'Jane Doe' } }} />
|
|
25
|
-
|
|
26
|
-
<Story name="Logged Out" />
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import './header.css';
|
|
3
|
-
import Button from './Button.svelte';
|
|
4
|
-
|
|
5
|
-
interface Props {
|
|
6
|
-
user?: { name: string };
|
|
7
|
-
onLogin?: () => void;
|
|
8
|
-
onLogout?: () => void;
|
|
9
|
-
onCreateAccount?: () => void;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const { user, onLogin, onLogout, onCreateAccount }: Props = $props();
|
|
13
|
-
</script>
|
|
14
|
-
|
|
15
|
-
<header>
|
|
16
|
-
<div class="storybook-header">
|
|
17
|
-
<div>
|
|
18
|
-
<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
|
|
19
|
-
<g fill="none" fill-rule="evenodd">
|
|
20
|
-
<path
|
|
21
|
-
d="M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z"
|
|
22
|
-
fill="#FFF"
|
|
23
|
-
/>
|
|
24
|
-
<path
|
|
25
|
-
d="M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z"
|
|
26
|
-
fill="#555AB9"
|
|
27
|
-
/>
|
|
28
|
-
<path d="M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z" fill="#91BAF8" />
|
|
29
|
-
</g>
|
|
30
|
-
</svg>
|
|
31
|
-
<h1>Acme</h1>
|
|
32
|
-
</div>
|
|
33
|
-
<div>
|
|
34
|
-
{#if user}
|
|
35
|
-
<span class="welcome">
|
|
36
|
-
Welcome, <b>{user.name}</b>!
|
|
37
|
-
</span>
|
|
38
|
-
<Button size="small" onClick={onLogout} label="Log out" />
|
|
39
|
-
{:else}
|
|
40
|
-
<Button size="small" onClick={onLogin} label="Log in" />
|
|
41
|
-
<Button primary size="small" onClick={onCreateAccount} label="Sign up" />
|
|
42
|
-
{/if}
|
|
43
|
-
</div>
|
|
44
|
-
</div>
|
|
45
|
-
</header>
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
<script module>
|
|
2
|
-
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
-
import { expect, userEvent, waitFor, within } from 'storybook/test';
|
|
4
|
-
import Page from './Page.svelte';
|
|
5
|
-
import { fn } from 'storybook/test';
|
|
6
|
-
|
|
7
|
-
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
|
|
8
|
-
const { Story } = defineMeta({
|
|
9
|
-
title: 'Example/Page',
|
|
10
|
-
component: Page,
|
|
11
|
-
parameters: {
|
|
12
|
-
// More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
|
|
13
|
-
layout: 'fullscreen',
|
|
14
|
-
},
|
|
15
|
-
});
|
|
16
|
-
</script>
|
|
17
|
-
|
|
18
|
-
<Story name="Logged In" play={async ({ canvasElement }) => {
|
|
19
|
-
const canvas = within(canvasElement);
|
|
20
|
-
const loginButton = canvas.getByRole('button', { name: /Log in/i });
|
|
21
|
-
await expect(loginButton).toBeInTheDocument();
|
|
22
|
-
await userEvent.click(loginButton);
|
|
23
|
-
await waitFor(() => expect(loginButton).not.toBeInTheDocument());
|
|
24
|
-
|
|
25
|
-
const logoutButton = canvas.getByRole('button', { name: /Log out/i });
|
|
26
|
-
await expect(logoutButton).toBeInTheDocument();
|
|
27
|
-
}}
|
|
28
|
-
/>
|
|
29
|
-
|
|
30
|
-
<Story name="Logged Out" />
|