@storybook/vue3 7.0.0-beta.8 → 7.0.0-rc.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.
Files changed (37) hide show
  1. package/dist/chunk-2GDW2BFM.mjs +1 -0
  2. package/dist/config.d.ts +8 -5
  3. package/dist/config.js +46 -4
  4. package/dist/config.mjs +46 -1
  5. package/dist/index.d.ts +14 -7
  6. package/dist/index.js +1 -4
  7. package/dist/index.mjs +1 -1
  8. package/dist/{render-e631cd2d.d.ts → render-c842c5d5.d.ts} +1 -1
  9. package/package.json +12 -14
  10. package/template/cli/{Button.stories.js → js/Button.stories.js} +1 -1
  11. package/template/cli/{Button.vue → js/Button.vue} +2 -2
  12. package/template/cli/{Header.stories.js → js/Header.stories.js} +2 -2
  13. package/template/cli/js/Header.vue +59 -0
  14. package/template/cli/{Page.vue → js/Page.vue} +3 -8
  15. package/template/cli/ts-3-8/Button.stories.ts +52 -0
  16. package/template/cli/ts-3-8/Button.vue +48 -0
  17. package/template/cli/ts-3-8/Header.stories.ts +42 -0
  18. package/template/cli/{Header.vue → ts-3-8/Header.vue} +8 -12
  19. package/template/cli/ts-3-8/Page.stories.ts +34 -0
  20. package/template/cli/ts-3-8/Page.vue +70 -0
  21. package/template/cli/ts-4-9/Button.stories.ts +52 -0
  22. package/template/cli/ts-4-9/Button.vue +48 -0
  23. package/template/cli/ts-4-9/Header.stories.ts +42 -0
  24. package/template/cli/ts-4-9/Header.vue +37 -0
  25. package/template/cli/ts-4-9/Page.stories.ts +34 -0
  26. package/template/cli/ts-4-9/Page.vue +70 -0
  27. package/template/components/Button.vue +2 -2
  28. package/template/components/Html.vue +1 -3
  29. package/template/components/index.js +1 -1
  30. package/template/stories/OverrideArgs.stories.js +1 -2
  31. package/template/stories/ReactiveArgs.stories.js +44 -0
  32. package/template/stories/ReactiveArgs.vue +40 -0
  33. package/template/stories/decorators.stories.js +1 -1
  34. package/template/stories/preview.js +1 -1
  35. package/template/stories/vue3-mdx.stories.mdx +1 -1
  36. package/dist/chunk-OBKGUFRJ.mjs +0 -4
  37. /package/template/cli/{Page.stories.js → js/Page.stories.js} +0 -0
@@ -0,0 +1,34 @@
1
+ import type { Meta, StoryObj } from '@storybook/vue3';
2
+ import { within, userEvent } from '@storybook/testing-library';
3
+ import MyPage from './Page.vue';
4
+
5
+ const meta = {
6
+ title: 'Example/Page',
7
+ component: MyPage,
8
+ render: () => ({
9
+ components: { MyPage },
10
+ template: '<my-page />',
11
+ }),
12
+ parameters: {
13
+ // More on how to position stories at: https://storybook.js.org/docs/7.0/vue/configure/story-layout
14
+ layout: 'fullscreen',
15
+ },
16
+ // This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/7.0/vue/writing-docs/docs-page
17
+ tags: ['autodocs'],
18
+ } satisfies Meta<typeof MyPage>;
19
+
20
+ export default meta;
21
+ type Story = StoryObj<typeof meta>;
22
+
23
+ // More on interaction testing: https://storybook.js.org/docs/7.0/vue/writing-tests/interaction-testing
24
+ export const LoggedIn: Story = {
25
+ play: async ({ canvasElement }: any) => {
26
+ const canvas = within(canvasElement);
27
+ const loginButton = await canvas.getByRole('button', {
28
+ name: /Log in/i,
29
+ });
30
+ await userEvent.click(loginButton);
31
+ },
32
+ };
33
+
34
+ export const LoggedOut: Story = {};
@@ -0,0 +1,70 @@
1
+ <template>
2
+ <article>
3
+ <my-header :user="user" @login="onLogin" @logout="onLogout" @create-account="onCreateAccount" />
4
+
5
+ <section>
6
+ <h2>Pages in Storybook</h2>
7
+ <p>
8
+ We recommend building UIs with a
9
+ <a href="https://componentdriven.org" target="_blank" rel="noopener noreferrer">
10
+ <strong>component-driven</strong>
11
+ </a>
12
+ process starting with atomic components and ending with pages.
13
+ </p>
14
+ <p>
15
+ Render pages with mock data. This makes it easy to build and review page states without
16
+ needing to navigate to them in your app. Here are some handy patterns for managing page data
17
+ in Storybook:
18
+ </p>
19
+ <ul>
20
+ <li>
21
+ Use a higher-level connected component. Storybook helps you compose such data from the
22
+ "args" of child component stories
23
+ </li>
24
+ <li>
25
+ Assemble data in the page component from your services. You can mock these services out
26
+ using Storybook.
27
+ </li>
28
+ </ul>
29
+ <p>
30
+ Get a guided tutorial on component-driven development at
31
+ <a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer">Storybook tutorials</a>
32
+ . Read more in the
33
+ <a href="https://storybook.js.org/docs" target="_blank" rel="noopener noreferrer">docs</a>
34
+ .
35
+ </p>
36
+ <div class="tip-wrapper">
37
+ <span class="tip">Tip</span>
38
+ Adjust the width of the canvas with the
39
+ <svg width="10" height="10" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg">
40
+ <g fill="none" fill-rule="evenodd">
41
+ <path
42
+ d="M1.5 5.2h4.8c.3 0 .5.2.5.4v5.1c-.1.2-.3.3-.4.3H1.4a.5.5 0 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 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"
43
+ id="a" fill="#999" />
44
+ </g>
45
+ </svg>
46
+ Viewports addon in the toolbar
47
+ </div>
48
+ </section>
49
+ </article>
50
+ </template>
51
+
52
+ <script lang="ts" setup>
53
+ import './page.css';
54
+ import MyHeader from './Header.vue';
55
+
56
+ import { ref } from 'vue';
57
+
58
+ const user = ref<{ name: string } | null>(null)
59
+
60
+ const onLogin = () => {
61
+ user.value = { name: 'Jane Doe' };
62
+ };
63
+ const onLogout = () => {
64
+ user.value = null;
65
+ };
66
+ const onCreateAccount = () => {
67
+ user.value = { name: 'Jane Doe' };
68
+ };
69
+
70
+ </script>
@@ -45,8 +45,8 @@ export default {
45
45
  })),
46
46
  onClick() {
47
47
  emit('click');
48
- }
49
- }
48
+ },
49
+ };
50
50
  },
51
51
  };
52
52
  </script>
@@ -3,7 +3,6 @@
3
3
  </template>
4
4
 
5
5
  <script>
6
-
7
6
  export default {
8
7
  name: 'my-html',
9
8
 
@@ -14,7 +13,6 @@ export default {
14
13
  },
15
14
  },
16
15
 
17
-
18
- setup() { },
16
+ setup() {},
19
17
  };
20
18
  </script>
@@ -1,4 +1,4 @@
1
- import globalThis from 'global';
1
+ import { global as globalThis } from '@storybook/global';
2
2
 
3
3
  import Button from './Button.vue';
4
4
  import Pre from './Pre.vue';
@@ -20,13 +20,12 @@ export default {
20
20
  type: 'select',
21
21
  options: Object.keys(icons),
22
22
  },
23
- defaultValue: 'Primary',
24
23
  },
25
24
  },
26
25
  render: (args) => {
27
26
  // Individual properties can be overridden by spreading the args
28
27
  // and the replacing the key-values that need to be updated
29
- args = { ...args, icon: icons[args.icon] }; // eslint-disable-line no-param-reassign
28
+ args = { ...args, icon: icons[args.icon || 'Primary'] }; // eslint-disable-line no-param-reassign
30
29
  return {
31
30
  // Components used in your story `template` are defined in the `components` object
32
31
  components: { OverrideArgs },
@@ -0,0 +1,44 @@
1
+ import { expect } from '@storybook/jest';
2
+ import { global as globalThis } from '@storybook/global';
3
+ import { within, userEvent } from '@storybook/testing-library';
4
+ import { UPDATE_STORY_ARGS, STORY_ARGS_UPDATED, RESET_STORY_ARGS } from '@storybook/core-events';
5
+ import ReactiveArgs from './ReactiveArgs.vue';
6
+
7
+ export default {
8
+ component: ReactiveArgs,
9
+ argTypes: {
10
+ // To show that other props are passed through
11
+ backgroundColor: { control: 'color' },
12
+ },
13
+ };
14
+
15
+ export const ReactiveTest = {
16
+ args: {
17
+ label: 'Button',
18
+ },
19
+ // test that args are updated correctly in rective mode
20
+ play: async ({ canvasElement, id }) => {
21
+ const channel = globalThis.__STORYBOOK_ADDONS_CHANNEL__;
22
+ const canvas = within(canvasElement);
23
+
24
+ await channel.emit(RESET_STORY_ARGS, { storyId: id });
25
+ await new Promise((resolve) => {
26
+ channel.once(STORY_ARGS_UPDATED, resolve);
27
+ });
28
+ const reactiveButton = await canvas.getByRole('button');
29
+ await expect(reactiveButton).toHaveTextContent('Button 0');
30
+
31
+ await userEvent.click(reactiveButton); // click to update the label to increment the count + 1
32
+ await channel.emit(UPDATE_STORY_ARGS, {
33
+ storyId: id,
34
+ updatedArgs: { label: 'updated' },
35
+ });
36
+ await new Promise((resolve) => {
37
+ channel.once(STORY_ARGS_UPDATED, resolve);
38
+ });
39
+ await expect(canvas.getByRole('button')).toHaveTextContent('updated 1');
40
+
41
+ await userEvent.click(reactiveButton); // click to update the label to increment the count + 1
42
+ await expect(reactiveButton).toHaveTextContent('updated 2');
43
+ },
44
+ };
@@ -0,0 +1,40 @@
1
+ <template>
2
+ <button type="button" @click="onClick" :class="classes" :style="style">{{ label }} {{ counter }}</button>
3
+ </template>
4
+
5
+ <script>
6
+ import { computed, ref } from 'vue';
7
+
8
+ export default {
9
+ name: 'reactive-args',
10
+
11
+ props: {
12
+ label: {
13
+ type: String,
14
+ },
15
+
16
+ backgroundColor: {
17
+ type: String
18
+ },
19
+ },
20
+
21
+ setup(props, { emit }) {
22
+ const classes = {
23
+ 'storybook-button': true,
24
+ 'storybook-button--primary': true,
25
+ 'storybook-button--large': true,
26
+ };
27
+ const style = computed(() => ({
28
+ backgroundColor: props.backgroundColor,
29
+ }));
30
+ const counter = ref(0);
31
+ const onClick = () => {
32
+ emit('click', 1);
33
+ counter.value += 1;
34
+ };
35
+
36
+ // Notice that `icon` prop component is still passed through even though it isn't mapped
37
+ return { classes, style, counter, onClick }
38
+ },
39
+ };
40
+ </script>
@@ -1,4 +1,4 @@
1
- import globalThis from 'global';
1
+ import { global as globalThis } from '@storybook/global';
2
2
  import { h } from 'vue';
3
3
 
4
4
  const { Button, Pre } = globalThis.Components;
@@ -1,4 +1,4 @@
1
- import globalThis from 'global';
1
+ 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
 
@@ -1,4 +1,4 @@
1
- import globalThis from 'global';
1
+ import { global as globalThis } from '@storybook/global';
2
2
  import { Meta, Story, Canvas } from '@storybook/addon-docs';
3
3
 
4
4
  <Meta title="stories/renderers/vue3/vue3-mdx" />
@@ -1,4 +0,0 @@
1
- import{h}from"vue";import{sanitizeStoryContextUpdate}from"@storybook/preview-api";function normalizeFunctionalComponent(options){return typeof options=="function"?{render:options,name:options.name}:options}function prepare(rawStory,innerStory){let story=rawStory;return story==null?null:innerStory?{...normalizeFunctionalComponent(story),components:{...story.components||{},story:innerStory}}:{render(){return h(story)}}}function decorateStory(storyFn,decorators){return decorators.reduce((decorated,decorator)=>context=>{let story,decoratedStory=decorator(update=>(story=decorated({...context,...sanitizeStoryContextUpdate(update)}),story),context);return story||(story=decorated(context)),decoratedStory===story?story:prepare(decoratedStory,story)},context=>prepare(storyFn(context)))}import{dedent}from"ts-dedent";import{createApp,h as h2}from"vue";var render=(props,context)=>{let{id,component:Component}=context;if(!Component)throw new Error(`Unable to render story ${id} as the component annotation is missing from the default export`);return h2(Component,props)},setupFunction=app=>{},setup=fn=>{setupFunction=fn},map=new Map;function renderToCanvas({title,name,storyFn,showMain,showError,showException},canvasElement){let element,storybookApp=createApp({unmounted(){map.delete(canvasElement)},render(){return map.set(canvasElement,storybookApp),setupFunction(storybookApp),h2(element)}});if(storybookApp.config.errorHandler=e=>showException(e),element=storyFn(),!element){showError({title:`Expecting a Vue component from the story: "${name}" of "${title}".`,description:dedent`
2
- Did you forget to return the Vue component from the story?
3
- Use "() => ({ template: '<my-comp></my-comp>' })" or "() => ({ components: MyComp, template: '<my-comp></my-comp>' })" when defining the story.
4
- `});return}showMain(),map.get(canvasElement)?.unmount(),storybookApp.mount(canvasElement)}export{decorateStory,render,setup,renderToCanvas};