@storybook/sveltekit 9.0.0-alpha.9 → 9.0.0-beta.0
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/package.json +9 -9
- package/template/cli/{svelte-5-ts-3-8 → 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/{svelte-5-js → js}/Page.stories.svelte +1 -1
- package/template/cli/js/Page.svelte +4 -4
- package/template/cli/{svelte-5-ts-4-9 → ts}/Button.stories.svelte +1 -1
- package/template/cli/{svelte-5-ts-3-8 → ts}/Button.svelte +8 -7
- package/template/cli/{svelte-5-ts-4-9 → ts}/Header.svelte +3 -3
- package/template/cli/{svelte-5-ts-4-9 → ts}/Page.stories.svelte +1 -1
- package/template/stories_svelte-kit-skeleton-ts/modules/environment.stories.js +8 -0
- package/template/{stories_svelte-kit-prerelease-ts → stories_svelte-kit-skeleton-ts/modules}/forms.stories.js +1 -2
- package/template/{stories_svelte-kit-skeleton-js → stories_svelte-kit-skeleton-ts/modules}/hrefs.stories.js +1 -2
- package/template/{stories_svelte-kit-prerelease-ts → stories_svelte-kit-skeleton-ts/modules}/navigation.stories.js +1 -2
- package/template/stories_svelte-kit-skeleton-ts/modules/paths.stories.js +8 -0
- package/template/{stories_svelte-kit-prerelease-ts → stories_svelte-kit-skeleton-ts/modules}/stores.stories.js +1 -2
- 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.stories.svelte +0 -31
- 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/Header.svelte +0 -45
- package/template/cli/svelte-5-ts-3-8/Page.stories.svelte +0 -30
- 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/Page.svelte +0 -70
- package/template/cli/ts-4-9/Button.stories.ts +0 -48
- package/template/cli/ts-4-9/Button.svelte +0 -34
- package/template/cli/ts-4-9/Header.stories.ts +0 -27
- package/template/cli/ts-4-9/Header.svelte +0 -52
- package/template/cli/ts-4-9/Page.stories.ts +0 -32
- package/template/cli/ts-4-9/Page.svelte +0 -70
- package/template/stories_svelte-kit-prerelease-ts/DocsJSDocRunes.svelte +0 -55
- package/template/stories_svelte-kit-prerelease-ts/DocsTSInlinePropTypes.svelte +0 -114
- package/template/stories_svelte-kit-prerelease-ts/DocsTSLegacy.svelte +0 -102
- package/template/stories_svelte-kit-prerelease-ts/DocsTSReferencedPropTypes.svelte +0 -118
- package/template/stories_svelte-kit-prerelease-ts/Forms.svelte +0 -7
- package/template/stories_svelte-kit-prerelease-ts/docs-jsdoc-runes.stories.js +0 -10
- package/template/stories_svelte-kit-prerelease-ts/docs-ts-inline-prop-types.stories.js +0 -10
- package/template/stories_svelte-kit-prerelease-ts/docs-ts-referenced-prop-types.stories.js +0 -10
- package/template/stories_svelte-kit-prerelease-ts/docs-ts.stories.js +0 -10
- package/template/stories_svelte-kit-prerelease-ts/hrefs.stories.js +0 -53
- package/template/stories_svelte-kit-prerelease-ts/types.ts +0 -7
- package/template/stories_svelte-kit-skeleton-js/Hrefs.svelte +0 -8
- package/template/stories_svelte-kit-skeleton-js/Navigation.svelte +0 -38
- package/template/stories_svelte-kit-skeleton-js/Stores.svelte +0 -17
- package/template/stories_svelte-kit-skeleton-js/environment.stories.js +0 -11
- package/template/stories_svelte-kit-skeleton-js/forms.stories.js +0 -27
- package/template/stories_svelte-kit-skeleton-js/navigation.stories.js +0 -121
- package/template/stories_svelte-kit-skeleton-js/paths.stories.js +0 -11
- package/template/stories_svelte-kit-skeleton-js/stores.stories.js +0 -116
- package/template/stories_svelte-kit-skeleton-ts/DocsTS.svelte +0 -97
- package/template/stories_svelte-kit-skeleton-ts/Environment.svelte +0 -8
- package/template/stories_svelte-kit-skeleton-ts/Forms.svelte +0 -7
- package/template/stories_svelte-kit-skeleton-ts/Hrefs.svelte +0 -8
- package/template/stories_svelte-kit-skeleton-ts/Navigation.svelte +0 -37
- package/template/stories_svelte-kit-skeleton-ts/Paths.svelte +0 -6
- package/template/stories_svelte-kit-skeleton-ts/Stores.svelte +0 -17
- package/template/stories_svelte-kit-skeleton-ts/docs-ts.stories.js +0 -10
- package/template/stories_svelte-kit-skeleton-ts/environment.stories.js +0 -11
- package/template/stories_svelte-kit-skeleton-ts/forms.stories.js +0 -27
- package/template/stories_svelte-kit-skeleton-ts/hrefs.stories.js +0 -53
- package/template/stories_svelte-kit-skeleton-ts/navigation.stories.js +0 -121
- package/template/stories_svelte-kit-skeleton-ts/paths.stories.js +0 -11
- package/template/stories_svelte-kit-skeleton-ts/stores.stories.js +0 -116
- package/template/stories_svelte-kit-skeleton-ts/types.ts +0 -7
- /package/template/cli/{svelte-5-js → js}/Header.stories.svelte +0 -0
- /package/template/cli/{svelte-5-ts-3-8 → ts}/Header.stories.svelte +0 -0
- /package/template/cli/{svelte-5-ts-3-8 → ts}/Page.svelte +0 -0
- /package/template/{stories_svelte-kit-skeleton-js → stories_svelte-kit-skeleton-ts/modules}/Environment.svelte +0 -0
- /package/template/{stories_svelte-kit-skeleton-js → stories_svelte-kit-skeleton-ts/modules}/Forms.svelte +0 -0
- /package/template/{stories_svelte-kit-prerelease-ts → stories_svelte-kit-skeleton-ts/modules}/Hrefs.svelte +0 -0
- /package/template/{stories_svelte-kit-prerelease-ts → stories_svelte-kit-skeleton-ts/modules}/Navigation.svelte +0 -0
- /package/template/{stories_svelte-kit-skeleton-js → stories_svelte-kit-skeleton-ts/modules}/Paths.svelte +0 -0
- /package/template/{stories_svelte-kit-prerelease-ts → stories_svelte-kit-skeleton-ts/modules}/Stores.svelte +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/sveltekit",
|
|
3
|
-
"version": "9.0.0-
|
|
3
|
+
"version": "9.0.0-beta.0",
|
|
4
4
|
"description": "Storybook for SvelteKit",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook",
|
|
@@ -65,22 +65,22 @@
|
|
|
65
65
|
"prep": "jiti ../../../scripts/prepare/bundle.ts"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@storybook/builder-vite": "9.0.0-
|
|
69
|
-
"@storybook/svelte": "9.0.0-
|
|
70
|
-
"@storybook/svelte-vite": "9.0.0-
|
|
68
|
+
"@storybook/builder-vite": "9.0.0-beta.0",
|
|
69
|
+
"@storybook/svelte": "9.0.0-beta.0",
|
|
70
|
+
"@storybook/svelte-vite": "9.0.0-beta.0"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@types/node": "^22.0.0",
|
|
74
74
|
"typescript": "^5.7.3",
|
|
75
|
-
"vite": "^
|
|
75
|
+
"vite": "^6.2.5"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
78
|
-
"storybook": "^9.0.0-
|
|
79
|
-
"svelte": "^
|
|
80
|
-
"vite": "^
|
|
78
|
+
"storybook": "^9.0.0-beta.0",
|
|
79
|
+
"svelte": "^5.0.0",
|
|
80
|
+
"vite": "^5.0.0 || ^6.0.0"
|
|
81
81
|
},
|
|
82
82
|
"engines": {
|
|
83
|
-
"node": ">=
|
|
83
|
+
"node": ">=20.0.0"
|
|
84
84
|
},
|
|
85
85
|
"publishConfig": {
|
|
86
86
|
"access": "public"
|
|
@@ -2,35 +2,26 @@
|
|
|
2
2
|
import './button.css';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
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
|
|
6
11
|
*/
|
|
7
|
-
export let primary = false;
|
|
8
12
|
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
*/
|
|
12
|
-
export let backgroundColor = undefined;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @type {'small' | 'medium' | 'large'} How large should the button be?
|
|
16
|
-
*/
|
|
17
|
-
export let size = 'medium';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @type {string} Button contents
|
|
21
|
-
*/
|
|
22
|
-
export let label;
|
|
23
|
-
|
|
24
|
-
$: mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
|
|
13
|
+
/** @type {Props} */
|
|
14
|
+
const { primary = false, backgroundColor, size = 'medium', label, ...props } = $props();
|
|
25
15
|
|
|
26
|
-
|
|
16
|
+
let mode = $derived(primary ? 'storybook-button--primary' : 'storybook-button--secondary');
|
|
17
|
+
let style = $derived(backgroundColor ? `background-color: ${backgroundColor}` : '');
|
|
27
18
|
</script>
|
|
28
19
|
|
|
29
20
|
<button
|
|
30
21
|
type="button"
|
|
31
22
|
class={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
|
|
32
23
|
{style}
|
|
33
|
-
|
|
24
|
+
{...props}
|
|
34
25
|
>
|
|
35
26
|
{label}
|
|
36
27
|
</button>
|
|
@@ -2,21 +2,16 @@
|
|
|
2
2
|
import './header.css';
|
|
3
3
|
import Button from './Button.svelte';
|
|
4
4
|
|
|
5
|
-
|
|
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
|
+
*/
|
|
6
12
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const dispatch = createEventDispatcher();
|
|
10
|
-
|
|
11
|
-
function onLogin(event) {
|
|
12
|
-
dispatch('login', event);
|
|
13
|
-
}
|
|
14
|
-
function onLogout(event) {
|
|
15
|
-
dispatch('logout', event);
|
|
16
|
-
}
|
|
17
|
-
function onCreateAccount(event) {
|
|
18
|
-
dispatch('createAccount', event);
|
|
19
|
-
}
|
|
13
|
+
/** @type {Props} */
|
|
14
|
+
const { user, onLogin, onLogout, onCreateAccount } = $props();
|
|
20
15
|
</script>
|
|
21
16
|
|
|
22
17
|
<header>
|
|
@@ -42,10 +37,10 @@
|
|
|
42
37
|
<span class="welcome">
|
|
43
38
|
Welcome, <b>{user.name}</b>!
|
|
44
39
|
</span>
|
|
45
|
-
<Button size="small"
|
|
40
|
+
<Button size="small" onclick={onLogout} label="Log out" />
|
|
46
41
|
{:else}
|
|
47
|
-
<Button size="small"
|
|
48
|
-
<Button primary size="small"
|
|
42
|
+
<Button size="small" onclick={onLogin} label="Log in" />
|
|
43
|
+
<Button primary size="small" onclick={onCreateAccount} label="Sign up" />
|
|
49
44
|
{/if}
|
|
50
45
|
</div>
|
|
51
46
|
</div>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script module>
|
|
2
2
|
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
-
import { expect, userEvent, waitFor, within } from '
|
|
3
|
+
import { expect, userEvent, waitFor, within } from 'storybook/test';
|
|
4
4
|
import Page from './Page.svelte';
|
|
5
5
|
import { fn } from 'storybook/test';
|
|
6
6
|
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
import './page.css';
|
|
3
3
|
import Header from './Header.svelte';
|
|
4
4
|
|
|
5
|
-
let user = null;
|
|
5
|
+
let user = $state(null);
|
|
6
6
|
</script>
|
|
7
7
|
|
|
8
8
|
<article>
|
|
9
9
|
<Header
|
|
10
10
|
{user}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
onLogin={() => (user = { name: 'Jane Doe' })}
|
|
12
|
+
onLogout={() => (user = null)}
|
|
13
|
+
onCreateAccount={() => (user = { name: 'Jane Doe' })}
|
|
14
14
|
/>
|
|
15
15
|
|
|
16
16
|
<section class="storybook-page">
|
|
@@ -11,19 +11,20 @@
|
|
|
11
11
|
/** Button contents */
|
|
12
12
|
label: string;
|
|
13
13
|
/** The onclick event handler */
|
|
14
|
-
|
|
14
|
+
onclick?: () => void;
|
|
15
15
|
}
|
|
16
|
+
|
|
17
|
+
const { primary = false, backgroundColor, size = 'medium', label, ...props }: Props = $props();
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
let mode = $derived(primary ? 'storybook-button--primary' : 'storybook-button--secondary');
|
|
20
|
+
let style = $derived(backgroundColor ? `background-color: ${backgroundColor}` : '');
|
|
18
21
|
</script>
|
|
19
22
|
|
|
20
23
|
<button
|
|
21
24
|
type="button"
|
|
22
|
-
class={['storybook-button', `storybook-button--${size}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
style:background-color={backgroundColor}
|
|
26
|
-
onclick={onClick}
|
|
25
|
+
class={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
|
|
26
|
+
{style}
|
|
27
|
+
{...props}
|
|
27
28
|
>
|
|
28
29
|
{label}
|
|
29
30
|
</button>
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
<span class="welcome">
|
|
36
36
|
Welcome, <b>{user.name}</b>!
|
|
37
37
|
</span>
|
|
38
|
-
<Button size="small"
|
|
38
|
+
<Button size="small" onclick={onLogout} label="Log out" />
|
|
39
39
|
{:else}
|
|
40
|
-
<Button size="small"
|
|
41
|
-
<Button primary size="small"
|
|
40
|
+
<Button size="small" onclick={onLogin} label="Log in" />
|
|
41
|
+
<Button primary size="small" onclick={onCreateAccount} label="Sign up" />
|
|
42
42
|
{/if}
|
|
43
43
|
</div>
|
|
44
44
|
</div>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script module>
|
|
2
2
|
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
-
import { expect, userEvent, waitFor, within } from '
|
|
3
|
+
import { expect, userEvent, waitFor, within } from 'storybook/test';
|
|
4
4
|
import Page from './Page.svelte';
|
|
5
5
|
import { fn } from 'storybook/test';
|
|
6
6
|
|
|
@@ -3,9 +3,8 @@ import { expect, fn, within } from 'storybook/test';
|
|
|
3
3
|
import Forms from './Forms.svelte';
|
|
4
4
|
|
|
5
5
|
export default {
|
|
6
|
-
title: 'stories/sveltekit/modules/forms',
|
|
6
|
+
title: 'stories/frameworks/sveltekit/modules/forms',
|
|
7
7
|
component: Forms,
|
|
8
|
-
tags: ['autodocs'],
|
|
9
8
|
};
|
|
10
9
|
|
|
11
10
|
const enhance = fn();
|
|
@@ -3,9 +3,8 @@ import { expect, fn, within } from 'storybook/test';
|
|
|
3
3
|
import Hrefs from './Hrefs.svelte';
|
|
4
4
|
|
|
5
5
|
export default {
|
|
6
|
-
title: 'stories/sveltekit/modules/hrefs',
|
|
6
|
+
title: 'stories/frameworks/sveltekit/modules/hrefs',
|
|
7
7
|
component: Hrefs,
|
|
8
|
-
tags: ['autodocs'],
|
|
9
8
|
};
|
|
10
9
|
|
|
11
10
|
export const DefaultActions = {
|
|
@@ -3,9 +3,8 @@ import { expect, fn, within } from 'storybook/test';
|
|
|
3
3
|
import Navigation from './Navigation.svelte';
|
|
4
4
|
|
|
5
5
|
export default {
|
|
6
|
-
title: 'stories/sveltekit/modules/navigation',
|
|
6
|
+
title: 'stories/frameworks/sveltekit/modules/navigation',
|
|
7
7
|
component: Navigation,
|
|
8
|
-
tags: ['autodocs'],
|
|
9
8
|
};
|
|
10
9
|
|
|
11
10
|
const goto = fn();
|
|
@@ -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,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,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,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" />
|