@storybook/vue3 7.1.0-alpha.1 → 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.
Files changed (34) hide show
  1. package/dist/chunk-3MGVBGQN.mjs +1 -0
  2. package/dist/config.d.ts +2 -2
  3. package/dist/config.js +3 -3
  4. package/dist/config.mjs +3 -3
  5. package/dist/index.d.ts +2 -2
  6. package/dist/index.js +1 -1
  7. package/dist/index.mjs +1 -1
  8. package/dist/render-32b7dd3f.d.ts +148 -0
  9. package/package.json +6 -6
  10. package/template/stories/preview.js +29 -4
  11. package/template/stories_vue3-vite-default-ts/BaseLayout.vue +18 -0
  12. package/template/stories_vue3-vite-default-ts/CustomRenderFunctionalComponent.stories.ts +34 -0
  13. package/template/stories_vue3-vite-default-ts/CustomRenderOptionsArgsFromData.stories.ts +47 -0
  14. package/template/stories_vue3-vite-default-ts/CustomRenderOptionsArgsFromProps.stories.ts +33 -0
  15. package/template/stories_vue3-vite-default-ts/GlobalSetup.stories.ts +52 -0
  16. package/template/stories_vue3-vite-default-ts/GlobalSetup.vue +6 -0
  17. package/template/{stories/GlobalUsage.stories.js → stories_vue3-vite-default-ts/GlobalUsage.stories.ts} +1 -1
  18. package/template/stories_vue3-vite-default-ts/GlobalUsage.vue +3 -0
  19. package/template/stories_vue3-vite-default-ts/MySlotComponent.vue +12 -0
  20. package/template/{stories → stories_vue3-vite-default-ts}/OverrideArgs.stories.js +3 -1
  21. package/template/{stories → stories_vue3-vite-default-ts}/OverrideArgs.vue +3 -3
  22. package/template/stories_vue3-vite-default-ts/ReactiveArgs.stories.ts +135 -0
  23. package/template/stories_vue3-vite-default-ts/ReactiveDecorators.stories.ts +112 -0
  24. package/template/stories_vue3-vite-default-ts/ReactiveSlots.stories.ts +127 -0
  25. package/template/stories_vue3-vite-default-ts/Reactivity.vue +44 -0
  26. package/template/stories_vue3-vite-default-ts/ScopedSlots.stories.ts +81 -0
  27. package/template/stories_vue3-vite-default-ts/decorators.stories.ts +84 -0
  28. package/template/stories_vue3-vite-default-ts/preview.ts +12 -0
  29. package/dist/chunk-2GDW2BFM.mjs +0 -1
  30. package/dist/render-c842c5d5.d.ts +0 -14
  31. package/template/stories/GlobalUsage.vue +0 -3
  32. package/template/stories/ReactiveArgs.stories.js +0 -44
  33. package/template/stories/decorators.stories.js +0 -66
  34. /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.1",
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.1",
52
- "@storybook/docs-tools": "7.1.0-alpha.1",
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.1",
55
- "@storybook/types": "7.1.0-alpha.1",
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": "48a1df25493b1cc26a405096e723301f4bb04b4e"
83
+ "gitHead": "e7c833e690dd0d2966ffb7fb806a3bda89a508c8"
84
84
  }
@@ -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
- // TODO: I'd like to be able to export rather than imperatively calling an imported function
6
- // export const setup = (app) => {
7
- // app.component('GlobalButton', Button);
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
+ };
@@ -0,0 +1,6 @@
1
+ <template>
2
+ <global-button v-bind="$attrs"> </global-button>
3
+ <h2> Hi message: {{ $greetingMessage('hi') }}</h2>
4
+ <h3> Hello message: {{ $greetingMessage('hello') }}</h3>
5
+ <h4> Welcome message: {{ $greetingMessage('welcome') }}</h4>
6
+ </template>
@@ -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,3 @@
1
+ <template>
2
+ <global-button />
3
+ </template>
@@ -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
- export default {
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 = {};
@@ -5,8 +5,8 @@
5
5
  </button>
6
6
  </template>
7
7
 
8
- <script lang="typescript">
9
- import { h, computed, reactive } from 'vue';
8
+ <script lang="ts">
9
+ import { computed } from 'vue';
10
10
 
11
11
  export default {
12
12
  name: 'override-args',
@@ -22,7 +22,7 @@ export default {
22
22
  },
23
23
  },
24
24
 
25
- // @ts-expect-error (Converted from ts-ignore)
25
+
26
26
  setup(props, { emit }) {
27
27
  const classes = {
28
28
  'storybook-button': true,
@@ -0,0 +1,135 @@
1
+ import { expect } from '@storybook/jest';
2
+ import { global as globalThis } from '@storybook/global';
3
+ import type { Meta, StoryObj, StoryFn } from '@storybook/vue3';
4
+ import { within, userEvent } from '@storybook/testing-library';
5
+ import { UPDATE_STORY_ARGS, STORY_ARGS_UPDATED, RESET_STORY_ARGS } from '@storybook/core-events';
6
+
7
+ import ReactiveArgs from './ReactiveArgs.vue';
8
+
9
+ const meta = {
10
+ component: ReactiveArgs,
11
+ argTypes: {
12
+ // To show that other props are passed through
13
+ backgroundColor: { control: 'color' },
14
+ },
15
+ } satisfies Meta<typeof ReactiveArgs>;
16
+
17
+ export default meta;
18
+
19
+ type Story = StoryObj<typeof meta>;
20
+
21
+ export const ReactiveTest: Story = {
22
+ args: {
23
+ label: 'Button',
24
+ },
25
+ // test that args are updated correctly in rective mode
26
+ play: async ({ canvasElement, id }) => {
27
+ const channel = globalThis.__STORYBOOK_ADDONS_CHANNEL__;
28
+ const canvas = within(canvasElement);
29
+
30
+ await channel.emit(RESET_STORY_ARGS, { storyId: id });
31
+ await new Promise((resolve) => {
32
+ channel.once(STORY_ARGS_UPDATED, resolve);
33
+ });
34
+ const reactiveButton = await canvas.getByRole('button');
35
+ await expect(reactiveButton).toHaveTextContent('Button 0');
36
+
37
+ await userEvent.click(reactiveButton); // click to update the label to increment the count + 1
38
+ await channel.emit(UPDATE_STORY_ARGS, {
39
+ storyId: id,
40
+ updatedArgs: { label: 'updated' },
41
+ });
42
+ await new Promise((resolve) => {
43
+ channel.once(STORY_ARGS_UPDATED, resolve);
44
+ });
45
+ await expect(canvas.getByRole('button')).toHaveTextContent('updated 1');
46
+
47
+ await userEvent.click(reactiveButton); // click to update the label to increment the count + 1
48
+ await expect(reactiveButton).toHaveTextContent('updated 2');
49
+ },
50
+ };
51
+
52
+ export const ReactiveHtmlWrapper: Story = {
53
+ args: { label: 'Wrapped Button' },
54
+
55
+ decorators: [
56
+ () => ({
57
+ template: `
58
+ <div style="border: 5px solid red;">
59
+ <story/>
60
+ </div>
61
+ `,
62
+ }),
63
+ ],
64
+ play: async ({ canvasElement, id }) => {
65
+ const channel = globalThis.__STORYBOOK_ADDONS_CHANNEL__;
66
+ const canvas = within(canvasElement);
67
+
68
+ await channel.emit(RESET_STORY_ARGS, { storyId: id });
69
+ await new Promise((resolve) => {
70
+ channel.once(STORY_ARGS_UPDATED, resolve);
71
+ });
72
+ const reactiveButton = await canvas.getByRole('button');
73
+ await expect(reactiveButton).toHaveTextContent('Wrapped Button 0');
74
+
75
+ await userEvent.click(reactiveButton); // click to update the label to increment the count + 1
76
+ await channel.emit(UPDATE_STORY_ARGS, {
77
+ storyId: id,
78
+ updatedArgs: { label: 'updated Wrapped Button' },
79
+ });
80
+ await new Promise((resolve) => {
81
+ channel.once(STORY_ARGS_UPDATED, resolve);
82
+ });
83
+ await expect(canvas.getByRole('button')).toHaveTextContent('updated Wrapped Button 1');
84
+
85
+ await userEvent.click(reactiveButton); // click to update the label to increment the count + 1
86
+ await expect(reactiveButton).toHaveTextContent('updated Wrapped Button 2');
87
+ },
88
+ };
89
+
90
+ // to test that Simple html Decorators in CSF2 format are applied correctly in reactive mode
91
+ const ReactiveCSF2WrapperTempl: StoryFn = (args, { argTypes }) => ({
92
+ components: { ReactiveArgs },
93
+ props: Object.keys(argTypes),
94
+ template: '<ReactiveArgs v-bind="$props" />',
95
+ });
96
+
97
+ export const ReactiveCSF2Wrapper = ReactiveCSF2WrapperTempl.bind({});
98
+
99
+ ReactiveCSF2Wrapper.args = {
100
+ label: 'CSF2 Wrapped Button',
101
+ };
102
+ ReactiveCSF2Wrapper.decorators = [
103
+ () => ({
104
+ template: `
105
+ <div style="border: 5px solid red;">
106
+ <story/>
107
+ </div>
108
+ `,
109
+ }),
110
+ ];
111
+
112
+ ReactiveCSF2Wrapper.play = async ({ canvasElement, id }) => {
113
+ const channel = globalThis.__STORYBOOK_ADDONS_CHANNEL__;
114
+ const canvas = within(canvasElement);
115
+
116
+ await channel.emit(RESET_STORY_ARGS, { storyId: id });
117
+ await new Promise((resolve) => {
118
+ channel.once(STORY_ARGS_UPDATED, resolve);
119
+ });
120
+ const reactiveButton = await canvas.getByRole('button');
121
+ await expect(reactiveButton).toHaveTextContent('CSF2 Wrapped Button 0');
122
+
123
+ await userEvent.click(reactiveButton); // click to update the label to increment the count + 1
124
+ await channel.emit(UPDATE_STORY_ARGS, {
125
+ storyId: id,
126
+ updatedArgs: { label: 'updated CSF2 Wrapped Button' },
127
+ });
128
+ await new Promise((resolve) => {
129
+ channel.once(STORY_ARGS_UPDATED, resolve);
130
+ });
131
+ await expect(canvas.getByRole('button')).toHaveTextContent('updated CSF2 Wrapped Button 1');
132
+
133
+ await userEvent.click(reactiveButton); // click to update the label to increment the count + 1
134
+ await expect(reactiveButton).toHaveTextContent('updated CSF2 Wrapped Button 2');
135
+ };