@storybook/vue3 7.1.0-alpha.0 → 7.1.0-alpha.10
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-3MGVBGQN.mjs +1 -0
- package/dist/config.d.ts +2 -2
- package/dist/config.js +3 -3
- package/dist/config.mjs +3 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/render-32b7dd3f.d.ts +148 -0
- package/package.json +6 -6
- package/template/cli/js/Button.stories.js +2 -2
- package/template/cli/js/Header.stories.js +2 -2
- package/template/cli/js/Page.stories.js +2 -2
- package/template/cli/ts-3-8/Button.stories.ts +3 -3
- package/template/cli/ts-3-8/Header.stories.ts +3 -3
- package/template/cli/ts-3-8/Page.stories.ts +3 -3
- package/template/cli/ts-4-9/Button.stories.ts +3 -3
- package/template/cli/ts-4-9/Header.stories.ts +3 -3
- package/template/cli/ts-4-9/Page.stories.ts +3 -3
- package/template/stories/preview.js +29 -4
- package/template/stories_vue3-vite-default-ts/BaseLayout.vue +18 -0
- package/template/stories_vue3-vite-default-ts/CustomRenderFunctionalComponent.stories.ts +34 -0
- package/template/stories_vue3-vite-default-ts/CustomRenderOptionsArgsFromData.stories.ts +47 -0
- package/template/stories_vue3-vite-default-ts/CustomRenderOptionsArgsFromProps.stories.ts +33 -0
- package/template/stories_vue3-vite-default-ts/GlobalSetup.stories.ts +52 -0
- package/template/stories_vue3-vite-default-ts/GlobalSetup.vue +6 -0
- package/template/{stories/GlobalUsage.stories.js → stories_vue3-vite-default-ts/GlobalUsage.stories.ts} +1 -1
- package/template/stories_vue3-vite-default-ts/GlobalUsage.vue +3 -0
- package/template/stories_vue3-vite-default-ts/MySlotComponent.vue +12 -0
- package/template/{stories → stories_vue3-vite-default-ts}/OverrideArgs.stories.js +3 -1
- package/template/{stories → stories_vue3-vite-default-ts}/OverrideArgs.vue +3 -3
- package/template/stories_vue3-vite-default-ts/ReactiveArgs.stories.ts +135 -0
- package/template/stories_vue3-vite-default-ts/ReactiveDecorators.stories.ts +112 -0
- package/template/stories_vue3-vite-default-ts/ReactiveSlots.stories.ts +127 -0
- package/template/stories_vue3-vite-default-ts/Reactivity.vue +44 -0
- package/template/stories_vue3-vite-default-ts/ScopedSlots.stories.ts +81 -0
- package/template/stories_vue3-vite-default-ts/decorators.stories.ts +84 -0
- package/template/stories_vue3-vite-default-ts/preview.ts +12 -0
- package/dist/chunk-2GDW2BFM.mjs +0 -1
- package/dist/render-c842c5d5.d.ts +0 -14
- package/template/stories/GlobalUsage.vue +0 -3
- package/template/stories/ReactiveArgs.stories.js +0 -44
- package/template/stories/decorators.stories.js +0 -66
- /package/template/{stories → stories_vue3-vite-default-ts}/ReactiveArgs.vue +0 -0
@@ -0,0 +1,148 @@
|
|
1
|
+
import { ConcreteComponent, App } from 'vue';
|
2
|
+
import { WebRenderer, ArgsStoryFn as ArgsStoryFn$1, RenderContext } from '@storybook/types';
|
3
|
+
|
4
|
+
type StoryFnVueReturnType = ConcreteComponent<any>;
|
5
|
+
interface VueRenderer extends WebRenderer {
|
6
|
+
component: Omit<ConcreteComponent<this['T']>, 'props'>;
|
7
|
+
storyResult: StoryFnVueReturnType;
|
8
|
+
}
|
9
|
+
|
10
|
+
interface SBBaseType {
|
11
|
+
required?: boolean;
|
12
|
+
raw?: string;
|
13
|
+
}
|
14
|
+
type SBScalarType = SBBaseType & {
|
15
|
+
name: 'boolean' | 'string' | 'number' | 'function' | 'symbol';
|
16
|
+
};
|
17
|
+
type SBArrayType = SBBaseType & {
|
18
|
+
name: 'array';
|
19
|
+
value: SBType;
|
20
|
+
};
|
21
|
+
type SBObjectType = SBBaseType & {
|
22
|
+
name: 'object';
|
23
|
+
value: Record<string, SBType>;
|
24
|
+
};
|
25
|
+
type SBEnumType = SBBaseType & {
|
26
|
+
name: 'enum';
|
27
|
+
value: (string | number)[];
|
28
|
+
};
|
29
|
+
type SBIntersectionType = SBBaseType & {
|
30
|
+
name: 'intersection';
|
31
|
+
value: SBType[];
|
32
|
+
};
|
33
|
+
type SBUnionType = SBBaseType & {
|
34
|
+
name: 'union';
|
35
|
+
value: SBType[];
|
36
|
+
};
|
37
|
+
type SBOtherType = SBBaseType & {
|
38
|
+
name: 'other';
|
39
|
+
value: string;
|
40
|
+
};
|
41
|
+
type SBType = SBScalarType | SBEnumType | SBArrayType | SBObjectType | SBIntersectionType | SBUnionType | SBOtherType;
|
42
|
+
|
43
|
+
type StoryId = string;
|
44
|
+
type ComponentId = string;
|
45
|
+
type ComponentTitle = string;
|
46
|
+
type StoryName = string;
|
47
|
+
type Tag = string;
|
48
|
+
interface StoryIdentifier {
|
49
|
+
componentId: ComponentId;
|
50
|
+
title: ComponentTitle;
|
51
|
+
/** @deprecated */
|
52
|
+
kind: ComponentTitle;
|
53
|
+
id: StoryId;
|
54
|
+
name: StoryName;
|
55
|
+
/** @deprecated */
|
56
|
+
story: StoryName;
|
57
|
+
tags: Tag[];
|
58
|
+
}
|
59
|
+
interface Parameters {
|
60
|
+
[name: string]: any;
|
61
|
+
}
|
62
|
+
type ConditionalTest = {
|
63
|
+
truthy?: boolean;
|
64
|
+
} | {
|
65
|
+
exists: boolean;
|
66
|
+
} | {
|
67
|
+
eq: any;
|
68
|
+
} | {
|
69
|
+
neq: any;
|
70
|
+
};
|
71
|
+
type ConditionalValue = {
|
72
|
+
arg: string;
|
73
|
+
} | {
|
74
|
+
global: string;
|
75
|
+
};
|
76
|
+
type Conditional = ConditionalValue & ConditionalTest;
|
77
|
+
interface InputType {
|
78
|
+
name?: string;
|
79
|
+
description?: string;
|
80
|
+
defaultValue?: any;
|
81
|
+
type?: SBType | SBScalarType['name'];
|
82
|
+
if?: Conditional;
|
83
|
+
[key: string]: any;
|
84
|
+
}
|
85
|
+
interface StrictInputType extends InputType {
|
86
|
+
name: string;
|
87
|
+
type?: SBType;
|
88
|
+
}
|
89
|
+
interface Args {
|
90
|
+
[name: string]: any;
|
91
|
+
}
|
92
|
+
type StrictArgTypes<TArgs = Args> = {
|
93
|
+
[name in keyof TArgs]: StrictInputType;
|
94
|
+
};
|
95
|
+
type Globals = {
|
96
|
+
[name: string]: any;
|
97
|
+
};
|
98
|
+
type Renderer = {
|
99
|
+
/** What is the type of the `component` annotation in this renderer? */
|
100
|
+
component: unknown;
|
101
|
+
/** What does the story function return in this renderer? */
|
102
|
+
storyResult: unknown;
|
103
|
+
/** What type of element does this renderer render to? */
|
104
|
+
canvasElement: unknown;
|
105
|
+
T?: unknown;
|
106
|
+
};
|
107
|
+
type StoryContextForEnhancers<TRenderer extends Renderer = Renderer, TArgs = Args> = StoryIdentifier & {
|
108
|
+
component?: (TRenderer & {
|
109
|
+
T: any;
|
110
|
+
})['component'];
|
111
|
+
subcomponents?: Record<string, (TRenderer & {
|
112
|
+
T: any;
|
113
|
+
})['component']>;
|
114
|
+
parameters: Parameters;
|
115
|
+
initialArgs: TArgs;
|
116
|
+
argTypes: StrictArgTypes<TArgs>;
|
117
|
+
};
|
118
|
+
type StoryContextUpdate<TArgs = Args> = {
|
119
|
+
args?: TArgs;
|
120
|
+
globals?: Globals;
|
121
|
+
[key: string]: any;
|
122
|
+
};
|
123
|
+
type ViewMode = 'story' | 'docs';
|
124
|
+
type StoryContextForLoaders<TRenderer extends Renderer = Renderer, TArgs = Args> = StoryContextForEnhancers<TRenderer, TArgs> & Required<StoryContextUpdate<TArgs>> & {
|
125
|
+
hooks: unknown;
|
126
|
+
viewMode: ViewMode;
|
127
|
+
originalStoryFn: StoryFn<TRenderer>;
|
128
|
+
};
|
129
|
+
type StoryContext<TRenderer extends Renderer = Renderer, TArgs = Args> = StoryContextForLoaders<TRenderer, TArgs> & {
|
130
|
+
loaded: Record<string, any>;
|
131
|
+
abortSignal: AbortSignal;
|
132
|
+
canvasElement: TRenderer['canvasElement'];
|
133
|
+
};
|
134
|
+
type LegacyStoryFn<TRenderer extends Renderer = Renderer, TArgs = Args> = (context: StoryContext<TRenderer, TArgs>) => TRenderer['storyResult'];
|
135
|
+
type ArgsStoryFn<TRenderer extends Renderer = Renderer, TArgs = Args> = (args: TArgs, context: StoryContext<TRenderer, TArgs>) => (TRenderer & {
|
136
|
+
T: TArgs;
|
137
|
+
})['storyResult'];
|
138
|
+
type StoryFn<TRenderer extends Renderer = Renderer, TArgs = Args> = LegacyStoryFn<TRenderer, TArgs> | ArgsStoryFn<TRenderer, TArgs>;
|
139
|
+
|
140
|
+
declare const render: ArgsStoryFn$1<VueRenderer>;
|
141
|
+
/** add a setup function to set that will be call when story is created a d
|
142
|
+
*
|
143
|
+
* @param fn
|
144
|
+
*/
|
145
|
+
declare const setup: (fn: (app: App, storyContext?: StoryContext<VueRenderer>) => void) => void;
|
146
|
+
declare function renderToCanvas({ storyFn, forceRemount, showMain, showException, storyContext, id }: RenderContext<VueRenderer>, canvasElement: VueRenderer['canvasElement']): () => void;
|
147
|
+
|
148
|
+
export { VueRenderer as V, renderToCanvas as a, render as r, setup as s };
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@storybook/vue3",
|
3
|
-
"version": "7.1.0-alpha.
|
3
|
+
"version": "7.1.0-alpha.10",
|
4
4
|
"description": "Storybook Vue 3 renderer",
|
5
5
|
"keywords": [
|
6
6
|
"storybook"
|
@@ -48,11 +48,11 @@
|
|
48
48
|
"prep": "../../../scripts/prepare/bundle.ts"
|
49
49
|
},
|
50
50
|
"dependencies": {
|
51
|
-
"@storybook/core-client": "7.1.0-alpha.
|
52
|
-
"@storybook/docs-tools": "7.1.0-alpha.
|
51
|
+
"@storybook/core-client": "7.1.0-alpha.10",
|
52
|
+
"@storybook/docs-tools": "7.1.0-alpha.10",
|
53
53
|
"@storybook/global": "^5.0.0",
|
54
|
-
"@storybook/preview-api": "7.1.0-alpha.
|
55
|
-
"@storybook/types": "7.1.0-alpha.
|
54
|
+
"@storybook/preview-api": "7.1.0-alpha.10",
|
55
|
+
"@storybook/types": "7.1.0-alpha.10",
|
56
56
|
"ts-dedent": "^2.0.0",
|
57
57
|
"type-fest": "2.19.0"
|
58
58
|
},
|
@@ -80,5 +80,5 @@
|
|
80
80
|
],
|
81
81
|
"platform": "browser"
|
82
82
|
},
|
83
|
-
"gitHead": "
|
83
|
+
"gitHead": "e7c833e690dd0d2966ffb7fb806a3bda89a508c8"
|
84
84
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import MyButton from './Button.vue';
|
2
2
|
|
3
|
-
// More on how to set up stories at: https://storybook.js.org/docs/
|
3
|
+
// More on how to set up stories at: https://storybook.js.org/docs/vue/writing-stories/introduction
|
4
4
|
export default {
|
5
5
|
title: 'Example/Button',
|
6
6
|
component: MyButton,
|
@@ -19,7 +19,7 @@ export default {
|
|
19
19
|
},
|
20
20
|
};
|
21
21
|
|
22
|
-
// More on writing stories with args: https://storybook.js.org/docs/
|
22
|
+
// More on writing stories with args: https://storybook.js.org/docs/vue/writing-stories/args
|
23
23
|
export const Primary = {
|
24
24
|
args: {
|
25
25
|
primary: true,
|
@@ -3,7 +3,7 @@ import MyHeader from './Header.vue';
|
|
3
3
|
export default {
|
4
4
|
title: 'Example/Header',
|
5
5
|
component: MyHeader,
|
6
|
-
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/
|
6
|
+
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/vue/writing-docs/autodocs
|
7
7
|
tags: ['autodocs'],
|
8
8
|
render: (args) => ({
|
9
9
|
// Components used in your story `template` are defined in the `components` object
|
@@ -21,7 +21,7 @@ export default {
|
|
21
21
|
template: '<my-header :user="user" />',
|
22
22
|
}),
|
23
23
|
parameters: {
|
24
|
-
// More on how to position stories at: https://storybook.js.org/docs/
|
24
|
+
// More on how to position stories at: https://storybook.js.org/docs/vue/configure/story-layout
|
25
25
|
layout: 'fullscreen',
|
26
26
|
},
|
27
27
|
};
|
@@ -5,14 +5,14 @@ export default {
|
|
5
5
|
title: 'Example/Page',
|
6
6
|
component: MyPage,
|
7
7
|
parameters: {
|
8
|
-
// More on how to position stories at: https://storybook.js.org/docs/
|
8
|
+
// More on how to position stories at: https://storybook.js.org/docs/vue/configure/story-layout
|
9
9
|
layout: 'fullscreen',
|
10
10
|
},
|
11
11
|
};
|
12
12
|
|
13
13
|
export const LoggedOut = {};
|
14
14
|
|
15
|
-
// More on interaction testing: https://storybook.js.org/docs/
|
15
|
+
// More on interaction testing: https://storybook.js.org/docs/vue/writing-tests/interaction-testing
|
16
16
|
export const LoggedIn = {
|
17
17
|
render: () => ({
|
18
18
|
components: {
|
@@ -2,11 +2,11 @@ import type { Meta, StoryObj } from '@storybook/vue3';
|
|
2
2
|
|
3
3
|
import Button from './Button.vue';
|
4
4
|
|
5
|
-
// More on how to set up stories at: https://storybook.js.org/docs/
|
5
|
+
// More on how to set up stories at: https://storybook.js.org/docs/vue/writing-stories/introduction
|
6
6
|
const meta: Meta<typeof Button> = {
|
7
7
|
title: 'Example/Button',
|
8
8
|
component: Button,
|
9
|
-
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/
|
9
|
+
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/vue/writing-docs/autodocs
|
10
10
|
tags: ['autodocs'],
|
11
11
|
argTypes: {
|
12
12
|
size: { control: 'select', options: ['small', 'medium', 'large'] },
|
@@ -20,7 +20,7 @@ export default meta;
|
|
20
20
|
type Story = StoryObj<typeof Button>;
|
21
21
|
/*
|
22
22
|
*👇 Render functions are a framework specific feature to allow you control on how the component renders.
|
23
|
-
* See https://storybook.js.org/docs/
|
23
|
+
* See https://storybook.js.org/docs/vue/api/csf
|
24
24
|
* to learn how to use render functions.
|
25
25
|
*/
|
26
26
|
export const Primary: Story = {
|
@@ -4,7 +4,7 @@ import MyHeader from './Header.vue';
|
|
4
4
|
|
5
5
|
const meta: Meta<typeof MyHeader> = {
|
6
6
|
/* 👇 The title prop is optional.
|
7
|
-
* See https://storybook.js.org/docs/
|
7
|
+
* See https://storybook.js.org/docs/vue/configure/overview#configure-story-loading
|
8
8
|
* to learn how to generate automatic titles
|
9
9
|
*/
|
10
10
|
title: 'Example/Header',
|
@@ -17,10 +17,10 @@ const meta: Meta<typeof MyHeader> = {
|
|
17
17
|
template: '<my-header :user="args.user" />',
|
18
18
|
}),
|
19
19
|
parameters: {
|
20
|
-
// More on how to position stories at: https://storybook.js.org/docs/
|
20
|
+
// More on how to position stories at: https://storybook.js.org/docs/react/configure/story-layout
|
21
21
|
layout: 'fullscreen',
|
22
22
|
},
|
23
|
-
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/
|
23
|
+
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/vue/writing-docs/autodocs
|
24
24
|
tags: ['autodocs'],
|
25
25
|
};
|
26
26
|
|
@@ -10,17 +10,17 @@ const meta: Meta<typeof MyPage> = {
|
|
10
10
|
template: '<my-page />',
|
11
11
|
}),
|
12
12
|
parameters: {
|
13
|
-
// More on how to position stories at: https://storybook.js.org/docs/
|
13
|
+
// More on how to position stories at: https://storybook.js.org/docs/vue/configure/story-layout
|
14
14
|
layout: 'fullscreen',
|
15
15
|
},
|
16
|
-
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/
|
16
|
+
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/vue/writing-docs/autodocs
|
17
17
|
tags: ['autodocs'],
|
18
18
|
};
|
19
19
|
|
20
20
|
export default meta;
|
21
21
|
type Story = StoryObj<typeof MyPage>;
|
22
22
|
|
23
|
-
// More on interaction testing: https://storybook.js.org/docs/
|
23
|
+
// More on interaction testing: https://storybook.js.org/docs/vue/writing-tests/interaction-testing
|
24
24
|
export const LoggedIn: Story = {
|
25
25
|
play: async ({ canvasElement }: any) => {
|
26
26
|
const canvas = within(canvasElement);
|
@@ -2,11 +2,11 @@ import type { Meta, StoryObj } from '@storybook/vue3';
|
|
2
2
|
|
3
3
|
import Button from './Button.vue';
|
4
4
|
|
5
|
-
// More on how to set up stories at: https://storybook.js.org/docs/
|
5
|
+
// More on how to set up stories at: https://storybook.js.org/docs/vue/writing-stories/introduction
|
6
6
|
const meta = {
|
7
7
|
title: 'Example/Button',
|
8
8
|
component: Button,
|
9
|
-
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/
|
9
|
+
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/vue/writing-docs/autodocs
|
10
10
|
tags: ['autodocs'],
|
11
11
|
argTypes: {
|
12
12
|
size: { control: 'select', options: ['small', 'medium', 'large'] },
|
@@ -20,7 +20,7 @@ export default meta;
|
|
20
20
|
type Story = StoryObj<typeof meta>;
|
21
21
|
/*
|
22
22
|
*👇 Render functions are a framework specific feature to allow you control on how the component renders.
|
23
|
-
* See https://storybook.js.org/docs/
|
23
|
+
* See https://storybook.js.org/docs/vue/api/csf
|
24
24
|
* to learn how to use render functions.
|
25
25
|
*/
|
26
26
|
export const Primary: Story = {
|
@@ -4,7 +4,7 @@ import MyHeader from './Header.vue';
|
|
4
4
|
|
5
5
|
const meta = {
|
6
6
|
/* 👇 The title prop is optional.
|
7
|
-
* See https://storybook.js.org/docs/
|
7
|
+
* See https://storybook.js.org/docs/vue/configure/overview#configure-story-loading
|
8
8
|
* to learn how to generate automatic titles
|
9
9
|
*/
|
10
10
|
title: 'Example/Header',
|
@@ -17,10 +17,10 @@ const meta = {
|
|
17
17
|
template: '<my-header :user="args.user" />',
|
18
18
|
}),
|
19
19
|
parameters: {
|
20
|
-
// More on how to position stories at: https://storybook.js.org/docs/
|
20
|
+
// More on how to position stories at: https://storybook.js.org/docs/react/configure/story-layout
|
21
21
|
layout: 'fullscreen',
|
22
22
|
},
|
23
|
-
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/
|
23
|
+
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/vue/writing-docs/autodocs
|
24
24
|
tags: ['autodocs'],
|
25
25
|
} satisfies Meta<typeof MyHeader>;
|
26
26
|
|
@@ -10,17 +10,17 @@ const meta = {
|
|
10
10
|
template: '<my-page />',
|
11
11
|
}),
|
12
12
|
parameters: {
|
13
|
-
// More on how to position stories at: https://storybook.js.org/docs/
|
13
|
+
// More on how to position stories at: https://storybook.js.org/docs/vue/configure/story-layout
|
14
14
|
layout: 'fullscreen',
|
15
15
|
},
|
16
|
-
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/
|
16
|
+
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/vue/writing-docs/autodocs
|
17
17
|
tags: ['autodocs'],
|
18
18
|
} satisfies Meta<typeof MyPage>;
|
19
19
|
|
20
20
|
export default meta;
|
21
21
|
type Story = StoryObj<typeof meta>;
|
22
22
|
|
23
|
-
// More on interaction testing: https://storybook.js.org/docs/
|
23
|
+
// More on interaction testing: https://storybook.js.org/docs/vue/writing-tests/interaction-testing
|
24
24
|
export const LoggedIn: Story = {
|
25
25
|
play: async ({ canvasElement }: any) => {
|
26
26
|
const canvas = within(canvasElement);
|
@@ -2,12 +2,37 @@ import { global as globalThis } from '@storybook/global';
|
|
2
2
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
3
3
|
import { setup } from '@storybook/vue3';
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
//
|
8
|
-
//
|
5
|
+
const somePlugin = {
|
6
|
+
install: (app, options) => {
|
7
|
+
// inject a globally available $greetingText() method
|
8
|
+
// eslint-disable-next-line no-param-reassign
|
9
|
+
app.config.globalProperties.$greetingMessage = (key) => {
|
10
|
+
// retrieve a nested property in `options`
|
11
|
+
// using `key`
|
12
|
+
return options.greetings[key];
|
13
|
+
};
|
14
|
+
},
|
15
|
+
};
|
16
|
+
const someColor = 'someColor';
|
9
17
|
|
18
|
+
// add components to global scope
|
10
19
|
setup((app) => {
|
11
20
|
// This adds a component that can be used globally in stories
|
12
21
|
app.component('GlobalButton', globalThis.Components.Button);
|
13
22
|
});
|
23
|
+
|
24
|
+
// this adds a plugin to vue app that can be used globally in stories
|
25
|
+
setup((app, context) => {
|
26
|
+
app.use(somePlugin, {
|
27
|
+
greetings: {
|
28
|
+
hello: `Hello Story! from some plugin your name is ${context?.name}!`,
|
29
|
+
welcome: `Welcome Story! from some plugin your name is ${context?.name}!`,
|
30
|
+
hi: `Hi Story! from some plugin your name is ${context?.name}!`,
|
31
|
+
},
|
32
|
+
});
|
33
|
+
});
|
34
|
+
|
35
|
+
// additonal setup to provide some propriety to the app
|
36
|
+
setup((app, context) => {
|
37
|
+
app.provide(someColor, 'green');
|
38
|
+
});
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<script setup lang="ts">
|
2
|
+
defineProps({
|
3
|
+
label: String,
|
4
|
+
});
|
5
|
+
</script>
|
6
|
+
<template>
|
7
|
+
<div>
|
8
|
+
<header data-testid="header-slot">
|
9
|
+
<slot name="header" title="Header title from the slot"></slot>
|
10
|
+
</header>
|
11
|
+
<main data-testid="default-slot">
|
12
|
+
<slot></slot>
|
13
|
+
</main>
|
14
|
+
<footer data-testid="footer-slot">
|
15
|
+
<slot name="footer"></slot>
|
16
|
+
</footer>
|
17
|
+
</div>
|
18
|
+
</template>
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import type { Meta } from '@storybook/vue3';
|
2
|
+
import { h } from 'vue';
|
3
|
+
import Reactivity from './Reactivity.vue';
|
4
|
+
import * as ReactiveDecorators from './ReactiveDecorators.stories';
|
5
|
+
|
6
|
+
const meta = {
|
7
|
+
...ReactiveDecorators.default,
|
8
|
+
component: Reactivity,
|
9
|
+
// storybook render function is not a functional component. it returns a functional component or a component options
|
10
|
+
render: (args) => {
|
11
|
+
// create the slot contents as a functional components
|
12
|
+
const header = ({ title }: { title: string }) => h('h3', `${args.header} - Title: ${title}`);
|
13
|
+
const defaultSlot = () => h('p', `${args.default}`);
|
14
|
+
const footer = () => h('p', `${args.footer}`);
|
15
|
+
// vue render function is a functional components
|
16
|
+
return () =>
|
17
|
+
h('div', [
|
18
|
+
`Custom render uses a functional component, and passes slots to the component:`,
|
19
|
+
h(Reactivity, args, { header, default: defaultSlot, footer }),
|
20
|
+
]);
|
21
|
+
},
|
22
|
+
} satisfies Meta<typeof Reactivity>;
|
23
|
+
|
24
|
+
export default meta;
|
25
|
+
|
26
|
+
export {
|
27
|
+
NoDecorators,
|
28
|
+
DecoratorFunctionalComponent,
|
29
|
+
DecoratorFunctionalComponentArgsFromContext,
|
30
|
+
DecoratorFunctionalComponentArgsFromProps,
|
31
|
+
DecoratorComponentOptions,
|
32
|
+
DecoratorComponentOptionsArgsFromData,
|
33
|
+
DecoratorComponentOptionsArgsFromProps,
|
34
|
+
} from './ReactiveDecorators.stories';
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import type { Meta } from '@storybook/vue3';
|
2
|
+
import { defineComponent, shallowReactive } from 'vue';
|
3
|
+
import Reactivity from './Reactivity.vue';
|
4
|
+
import * as ReactiveDecorators from './ReactiveDecorators.stories';
|
5
|
+
|
6
|
+
// when you use custom render, you can use any vue api to create your story and garanti reactivity, otherwise i can ease kill the reactivity.
|
7
|
+
const state = shallowReactive<{ header: any; default: any; footer: any }>({
|
8
|
+
header: '',
|
9
|
+
default: '',
|
10
|
+
footer: '',
|
11
|
+
}); // or reactive
|
12
|
+
|
13
|
+
const meta = {
|
14
|
+
...ReactiveDecorators.default,
|
15
|
+
component: Reactivity,
|
16
|
+
render: (args, { argTypes }) => {
|
17
|
+
state.header = args.header;
|
18
|
+
state.default = args.default;
|
19
|
+
state.footer = args.footer;
|
20
|
+
// return a component options
|
21
|
+
return defineComponent({
|
22
|
+
data: () => ({ args, header: state.header, default: state.default, footer: state.footer }),
|
23
|
+
components: {
|
24
|
+
Reactivity,
|
25
|
+
},
|
26
|
+
template: `<div>Custom render uses options api and binds args to data:
|
27
|
+
<Reactivity v-bind="args">
|
28
|
+
<template #header="{title}"><h3>{{ args.header }} - Title: {{ title }}</h3></template>
|
29
|
+
<template #default>{{ args.default }}</template>
|
30
|
+
<template #footer>{{ args.footer }} </template>
|
31
|
+
</Reactivity>
|
32
|
+
</div>`,
|
33
|
+
});
|
34
|
+
},
|
35
|
+
} satisfies Meta<typeof Reactivity>;
|
36
|
+
|
37
|
+
export default meta;
|
38
|
+
|
39
|
+
export {
|
40
|
+
NoDecorators,
|
41
|
+
DecoratorFunctionalComponent,
|
42
|
+
DecoratorFunctionalComponentArgsFromContext,
|
43
|
+
DecoratorFunctionalComponentArgsFromProps,
|
44
|
+
DecoratorComponentOptions,
|
45
|
+
DecoratorComponentOptionsArgsFromData,
|
46
|
+
DecoratorComponentOptionsArgsFromProps,
|
47
|
+
} from './ReactiveDecorators.stories';
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import type { Meta } from '@storybook/vue3';
|
2
|
+
import { defineComponent } from 'vue';
|
3
|
+
import Reactivity from './Reactivity.vue';
|
4
|
+
import * as ReactiveDecorators from './ReactiveDecorators.stories';
|
5
|
+
|
6
|
+
const meta = {
|
7
|
+
...ReactiveDecorators.default,
|
8
|
+
component: Reactivity,
|
9
|
+
render: (args, { argTypes }) => {
|
10
|
+
return defineComponent({
|
11
|
+
props: Object.keys(argTypes),
|
12
|
+
components: { Reactivity },
|
13
|
+
template: `<div>Custom render uses options api and binds args to props: <Reactivity v-bind="$props">
|
14
|
+
<template #header="{title}"><h3>{{ header }} - Title: {{ title }}</h3></template>
|
15
|
+
{{ $props.default }}
|
16
|
+
<template #footer>{{ footer }}</template>
|
17
|
+
</Reactivity>
|
18
|
+
</div>`,
|
19
|
+
});
|
20
|
+
},
|
21
|
+
} satisfies Meta<typeof Reactivity>;
|
22
|
+
|
23
|
+
export default meta;
|
24
|
+
|
25
|
+
export {
|
26
|
+
NoDecorators,
|
27
|
+
DecoratorFunctionalComponent,
|
28
|
+
DecoratorFunctionalComponentArgsFromContext,
|
29
|
+
DecoratorFunctionalComponentArgsFromProps,
|
30
|
+
DecoratorComponentOptions,
|
31
|
+
DecoratorComponentOptionsArgsFromData,
|
32
|
+
DecoratorComponentOptionsArgsFromProps,
|
33
|
+
} from './ReactiveDecorators.stories';
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import { expect } from '@storybook/jest';
|
2
|
+
import type { Meta, StoryObj } from '@storybook/vue3';
|
3
|
+
import { within } from '@storybook/testing-library';
|
4
|
+
import { inject } from 'vue';
|
5
|
+
import GlobalSetup from './GlobalSetup.vue';
|
6
|
+
|
7
|
+
const meta: Meta = {
|
8
|
+
component: GlobalSetup,
|
9
|
+
argTypes: {},
|
10
|
+
render: (args: any) => ({
|
11
|
+
// Components used in your story `template` are defined in the `components` object
|
12
|
+
components: { GlobalUsage: GlobalSetup },
|
13
|
+
// The story's `args` need to be mapped into the template through the `setup()` method
|
14
|
+
setup() {
|
15
|
+
const color = inject('someColor', 'red'); // <-- this is the global setup from .storybook/preview.ts
|
16
|
+
return { args: { ...args, backgroundColor: color } };
|
17
|
+
},
|
18
|
+
// And then the `args` are bound to your component with `v-bind="args"`
|
19
|
+
template: '<global-usage v-bind="args" />',
|
20
|
+
}),
|
21
|
+
} satisfies Meta<typeof GlobalSetup>;
|
22
|
+
export default meta;
|
23
|
+
|
24
|
+
type Story = StoryObj<typeof meta>;
|
25
|
+
|
26
|
+
export const Primary: Story = {
|
27
|
+
args: {
|
28
|
+
primary: true,
|
29
|
+
label: 'someColor injected from .storybook/preview.ts',
|
30
|
+
},
|
31
|
+
play: async ({ canvasElement, id }) => {
|
32
|
+
const canvas = within(canvasElement);
|
33
|
+
|
34
|
+
const button = await canvas.getByRole('button');
|
35
|
+
await expect(button).toHaveStyle('background-color: rgb(0, 128, 0)'); // <-- this provide themeColor = green from .storybook/preview.ts
|
36
|
+
|
37
|
+
const h2 = await canvas.getByRole('heading', { level: 2 });
|
38
|
+
await expect(h2).toHaveTextContent('Hi Story! from some plugin your name is Primary!');
|
39
|
+
|
40
|
+
const h3 = await canvas.getByRole('heading', { level: 3 });
|
41
|
+
await expect(h3).toHaveTextContent('Hello Story! from some plugin your name is Primary!');
|
42
|
+
|
43
|
+
const h4 = await canvas.getByRole('heading', { level: 4 });
|
44
|
+
await expect(h4).toHaveTextContent('Welcome Story! from some plugin your name is Primary!');
|
45
|
+
},
|
46
|
+
};
|
47
|
+
|
48
|
+
export const Secondary: Story = {
|
49
|
+
args: {
|
50
|
+
label: 'someColor injected from .storybook/preview.ts',
|
51
|
+
},
|
52
|
+
};
|
@@ -3,7 +3,7 @@ import GlobalUsage from './GlobalUsage.vue';
|
|
3
3
|
export default {
|
4
4
|
component: GlobalUsage,
|
5
5
|
argTypes: {},
|
6
|
-
render: (args) => ({
|
6
|
+
render: (args: any) => ({
|
7
7
|
// Components used in your story `template` are defined in the `components` object
|
8
8
|
components: { GlobalUsage },
|
9
9
|
// The story's `args` need to be mapped into the template through the `setup()` method
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<!-- <MyComponent> template -->
|
2
|
+
<script setup lang="ts">
|
3
|
+
const props = defineProps({
|
4
|
+
label: String,
|
5
|
+
year: Number,
|
6
|
+
});
|
7
|
+
</script>
|
8
|
+
<template>
|
9
|
+
<div data-testid="scoped-slot">
|
10
|
+
<slot :text="`Hello ${props.label} from the slot`" :year="props.year"></slot>
|
11
|
+
</div>
|
12
|
+
</template>
|
@@ -10,7 +10,7 @@ const icons = {
|
|
10
10
|
},
|
11
11
|
};
|
12
12
|
|
13
|
-
|
13
|
+
const meta = {
|
14
14
|
component: OverrideArgs,
|
15
15
|
argTypes: {
|
16
16
|
// To show that other props are passed through
|
@@ -39,4 +39,6 @@ export default {
|
|
39
39
|
},
|
40
40
|
};
|
41
41
|
|
42
|
+
export default meta;
|
43
|
+
|
42
44
|
export const TestOne = {};
|