@storybook/vue3 7.0.0-beta.9 → 7.0.0-rc.1
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-2GDW2BFM.mjs +1 -0
- package/dist/config.d.ts +8 -5
- package/dist/config.js +46 -4
- package/dist/config.mjs +46 -1
- package/dist/index.d.ts +14 -7
- package/dist/index.js +1 -4
- package/dist/index.mjs +1 -1
- package/dist/{render-e631cd2d.d.ts → render-c842c5d5.d.ts} +1 -1
- package/package.json +12 -14
- package/template/cli/{Button.stories.js → js/Button.stories.js} +1 -1
- package/template/cli/{Button.vue → js/Button.vue} +2 -2
- package/template/cli/{Header.stories.js → js/Header.stories.js} +2 -2
- package/template/cli/js/Header.vue +59 -0
- package/template/cli/{Page.vue → js/Page.vue} +3 -8
- package/template/cli/ts-3-8/Button.stories.ts +52 -0
- package/template/cli/ts-3-8/Button.vue +48 -0
- package/template/cli/ts-3-8/Header.stories.ts +42 -0
- package/template/cli/{Header.vue → ts-3-8/Header.vue} +8 -12
- package/template/cli/ts-3-8/Page.stories.ts +34 -0
- package/template/cli/ts-3-8/Page.vue +70 -0
- package/template/cli/ts-4-9/Button.stories.ts +52 -0
- package/template/cli/ts-4-9/Button.vue +48 -0
- package/template/cli/ts-4-9/Header.stories.ts +42 -0
- package/template/cli/ts-4-9/Header.vue +37 -0
- package/template/cli/ts-4-9/Page.stories.ts +34 -0
- package/template/cli/ts-4-9/Page.vue +70 -0
- package/template/components/Button.vue +2 -2
- package/template/components/Html.vue +1 -3
- package/template/components/index.js +1 -1
- package/template/stories/OverrideArgs.stories.js +1 -2
- package/template/stories/ReactiveArgs.stories.js +44 -0
- package/template/stories/ReactiveArgs.vue +40 -0
- package/template/stories/decorators.stories.js +1 -1
- package/template/stories/preview.js +1 -1
- package/template/stories/vue3-mdx.stories.mdx +1 -1
- package/dist/chunk-OBKGUFRJ.mjs +0 -4
- /package/template/cli/{Page.stories.js → js/Page.stories.js} +0 -0
@@ -9,6 +9,6 @@ interface VueRenderer extends WebRenderer {
|
|
9
9
|
|
10
10
|
declare const render: ArgsStoryFn<VueRenderer>;
|
11
11
|
declare const setup: (fn: (app: any) => void) => void;
|
12
|
-
declare function renderToCanvas({
|
12
|
+
declare function renderToCanvas({ storyFn, forceRemount, showMain, showException, storyContext }: RenderContext<VueRenderer>, canvasElement: VueRenderer['canvasElement']): () => void;
|
13
13
|
|
14
14
|
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.0.0-
|
3
|
+
"version": "7.0.0-rc.1",
|
4
4
|
"description": "Storybook Vue 3 renderer",
|
5
5
|
"keywords": [
|
6
6
|
"storybook"
|
@@ -21,6 +21,7 @@
|
|
21
21
|
"license": "MIT",
|
22
22
|
"exports": {
|
23
23
|
".": {
|
24
|
+
"node": "./dist/index.js",
|
24
25
|
"require": "./dist/index.js",
|
25
26
|
"import": "./dist/index.mjs",
|
26
27
|
"types": "./dist/index.d.ts"
|
@@ -30,11 +31,7 @@
|
|
30
31
|
"import": "./dist/config.mjs",
|
31
32
|
"types": "./dist/config.d.ts"
|
32
33
|
},
|
33
|
-
"./package.json":
|
34
|
-
"require": "./package.json",
|
35
|
-
"import": "./package.json",
|
36
|
-
"types": "./package.json"
|
37
|
-
}
|
34
|
+
"./package.json": "./package.json"
|
38
35
|
},
|
39
36
|
"main": "dist/index.js",
|
40
37
|
"module": "dist/index.mjs",
|
@@ -51,20 +48,21 @@
|
|
51
48
|
"prep": "../../../scripts/prepare/bundle.ts"
|
52
49
|
},
|
53
50
|
"dependencies": {
|
54
|
-
"@storybook/core-client": "7.0.0-
|
55
|
-
"@storybook/docs-tools": "7.0.0-
|
56
|
-
"@storybook/
|
57
|
-
"@storybook/
|
58
|
-
"
|
51
|
+
"@storybook/core-client": "7.0.0-rc.1",
|
52
|
+
"@storybook/docs-tools": "7.0.0-rc.1",
|
53
|
+
"@storybook/global": "^5.0.0",
|
54
|
+
"@storybook/preview-api": "7.0.0-rc.1",
|
55
|
+
"@storybook/types": "7.0.0-rc.1",
|
59
56
|
"ts-dedent": "^2.0.0",
|
60
57
|
"type-fest": "2.19.0"
|
61
58
|
},
|
62
59
|
"devDependencies": {
|
63
60
|
"@digitak/esrun": "^3.2.2",
|
61
|
+
"@types/prettier": "2.7.2",
|
64
62
|
"@vue/vue3-jest": "29",
|
65
63
|
"typescript": "~4.9.3",
|
66
|
-
"vue": "^3.2.
|
67
|
-
"vue-tsc": "^1.0
|
64
|
+
"vue": "^3.2.47",
|
65
|
+
"vue-tsc": "^1.2.0"
|
68
66
|
},
|
69
67
|
"peerDependencies": {
|
70
68
|
"vue": "^3.0.0"
|
@@ -82,5 +80,5 @@
|
|
82
80
|
],
|
83
81
|
"platform": "browser"
|
84
82
|
},
|
85
|
-
"gitHead": "
|
83
|
+
"gitHead": "115d69123dc7c4dfab9538d2b273cb0fcc372852"
|
86
84
|
}
|
@@ -3,8 +3,8 @@ 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
|
7
|
-
tags: ['
|
6
|
+
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/7.0/vue/writing-docs/docs-page
|
7
|
+
tags: ['autodocs'],
|
8
8
|
render: (args) => ({
|
9
9
|
// Components used in your story `template` are defined in the `components` object
|
10
10
|
components: {
|
@@ -0,0 +1,59 @@
|
|
1
|
+
<template>
|
2
|
+
<header>
|
3
|
+
<div class="wrapper">
|
4
|
+
<div>
|
5
|
+
<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
|
6
|
+
<g fill="none" fill-rule="evenodd">
|
7
|
+
<path
|
8
|
+
d="M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z"
|
9
|
+
fill="#FFF"
|
10
|
+
/>
|
11
|
+
<path
|
12
|
+
d="M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z"
|
13
|
+
fill="#555AB9"
|
14
|
+
/>
|
15
|
+
<path
|
16
|
+
d="M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z"
|
17
|
+
fill="#91BAF8"
|
18
|
+
/>
|
19
|
+
</g>
|
20
|
+
</svg>
|
21
|
+
<h1>Acme</h1>
|
22
|
+
</div>
|
23
|
+
<div>
|
24
|
+
<span class="welcome" v-if="user"
|
25
|
+
>Welcome, <b>{{ user.name }}</b
|
26
|
+
>!</span
|
27
|
+
>
|
28
|
+
<my-button size="small" @click="$emit('logout')" label="Log out" v-if="user" />
|
29
|
+
<my-button size="small" @click="$emit('login')" label="Log in" v-if="!user" />
|
30
|
+
<my-button
|
31
|
+
primary
|
32
|
+
size="small"
|
33
|
+
@click="$emit('createAccount')"
|
34
|
+
label="Sign up"
|
35
|
+
v-if="!user"
|
36
|
+
/>
|
37
|
+
</div>
|
38
|
+
</div>
|
39
|
+
</header>
|
40
|
+
</template>
|
41
|
+
|
42
|
+
<script>
|
43
|
+
import './header.css';
|
44
|
+
import MyButton from './Button.vue';
|
45
|
+
|
46
|
+
export default {
|
47
|
+
name: 'my-header',
|
48
|
+
|
49
|
+
components: { MyButton },
|
50
|
+
|
51
|
+
props: {
|
52
|
+
user: {
|
53
|
+
type: Object,
|
54
|
+
},
|
55
|
+
},
|
56
|
+
|
57
|
+
emits: ['login', 'logout', 'createAccount'],
|
58
|
+
};
|
59
|
+
</script>
|
@@ -1,11 +1,6 @@
|
|
1
1
|
<template>
|
2
2
|
<article>
|
3
|
-
<my-header
|
4
|
-
:user="user"
|
5
|
-
@login="onLogin"
|
6
|
-
@logout="onLogout"
|
7
|
-
@createAccount="onCreateAccount"
|
8
|
-
/>
|
3
|
+
<my-header :user="user" @login="onLogin" @logout="onLogout" @createAccount="onCreateAccount" />
|
9
4
|
|
10
5
|
<section>
|
11
6
|
<h2>Pages in Storybook</h2>
|
@@ -69,8 +64,8 @@ export default {
|
|
69
64
|
|
70
65
|
data() {
|
71
66
|
return {
|
72
|
-
user: null
|
73
|
-
}
|
67
|
+
user: null,
|
68
|
+
};
|
74
69
|
},
|
75
70
|
|
76
71
|
methods: {
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3';
|
2
|
+
|
3
|
+
import Button from './Button.vue';
|
4
|
+
|
5
|
+
// More on how to set up stories at: https://storybook.js.org/docs/7.0/vue/writing-stories/introduction
|
6
|
+
const meta: Meta<typeof Button> = {
|
7
|
+
title: 'Example/Button',
|
8
|
+
component: Button,
|
9
|
+
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/7.0/vue/writing-docs/docs-page
|
10
|
+
tags: ['autodocs'],
|
11
|
+
argTypes: {
|
12
|
+
size: { control: 'select', options: ['small', 'medium', 'large'] },
|
13
|
+
backgroundColor: { control: 'color' },
|
14
|
+
onClick: { action: 'clicked' },
|
15
|
+
},
|
16
|
+
args: { primary: false }, // default value
|
17
|
+
};
|
18
|
+
|
19
|
+
export default meta;
|
20
|
+
type Story = StoryObj<typeof Button>;
|
21
|
+
/*
|
22
|
+
*👇 Render functions are a framework specific feature to allow you control on how the component renders.
|
23
|
+
* See https://storybook.js.org/docs/7.0/vue/api/csf
|
24
|
+
* to learn how to use render functions.
|
25
|
+
*/
|
26
|
+
export const Primary: Story = {
|
27
|
+
args: {
|
28
|
+
primary: true,
|
29
|
+
label: 'Button',
|
30
|
+
},
|
31
|
+
};
|
32
|
+
|
33
|
+
export const Secondary: Story = {
|
34
|
+
args: {
|
35
|
+
primary: false,
|
36
|
+
label: 'Button',
|
37
|
+
},
|
38
|
+
};
|
39
|
+
|
40
|
+
export const Large: Story = {
|
41
|
+
args: {
|
42
|
+
label: 'Button',
|
43
|
+
size: 'large',
|
44
|
+
},
|
45
|
+
};
|
46
|
+
|
47
|
+
export const Small: Story = {
|
48
|
+
args: {
|
49
|
+
label: 'Button',
|
50
|
+
size: 'small',
|
51
|
+
},
|
52
|
+
};
|
@@ -0,0 +1,48 @@
|
|
1
|
+
<template>
|
2
|
+
<button type="button" :class="classes" @click="onClick" :style="style">{{ label }} </button>
|
3
|
+
</template>
|
4
|
+
|
5
|
+
<script lang="ts" setup>
|
6
|
+
import "./buttons.css"
|
7
|
+
import { computed } from 'vue';
|
8
|
+
|
9
|
+
const props = withDefaults(defineProps<{
|
10
|
+
/**
|
11
|
+
* The label of the button
|
12
|
+
*/
|
13
|
+
label: string,
|
14
|
+
/**
|
15
|
+
* primary or secondary button
|
16
|
+
*/
|
17
|
+
primary?: boolean,
|
18
|
+
/**
|
19
|
+
* size of the button
|
20
|
+
*/
|
21
|
+
size?: 'small' | 'medium' | 'large',
|
22
|
+
/**
|
23
|
+
* background color of the button
|
24
|
+
*/
|
25
|
+
backgroundColor?: string,
|
26
|
+
|
27
|
+
}>(), { primary: false });
|
28
|
+
|
29
|
+
const emit = defineEmits<{
|
30
|
+
(e: 'click', id: number): void;
|
31
|
+
}>();
|
32
|
+
|
33
|
+
const classes = computed(() => ({
|
34
|
+
'storybook-button': true,
|
35
|
+
'storybook-button--primary': props.primary,
|
36
|
+
'storybook-button--secondary': !props.primary,
|
37
|
+
[`storybook-button--${props.size || 'medium'}`]: true,
|
38
|
+
}));
|
39
|
+
|
40
|
+
const style = computed(() => ({
|
41
|
+
backgroundColor: props.backgroundColor
|
42
|
+
}));
|
43
|
+
|
44
|
+
const onClick = () => {
|
45
|
+
emit("click", 1)
|
46
|
+
};
|
47
|
+
|
48
|
+
</script>
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3';
|
2
|
+
|
3
|
+
import MyHeader from './Header.vue';
|
4
|
+
|
5
|
+
const meta: Meta<typeof MyHeader> = {
|
6
|
+
/* 👇 The title prop is optional.
|
7
|
+
* See https://storybook.js.org/docs/7.0/vue/configure/overview#configure-story-loading
|
8
|
+
* to learn how to generate automatic titles
|
9
|
+
*/
|
10
|
+
title: 'Example/Header',
|
11
|
+
component: MyHeader,
|
12
|
+
render: (args: any) => ({
|
13
|
+
components: { MyHeader },
|
14
|
+
setup() {
|
15
|
+
return { args };
|
16
|
+
},
|
17
|
+
template: '<my-header :user="args.user" />',
|
18
|
+
}),
|
19
|
+
parameters: {
|
20
|
+
// More on how to position stories at: https://storybook.js.org/docs/7.0/react/configure/story-layout
|
21
|
+
layout: 'fullscreen',
|
22
|
+
},
|
23
|
+
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/7.0/vue/writing-docs/docs-page
|
24
|
+
tags: ['autodocs'],
|
25
|
+
};
|
26
|
+
|
27
|
+
export default meta;
|
28
|
+
type Story = StoryObj<typeof MyHeader>;
|
29
|
+
|
30
|
+
export const LoggedIn: Story = {
|
31
|
+
args: {
|
32
|
+
user: {
|
33
|
+
name: 'Jane Doe',
|
34
|
+
},
|
35
|
+
},
|
36
|
+
};
|
37
|
+
|
38
|
+
export const LoggedOut: Story = {
|
39
|
+
args: {
|
40
|
+
user: null,
|
41
|
+
},
|
42
|
+
};
|
@@ -21,21 +21,17 @@
|
|
21
21
|
</header>
|
22
22
|
</template>
|
23
23
|
|
24
|
-
<script>
|
24
|
+
<script lang="ts" setup>
|
25
25
|
import './header.css';
|
26
26
|
import MyButton from './Button.vue';
|
27
27
|
|
28
|
-
|
29
|
-
name: 'my-header',
|
28
|
+
defineProps<{ user: { name: string } | null }>();
|
30
29
|
|
31
|
-
|
30
|
+
defineEmits<{
|
31
|
+
(event: 'createAccount'): void;
|
32
|
+
(event: 'login'): void;
|
33
|
+
(event: 'logout'): void;
|
34
|
+
}>();
|
32
35
|
|
33
|
-
props: {
|
34
|
-
user: {
|
35
|
-
type: Object,
|
36
|
-
},
|
37
|
-
},
|
38
|
-
|
39
|
-
emits: ['login', 'logout', 'createAccount'],
|
40
|
-
};
|
41
36
|
</script>
|
37
|
+
|
@@ -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: Meta<typeof MyPage> = {
|
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
|
+
};
|
19
|
+
|
20
|
+
export default meta;
|
21
|
+
type Story = StoryObj<typeof MyPage>;
|
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>
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3';
|
2
|
+
|
3
|
+
import Button from './Button.vue';
|
4
|
+
|
5
|
+
// More on how to set up stories at: https://storybook.js.org/docs/7.0/vue/writing-stories/introduction
|
6
|
+
const meta = {
|
7
|
+
title: 'Example/Button',
|
8
|
+
component: Button,
|
9
|
+
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/7.0/vue/writing-docs/docs-page
|
10
|
+
tags: ['autodocs'],
|
11
|
+
argTypes: {
|
12
|
+
size: { control: 'select', options: ['small', 'medium', 'large'] },
|
13
|
+
backgroundColor: { control: 'color' },
|
14
|
+
onClick: { action: 'clicked' },
|
15
|
+
},
|
16
|
+
args: { primary: false }, // default value
|
17
|
+
} satisfies Meta<typeof Button>;
|
18
|
+
|
19
|
+
export default meta;
|
20
|
+
type Story = StoryObj<typeof meta>;
|
21
|
+
/*
|
22
|
+
*👇 Render functions are a framework specific feature to allow you control on how the component renders.
|
23
|
+
* See https://storybook.js.org/docs/7.0/vue/api/csf
|
24
|
+
* to learn how to use render functions.
|
25
|
+
*/
|
26
|
+
export const Primary: Story = {
|
27
|
+
args: {
|
28
|
+
primary: true,
|
29
|
+
label: 'Button',
|
30
|
+
},
|
31
|
+
};
|
32
|
+
|
33
|
+
export const Secondary: Story = {
|
34
|
+
args: {
|
35
|
+
primary: false,
|
36
|
+
label: 'Button',
|
37
|
+
},
|
38
|
+
};
|
39
|
+
|
40
|
+
export const Large: Story = {
|
41
|
+
args: {
|
42
|
+
label: 'Button',
|
43
|
+
size: 'large',
|
44
|
+
},
|
45
|
+
};
|
46
|
+
|
47
|
+
export const Small: Story = {
|
48
|
+
args: {
|
49
|
+
label: 'Button',
|
50
|
+
size: 'small',
|
51
|
+
},
|
52
|
+
};
|
@@ -0,0 +1,48 @@
|
|
1
|
+
<template>
|
2
|
+
<button type="button" :class="classes" @click="onClick" :style="style">{{ label }} </button>
|
3
|
+
</template>
|
4
|
+
|
5
|
+
<script lang="ts" setup>
|
6
|
+
import './button.css';
|
7
|
+
import { computed } from 'vue';
|
8
|
+
|
9
|
+
const props = withDefaults(defineProps<{
|
10
|
+
/**
|
11
|
+
* The label of the button
|
12
|
+
*/
|
13
|
+
label: string,
|
14
|
+
/**
|
15
|
+
* primary or secondary button
|
16
|
+
*/
|
17
|
+
primary?: boolean,
|
18
|
+
/**
|
19
|
+
* size of the button
|
20
|
+
*/
|
21
|
+
size?: 'small' | 'medium' | 'large',
|
22
|
+
/**
|
23
|
+
* background color of the button
|
24
|
+
*/
|
25
|
+
backgroundColor?: string,
|
26
|
+
|
27
|
+
}>(), { primary: false });
|
28
|
+
|
29
|
+
const emit = defineEmits<{
|
30
|
+
(e: 'click', id: number): void;
|
31
|
+
}>();
|
32
|
+
|
33
|
+
const classes = computed(() => ({
|
34
|
+
'storybook-button': true,
|
35
|
+
'storybook-button--primary': props.primary,
|
36
|
+
'storybook-button--secondary': !props.primary,
|
37
|
+
[`storybook-button--${props.size || 'medium'}`]: true,
|
38
|
+
}));
|
39
|
+
|
40
|
+
const style = computed(() => ({
|
41
|
+
backgroundColor: props.backgroundColor
|
42
|
+
}));
|
43
|
+
|
44
|
+
const onClick = () => {
|
45
|
+
emit("click", 1)
|
46
|
+
};
|
47
|
+
|
48
|
+
</script>
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3';
|
2
|
+
|
3
|
+
import MyHeader from './Header.vue';
|
4
|
+
|
5
|
+
const meta = {
|
6
|
+
/* 👇 The title prop is optional.
|
7
|
+
* See https://storybook.js.org/docs/7.0/vue/configure/overview#configure-story-loading
|
8
|
+
* to learn how to generate automatic titles
|
9
|
+
*/
|
10
|
+
title: 'Example/Header',
|
11
|
+
component: MyHeader,
|
12
|
+
render: (args: any) => ({
|
13
|
+
components: { MyHeader },
|
14
|
+
setup() {
|
15
|
+
return { args };
|
16
|
+
},
|
17
|
+
template: '<my-header :user="args.user" />',
|
18
|
+
}),
|
19
|
+
parameters: {
|
20
|
+
// More on how to position stories at: https://storybook.js.org/docs/7.0/react/configure/story-layout
|
21
|
+
layout: 'fullscreen',
|
22
|
+
},
|
23
|
+
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/7.0/vue/writing-docs/docs-page
|
24
|
+
tags: ['autodocs'],
|
25
|
+
} satisfies Meta<typeof MyHeader>;
|
26
|
+
|
27
|
+
export default meta;
|
28
|
+
type Story = StoryObj<typeof meta>;
|
29
|
+
|
30
|
+
export const LoggedIn: Story = {
|
31
|
+
args: {
|
32
|
+
user: {
|
33
|
+
name: 'Jane Doe',
|
34
|
+
},
|
35
|
+
},
|
36
|
+
};
|
37
|
+
|
38
|
+
export const LoggedOut: Story = {
|
39
|
+
args: {
|
40
|
+
user: null,
|
41
|
+
},
|
42
|
+
};
|
@@ -0,0 +1,37 @@
|
|
1
|
+
<template>
|
2
|
+
<header>
|
3
|
+
<div class="wrapper">
|
4
|
+
<div>
|
5
|
+
<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
|
6
|
+
<g fill="none" fill-rule="evenodd">
|
7
|
+
<path d="M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z" fill="#FFF" />
|
8
|
+
<path d="M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z" fill="#555AB9" />
|
9
|
+
<path d="M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z" fill="#91BAF8" />
|
10
|
+
</g>
|
11
|
+
</svg>
|
12
|
+
<h1>Acme</h1>
|
13
|
+
</div>
|
14
|
+
<div>
|
15
|
+
<span class="welcome" v-if="user">Welcome, <b>{{ user.name }}</b>!</span>
|
16
|
+
<my-button size="small" @click="$emit('logout')" label="Log out" v-if="user" />
|
17
|
+
<my-button size="small" @click="$emit('login')" label="Log in" v-if="!user" />
|
18
|
+
<my-button primary size="small" @click="$emit('createAccount')" label="Sign up" v-if="!user" />
|
19
|
+
</div>
|
20
|
+
</div>
|
21
|
+
</header>
|
22
|
+
</template>
|
23
|
+
|
24
|
+
<script lang="ts" setup>
|
25
|
+
import './header.css';
|
26
|
+
import MyButton from './Button.vue';
|
27
|
+
|
28
|
+
defineProps<{ user: { name: string } | null }>();
|
29
|
+
|
30
|
+
defineEmits<{
|
31
|
+
(event: 'createAccount'): void;
|
32
|
+
(event: 'login'): void;
|
33
|
+
(event: 'logout'): void;
|
34
|
+
}>();
|
35
|
+
|
36
|
+
</script>
|
37
|
+
|