@storybook/svelte-vite 9.0.0-alpha.2 → 9.0.0-alpha.21
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/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/node/index.d.ts +1 -0
- package/dist/preset.d.ts +1 -0
- package/dist/preset.js +3 -11
- package/package.json +10 -9
- package/template/cli/js/Button.stories.svelte +31 -0
- package/template/cli/js/Button.svelte +27 -0
- package/template/cli/js/Header.stories.svelte +26 -0
- package/template/cli/js/Header.svelte +47 -0
- package/template/cli/js/Page.stories.svelte +30 -0
- package/template/cli/js/Page.svelte +70 -0
- package/template/cli/ts/Button.stories.svelte +31 -0
- package/template/cli/ts/Button.svelte +30 -0
- package/template/cli/ts/Header.stories.svelte +26 -0
- package/template/cli/ts/Header.svelte +45 -0
- package/template/cli/ts/Page.stories.svelte +30 -0
- package/template/cli/ts/Page.svelte +70 -0
- package/template/stories_svelte-vite-default-js/docgen/jsdoc.stories.js +17 -0
- package/template/stories_svelte-vite-default-js/docgen/jsdoc.svelte +92 -0
- package/template/stories_svelte-vite-default-ts/docgen/jsdoc.stories.js +17 -0
- package/template/stories_svelte-vite-default-ts/docgen/jsdoc.svelte +91 -0
- package/template/stories_svelte-vite-default-ts/docgen/ts-inline-prop-types.stories.ts +16 -0
- package/template/stories_svelte-vite-default-ts/docgen/ts-inline-prop-types.svelte +103 -0
- package/template/stories_svelte-vite-default-ts/docgen/ts-legacy.stories.ts +16 -0
- package/template/stories_svelte-vite-default-ts/docgen/ts-legacy.svelte +98 -0
- package/template/stories_svelte-vite-default-ts/docgen/ts-referenced-prop-types.stories.ts +16 -0
- package/template/stories_svelte-vite-default-ts/docgen/ts-referenced-prop-types.svelte +107 -0
- package/template/stories_svelte-vite-default-ts/docgen/ts.stories.ts +16 -0
- package/template/stories_svelte-vite-default-ts/docgen/ts.svelte +125 -0
- package/template/stories_svelte-vite-default-ts/docgen/types.ts +7 -0
- package/template/stories_svelte-vite-default-ts/docs-ts.stories.js +0 -10
|
@@ -0,0 +1,70 @@
|
|
|
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>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import JSDoc from './jsdoc.svelte';
|
|
2
|
+
|
|
3
|
+
/** @typedef {import('@storybook/svelte-vite').StoryObj} StoryObj */
|
|
4
|
+
|
|
5
|
+
/** @type {Meta<typeof JSDoc>} */
|
|
6
|
+
const meta = {
|
|
7
|
+
component: JSDoc,
|
|
8
|
+
tags: ['autodocs'],
|
|
9
|
+
render: (args, { argTypes }) => ({
|
|
10
|
+
Component: JSDoc,
|
|
11
|
+
props: { ...args, argTypes },
|
|
12
|
+
}),
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default meta;
|
|
16
|
+
|
|
17
|
+
export const Default = {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/**
|
|
3
|
+
* @typedef {Object} MyObject
|
|
4
|
+
* @property {string} foo
|
|
5
|
+
* @property {number} bar
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {Object} MyProps
|
|
10
|
+
* @property {boolean} [boolean] Boolean
|
|
11
|
+
* @property {string} [string] String
|
|
12
|
+
* @property {string} stringRequired String (required)
|
|
13
|
+
* @property {number} [number] Number
|
|
14
|
+
* @property {true} [trueLiteral] True literal
|
|
15
|
+
* @property {symbol} [symbol] Symbol
|
|
16
|
+
* @property {null} [nullValue] Null
|
|
17
|
+
* @property {undefined} [undefinedValue] Undefined
|
|
18
|
+
* @property {any} [any] Any
|
|
19
|
+
* @property {Date} [date] Date
|
|
20
|
+
* @property {import('./types').LiteralStrings} [unionLiteralStrings] Union of literal strings
|
|
21
|
+
* @property {import('./types').LiteralNumbers} [unionLiteralNumbers] Union of literal numbers
|
|
22
|
+
* @property {MyObject} [object] Object
|
|
23
|
+
* @property {{ foo: string; bar: number }} [inlineObject] Inline object
|
|
24
|
+
* @property {Record<string, number>} [record] Record
|
|
25
|
+
* @property {number | string} [unionTypes] Union of types
|
|
26
|
+
* @property {{ a: number } & { b: string }} [intersection] Intersection of types
|
|
27
|
+
* @property {(event: MouseEvent) => number} [func] Event callback function
|
|
28
|
+
* @property {import('svelte').Snippet} children Snippet contents
|
|
29
|
+
* @property {Record<string, any>} [argTypes] Actual arg types inferred from the component
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/** @type {MyProps} */
|
|
33
|
+
let {
|
|
34
|
+
boolean = true,
|
|
35
|
+
string = 'default',
|
|
36
|
+
stringRequired,
|
|
37
|
+
number = 123,
|
|
38
|
+
trueLiteral = undefined,
|
|
39
|
+
symbol = undefined,
|
|
40
|
+
nullValue = null,
|
|
41
|
+
undefinedValue = undefined,
|
|
42
|
+
any = undefined,
|
|
43
|
+
date = new Date('20 Jan 1983'),
|
|
44
|
+
unionLiteralStrings = 'apple',
|
|
45
|
+
unionLiteralNumbers = 1000,
|
|
46
|
+
object = undefined,
|
|
47
|
+
inlineObject = undefined,
|
|
48
|
+
record = { a: 1, b: 2 },
|
|
49
|
+
unionTypes = 123,
|
|
50
|
+
intersection = undefined,
|
|
51
|
+
func = () => 10,
|
|
52
|
+
children,
|
|
53
|
+
argTypes,
|
|
54
|
+
} = $props();
|
|
55
|
+
</script>
|
|
56
|
+
|
|
57
|
+
<h1>Docgen: JS - JSDoc</h1>
|
|
58
|
+
|
|
59
|
+
<h2>Args</h2>
|
|
60
|
+
<pre>{JSON.stringify(
|
|
61
|
+
{
|
|
62
|
+
boolean,
|
|
63
|
+
string,
|
|
64
|
+
stringRequired,
|
|
65
|
+
number,
|
|
66
|
+
trueLiteral,
|
|
67
|
+
symbol,
|
|
68
|
+
nullValue,
|
|
69
|
+
undefinedValue,
|
|
70
|
+
any,
|
|
71
|
+
date,
|
|
72
|
+
unionLiteralStrings,
|
|
73
|
+
unionLiteralNumbers,
|
|
74
|
+
object,
|
|
75
|
+
inlineObject,
|
|
76
|
+
record,
|
|
77
|
+
unionTypes,
|
|
78
|
+
intersection,
|
|
79
|
+
func,
|
|
80
|
+
argTypes,
|
|
81
|
+
},
|
|
82
|
+
null,
|
|
83
|
+
2
|
|
84
|
+
)}</pre>
|
|
85
|
+
|
|
86
|
+
<h2>Children</h2>
|
|
87
|
+
{#if children}
|
|
88
|
+
{@render children()}
|
|
89
|
+
{/if}
|
|
90
|
+
|
|
91
|
+
<h2>Arg Types</h2>
|
|
92
|
+
<pre>{JSON.stringify(argTypes, null, 2)}</pre>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import JSDoc from './jsdoc.svelte';
|
|
2
|
+
|
|
3
|
+
/** @typedef {import('@storybook/svelte-vite').StoryObj} StoryObj */
|
|
4
|
+
|
|
5
|
+
/** @type {Meta<typeof JSDoc>} */
|
|
6
|
+
const meta = {
|
|
7
|
+
component: JSDoc,
|
|
8
|
+
tags: ['autodocs'],
|
|
9
|
+
render: (args, { argTypes }) => ({
|
|
10
|
+
Component: JSDoc,
|
|
11
|
+
props: { ...args, argTypes },
|
|
12
|
+
}),
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default meta;
|
|
16
|
+
|
|
17
|
+
export const Default = {};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/**
|
|
3
|
+
* @typedef {Object} MyObject
|
|
4
|
+
* @property {string} foo
|
|
5
|
+
* @property {number} bar
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {Object} MyProps
|
|
10
|
+
* @property {boolean} [boolean] Boolean
|
|
11
|
+
* @property {string} [string] String
|
|
12
|
+
* @property {string} stringRequired String (required)
|
|
13
|
+
* @property {number} [number] Number
|
|
14
|
+
* @property {true} [trueLiteral] True literal
|
|
15
|
+
* @property {symbol} [symbol] Symbol
|
|
16
|
+
* @property {null} [nullValue] Null
|
|
17
|
+
* @property {undefined} [undefinedValue] Undefined
|
|
18
|
+
* @property {any} [any] Any
|
|
19
|
+
* @property {import('./types').LiteralStrings} [unionLiteralStrings] Union of literal strings
|
|
20
|
+
* @property {import('./types').LiteralNumbers} [unionLiteralNumbers] Union of literal numbers
|
|
21
|
+
* @property {MyObject} [object] Object
|
|
22
|
+
* @property {{ foo: string; bar: number }} [inlineObject] Inline object
|
|
23
|
+
* @property {Record<string, number>} [record] Record
|
|
24
|
+
* @property {Date} [date] Date
|
|
25
|
+
* @property {number | string} [unionTypes] Union of types
|
|
26
|
+
* @property {{ a: number } & { b: string }} [intersection] Intersection of types
|
|
27
|
+
* @property {import('svelte').Snippet} children Snippet contents
|
|
28
|
+
* @property {(event: MouseEvent) => number} [func] Event callback function
|
|
29
|
+
* @property {Record<string, any>} [argTypes] Actual arg types inferred from the component
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/** @type {MyProps} */
|
|
33
|
+
let {
|
|
34
|
+
boolean = true,
|
|
35
|
+
string = 'default',
|
|
36
|
+
stringRequired,
|
|
37
|
+
number = 123,
|
|
38
|
+
trueLiteral = undefined,
|
|
39
|
+
symbol = undefined,
|
|
40
|
+
nullValue = null,
|
|
41
|
+
undefinedValue = undefined,
|
|
42
|
+
any = undefined,
|
|
43
|
+
unionLiteralStrings = 'apple',
|
|
44
|
+
unionLiteralNumbers = 1000,
|
|
45
|
+
object = undefined,
|
|
46
|
+
inlineObject = undefined,
|
|
47
|
+
record = { a: 1, b: 2 },
|
|
48
|
+
date = new Date('20 Jan 1983'),
|
|
49
|
+
unionTypes = 123,
|
|
50
|
+
intersection = undefined,
|
|
51
|
+
children,
|
|
52
|
+
func = () => 10,
|
|
53
|
+
argTypes,
|
|
54
|
+
} = $props();
|
|
55
|
+
</script>
|
|
56
|
+
|
|
57
|
+
<h1>Docgen: JS - JSDoc</h1>
|
|
58
|
+
|
|
59
|
+
<h2>Args</h2>
|
|
60
|
+
<pre>{JSON.stringify(
|
|
61
|
+
{
|
|
62
|
+
boolean,
|
|
63
|
+
string,
|
|
64
|
+
stringRequired,
|
|
65
|
+
number,
|
|
66
|
+
trueLiteral,
|
|
67
|
+
symbol,
|
|
68
|
+
nullValue,
|
|
69
|
+
undefinedValue,
|
|
70
|
+
any,
|
|
71
|
+
date,
|
|
72
|
+
unionLiteralStrings,
|
|
73
|
+
unionLiteralNumbers,
|
|
74
|
+
object,
|
|
75
|
+
inlineObject,
|
|
76
|
+
record,
|
|
77
|
+
unionTypes,
|
|
78
|
+
intersection,
|
|
79
|
+
func,
|
|
80
|
+
},
|
|
81
|
+
null,
|
|
82
|
+
2
|
|
83
|
+
)}</pre>
|
|
84
|
+
|
|
85
|
+
<h2>Children</h2>
|
|
86
|
+
{#if children}
|
|
87
|
+
{@render children()}
|
|
88
|
+
{/if}
|
|
89
|
+
|
|
90
|
+
<h2>Arg Types</h2>
|
|
91
|
+
<pre>{JSON.stringify(argTypes, null, 2)}</pre>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Meta } from '@storybook/svelte-vite';
|
|
2
|
+
|
|
3
|
+
import TSInlinePropTypes from './ts-inline-prop-types.svelte';
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
6
|
+
component: TSInlinePropTypes,
|
|
7
|
+
tags: ['autodocs'],
|
|
8
|
+
render: (args, { argTypes }) => ({
|
|
9
|
+
Component: TSInlinePropTypes,
|
|
10
|
+
props: { ...args, argTypes },
|
|
11
|
+
}),
|
|
12
|
+
} satisfies Meta<typeof TSInlinePropTypes>;
|
|
13
|
+
|
|
14
|
+
export default meta;
|
|
15
|
+
|
|
16
|
+
export const Default = {};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { LiteralNumbers, LiteralStrings } from './types';
|
|
4
|
+
import { MyEnum } from './types';
|
|
5
|
+
|
|
6
|
+
type MyObject = {
|
|
7
|
+
foo: string;
|
|
8
|
+
bar: number;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
let {
|
|
12
|
+
boolean = true,
|
|
13
|
+
string = 'default',
|
|
14
|
+
stringRequired,
|
|
15
|
+
number = 123,
|
|
16
|
+
nullValue = null,
|
|
17
|
+
arrayOfNumbers = [1, 20, 300],
|
|
18
|
+
enumValue = MyEnum.FOO,
|
|
19
|
+
record = { a: 1, b: 2 },
|
|
20
|
+
date = new Date('20 Jan 1983'),
|
|
21
|
+
unionTypes = 123,
|
|
22
|
+
func = () => 10,
|
|
23
|
+
children,
|
|
24
|
+
argTypes,
|
|
25
|
+
}: {
|
|
26
|
+
/** Boolean */
|
|
27
|
+
boolean?: boolean;
|
|
28
|
+
/** String */
|
|
29
|
+
string?: string;
|
|
30
|
+
/** String (required) */
|
|
31
|
+
stringRequired: string;
|
|
32
|
+
/** Number */
|
|
33
|
+
number?: number;
|
|
34
|
+
/** True literal */
|
|
35
|
+
trueLiteral?: true;
|
|
36
|
+
/** Symbol */
|
|
37
|
+
symbol?: symbol;
|
|
38
|
+
/** Null */
|
|
39
|
+
nullValue?: null;
|
|
40
|
+
/** Undefined */
|
|
41
|
+
undefinedValue?: undefined;
|
|
42
|
+
/** Any */
|
|
43
|
+
any?: any;
|
|
44
|
+
/** Date */
|
|
45
|
+
date?: Date;
|
|
46
|
+
/** Array of numbers */
|
|
47
|
+
arrayOfNumbers?: number[];
|
|
48
|
+
/** Enum */
|
|
49
|
+
enumValue?: MyEnum;
|
|
50
|
+
/** Union of literal strings */
|
|
51
|
+
unionLiteralStrings?: LiteralStrings;
|
|
52
|
+
/** Union of literal numbers */
|
|
53
|
+
unionLiteralNumbers?: LiteralNumbers;
|
|
54
|
+
/** Object */
|
|
55
|
+
object?: MyObject;
|
|
56
|
+
/** Inline object */
|
|
57
|
+
inlineObject?: {
|
|
58
|
+
foo: string;
|
|
59
|
+
bar: number;
|
|
60
|
+
};
|
|
61
|
+
/** Record */
|
|
62
|
+
record?: Record<string, number>;
|
|
63
|
+
/** Union of types */
|
|
64
|
+
unionTypes?: number | string;
|
|
65
|
+
/** Intersection of types */
|
|
66
|
+
intersection?: { a: number } & { b: string };
|
|
67
|
+
/** Event callback function */
|
|
68
|
+
func?: (event: MouseEvent) => number;
|
|
69
|
+
/** Snippet contents */
|
|
70
|
+
children: Snippet;
|
|
71
|
+
/** Actual arg types inferred from the component */
|
|
72
|
+
argTypes: Record<string, any>;
|
|
73
|
+
} = $props();
|
|
74
|
+
</script>
|
|
75
|
+
|
|
76
|
+
<h1>Docgen: TS - inline prop types</h1>
|
|
77
|
+
|
|
78
|
+
<h2>Args</h2>
|
|
79
|
+
<pre>{JSON.stringify(
|
|
80
|
+
{
|
|
81
|
+
boolean,
|
|
82
|
+
string,
|
|
83
|
+
stringRequired,
|
|
84
|
+
number,
|
|
85
|
+
nullValue,
|
|
86
|
+
date,
|
|
87
|
+
arrayOfNumbers,
|
|
88
|
+
enumValue,
|
|
89
|
+
record,
|
|
90
|
+
unionTypes,
|
|
91
|
+
func,
|
|
92
|
+
},
|
|
93
|
+
null,
|
|
94
|
+
2
|
|
95
|
+
)}</pre>
|
|
96
|
+
|
|
97
|
+
<h2>Children</h2>
|
|
98
|
+
{#if children}
|
|
99
|
+
{@render children()}
|
|
100
|
+
{/if}
|
|
101
|
+
|
|
102
|
+
<h2>Arg Types</h2>
|
|
103
|
+
<pre>{JSON.stringify(argTypes, null, 2)}</pre>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Meta } from '@storybook/svelte-vite';
|
|
2
|
+
|
|
3
|
+
import TSLegacy from './ts-legacy.svelte';
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
6
|
+
component: TSLegacy,
|
|
7
|
+
tags: ['autodocs'],
|
|
8
|
+
render: (args, { argTypes }) => ({
|
|
9
|
+
Component: TSLegacy,
|
|
10
|
+
props: { ...args, argTypes } as any,
|
|
11
|
+
}),
|
|
12
|
+
} satisfies Meta<typeof TSLegacy>;
|
|
13
|
+
|
|
14
|
+
export default meta;
|
|
15
|
+
|
|
16
|
+
export const Default = {};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { LiteralNumbers, LiteralStrings } from './types';
|
|
4
|
+
import { MyEnum } from './types';
|
|
5
|
+
|
|
6
|
+
type MyObject = {
|
|
7
|
+
foo: string;
|
|
8
|
+
bar: number;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/** Boolean */
|
|
12
|
+
export let boolean: boolean = true;
|
|
13
|
+
/** String */
|
|
14
|
+
export let string: string = 'default';
|
|
15
|
+
/** String (required) */
|
|
16
|
+
export let stringRequired: string;
|
|
17
|
+
/** Number */
|
|
18
|
+
export let number: number = 123;
|
|
19
|
+
/** True literal */
|
|
20
|
+
export let trueLiteral: true | undefined = undefined;
|
|
21
|
+
/** Symbol */
|
|
22
|
+
export let symbol: symbol | undefined = undefined;
|
|
23
|
+
/** Null */
|
|
24
|
+
export let nullValue: null = null;
|
|
25
|
+
/** Undefined */
|
|
26
|
+
export let undefinedValue: undefined = undefined;
|
|
27
|
+
/** Any */
|
|
28
|
+
export let any: any = null;
|
|
29
|
+
/** Date */
|
|
30
|
+
export let date: Date = new Date('20 Jan 1983');
|
|
31
|
+
/** Array of numbers */
|
|
32
|
+
export let arrayOfNumbers: number[] = [1, 20, 300];
|
|
33
|
+
/** Enum */
|
|
34
|
+
export let enumValue: MyEnum = MyEnum.FOO;
|
|
35
|
+
/** Union of literal strings */
|
|
36
|
+
export let unionLiteralStrings: LiteralStrings = 'apple';
|
|
37
|
+
/** Union of literal numbers */
|
|
38
|
+
export let unionLiteralNumbers: LiteralNumbers = 1000;
|
|
39
|
+
/** Object */
|
|
40
|
+
export let object: MyObject | undefined = undefined;
|
|
41
|
+
/** Inline object */
|
|
42
|
+
export let inlineObject:
|
|
43
|
+
| {
|
|
44
|
+
foo: string;
|
|
45
|
+
bar: number;
|
|
46
|
+
}
|
|
47
|
+
| undefined = undefined;
|
|
48
|
+
/** Record */
|
|
49
|
+
export let record: Record<string, number> = { a: 1, b: 2 };
|
|
50
|
+
/** Union of types */
|
|
51
|
+
export let unionTypes: number | string = 123;
|
|
52
|
+
/** Intersection of types */
|
|
53
|
+
export let intersection: ({ a: number } & { b: string }) | undefined = undefined;
|
|
54
|
+
/** Event callback function */
|
|
55
|
+
export let func: (event: MouseEvent) => number = () => 10;
|
|
56
|
+
/** Snippet contents */
|
|
57
|
+
export let children: Snippet;
|
|
58
|
+
/** Actual arg types inferred from the component */
|
|
59
|
+
export let argTypes: Record<string, any> = {};
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
<h1>Docgen: TS - legacy</h1>
|
|
63
|
+
|
|
64
|
+
<h2>Args</h2>
|
|
65
|
+
<pre>{JSON.stringify(
|
|
66
|
+
{
|
|
67
|
+
boolean,
|
|
68
|
+
string,
|
|
69
|
+
stringRequired,
|
|
70
|
+
number,
|
|
71
|
+
trueLiteral,
|
|
72
|
+
symbol,
|
|
73
|
+
nullValue,
|
|
74
|
+
undefinedValue,
|
|
75
|
+
any,
|
|
76
|
+
date,
|
|
77
|
+
arrayOfNumbers,
|
|
78
|
+
enumValue,
|
|
79
|
+
unionLiteralStrings,
|
|
80
|
+
unionLiteralNumbers,
|
|
81
|
+
object,
|
|
82
|
+
inlineObject,
|
|
83
|
+
record,
|
|
84
|
+
unionTypes,
|
|
85
|
+
intersection,
|
|
86
|
+
func,
|
|
87
|
+
},
|
|
88
|
+
null,
|
|
89
|
+
2
|
|
90
|
+
)}</pre>
|
|
91
|
+
|
|
92
|
+
<h2>Children</h2>
|
|
93
|
+
{#if children}
|
|
94
|
+
{@render children()}
|
|
95
|
+
{/if}
|
|
96
|
+
|
|
97
|
+
<h2>Arg Types</h2>
|
|
98
|
+
<pre>{JSON.stringify(argTypes, null, 2)}</pre>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Meta } from '@storybook/svelte-vite';
|
|
2
|
+
|
|
3
|
+
import TSReferencedPropTypes from './ts-referenced-prop-types.svelte';
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
6
|
+
component: TSReferencedPropTypes,
|
|
7
|
+
tags: ['autodocs'],
|
|
8
|
+
render: (args, { argTypes }) => ({
|
|
9
|
+
Component: TSReferencedPropTypes,
|
|
10
|
+
props: { ...args, argTypes },
|
|
11
|
+
}),
|
|
12
|
+
} satisfies Meta<typeof TSReferencedPropTypes>;
|
|
13
|
+
|
|
14
|
+
export default meta;
|
|
15
|
+
|
|
16
|
+
export const Default = {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { LiteralNumbers, LiteralStrings } from './types';
|
|
4
|
+
import { MyEnum } from './types';
|
|
5
|
+
|
|
6
|
+
type MyObject = {
|
|
7
|
+
foo: string;
|
|
8
|
+
bar: number;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
type PropsA = {
|
|
12
|
+
/** Boolean */
|
|
13
|
+
boolean?: boolean;
|
|
14
|
+
/** String */
|
|
15
|
+
string?: string;
|
|
16
|
+
/** String (required) */
|
|
17
|
+
stringRequired: string;
|
|
18
|
+
/** Number */
|
|
19
|
+
number?: number;
|
|
20
|
+
};
|
|
21
|
+
type PropsB = {
|
|
22
|
+
/** True literal */
|
|
23
|
+
trueLiteral?: true;
|
|
24
|
+
/** Symbol */
|
|
25
|
+
symbol?: symbol;
|
|
26
|
+
/** Null */
|
|
27
|
+
nullValue?: null;
|
|
28
|
+
/** Undefined */
|
|
29
|
+
undefinedValue?: undefined;
|
|
30
|
+
/** Any */
|
|
31
|
+
any?: any;
|
|
32
|
+
/** Date */
|
|
33
|
+
date?: Date;
|
|
34
|
+
/** Array of numbers */
|
|
35
|
+
arrayOfNumbers?: number[];
|
|
36
|
+
/** Enum */
|
|
37
|
+
enumValue?: MyEnum;
|
|
38
|
+
/** Union of literal strings */
|
|
39
|
+
unionLiteralStrings?: LiteralStrings;
|
|
40
|
+
/** Union of literal numbers */
|
|
41
|
+
unionLiteralNumbers?: LiteralNumbers;
|
|
42
|
+
/** Object */
|
|
43
|
+
object?: MyObject;
|
|
44
|
+
/** Inline object */
|
|
45
|
+
inlineObject?: {
|
|
46
|
+
foo: string;
|
|
47
|
+
bar: number;
|
|
48
|
+
};
|
|
49
|
+
/** Record */
|
|
50
|
+
record?: Record<string, number>;
|
|
51
|
+
/** Union of types */
|
|
52
|
+
unionTypes?: number | string;
|
|
53
|
+
/** Intersection of types */
|
|
54
|
+
intersection?: { a: number } & { b: string };
|
|
55
|
+
/** Event callback function */
|
|
56
|
+
func?: (event: MouseEvent) => number;
|
|
57
|
+
/** Snippet contents */
|
|
58
|
+
children: Snippet;
|
|
59
|
+
/** Actual arg types inferred from the component */
|
|
60
|
+
argTypes: Record<string, any>;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
let {
|
|
64
|
+
boolean = true,
|
|
65
|
+
string = 'default',
|
|
66
|
+
stringRequired,
|
|
67
|
+
number = 123,
|
|
68
|
+
nullValue = null,
|
|
69
|
+
arrayOfNumbers = [1, 20, 300],
|
|
70
|
+
enumValue = MyEnum.FOO,
|
|
71
|
+
record = { a: 1, b: 2 },
|
|
72
|
+
date = new Date('20 Jan 1983'),
|
|
73
|
+
unionTypes = 123,
|
|
74
|
+
children,
|
|
75
|
+
func = () => 10,
|
|
76
|
+
argTypes,
|
|
77
|
+
}: PropsA & PropsB = $props();
|
|
78
|
+
</script>
|
|
79
|
+
|
|
80
|
+
<h1>Docgen: TS - referenced prop types</h1>
|
|
81
|
+
|
|
82
|
+
<h2>Args</h2>
|
|
83
|
+
<pre>{JSON.stringify(
|
|
84
|
+
{
|
|
85
|
+
boolean,
|
|
86
|
+
string,
|
|
87
|
+
stringRequired,
|
|
88
|
+
number,
|
|
89
|
+
nullValue,
|
|
90
|
+
arrayOfNumbers,
|
|
91
|
+
enumValue,
|
|
92
|
+
record,
|
|
93
|
+
date,
|
|
94
|
+
unionTypes,
|
|
95
|
+
func,
|
|
96
|
+
},
|
|
97
|
+
null,
|
|
98
|
+
2
|
|
99
|
+
)}</pre>
|
|
100
|
+
|
|
101
|
+
<h2>Children</h2>
|
|
102
|
+
{#if children}
|
|
103
|
+
{@render children()}
|
|
104
|
+
{/if}
|
|
105
|
+
|
|
106
|
+
<h2>Arg Types</h2>
|
|
107
|
+
<pre>{JSON.stringify(argTypes, null, 2)}</pre>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Meta } from '@storybook/svelte-vite';
|
|
2
|
+
|
|
3
|
+
import TS from './ts.svelte';
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
6
|
+
component: TS,
|
|
7
|
+
tags: ['autodocs'],
|
|
8
|
+
render: (args, { argTypes }) => ({
|
|
9
|
+
Component: TS,
|
|
10
|
+
props: { ...args, argTypes },
|
|
11
|
+
}),
|
|
12
|
+
} satisfies Meta<typeof TS>;
|
|
13
|
+
|
|
14
|
+
export default meta;
|
|
15
|
+
|
|
16
|
+
export const Default = {};
|