Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue3: Add TS / legacy TS CLI templates #20434

Merged
merged 21 commits into from
Jan 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
87d7c13
add typescript templates for vue-vite default-ts
chakAs3 Dec 29, 2022
75aca80
clean up files cli/js cli/ts
chakAs3 Dec 29, 2022
2cbea68
revert changes on renderers/vue as it is not concerned by ts only for…
chakAs3 Dec 29, 2022
77d2b4a
Merge branch 'storybookjs:next' into vue-vite-default-ts
chakAs3 Dec 29, 2022
be9eca2
fix interactivity on Header Component
chakAs3 Dec 29, 2022
1fbe59d
Merge branch 'storybookjs:next' into vue-vite-default-ts
chakAs3 Dec 29, 2022
7b047c6
Merge branch 'vue-vite-default-ts' of github.com:chakAs3/storybook in…
chakAs3 Dec 29, 2022
c6e6fdb
fix template to pass the e2e-tests
chakAs3 Dec 29, 2022
2ffdb02
fix template header to pass the e2e-tests
chakAs3 Dec 29, 2022
cc1e972
fix template header to pass the e2e-tests
chakAs3 Dec 29, 2022
c272000
(vue-render) fix template Page to pass e2e-tests
chakAs3 Dec 29, 2022
e1dd6bd
(Vue Renderer) use setup script + remove any changes as baselines to …
chakAs3 Dec 30, 2022
a64942d
Merge branch 'storybookjs:next' into vue-vite-default-ts
chakAs3 Dec 30, 2022
f9d82f1
(Vue Renderer) use setup script + remove any changes as baselines to …
chakAs3 Dec 30, 2022
a8b8148
Merge branch 'vue-vite-default-ts' of github.com:chakAs3/storybook in…
chakAs3 Dec 30, 2022
0842d0f
Merge branch 'storybookjs:next' into vue-vite-default-ts
chakAs3 Dec 30, 2022
024e8cf
(vue renderer) add ts-legacy assets ..
chakAs3 Dec 30, 2022
837446b
Merge branch 'vue-vite-default-ts' of github.com:chakAs3/storybook in…
chakAs3 Dec 31, 2022
51cd7f9
Merge branch 'storybookjs:next' into vue-vite-default-ts
chakAs3 Dec 31, 2022
e69c7be
revert e2e tests chnage
chakAs3 Dec 31, 2022
a352856
Merge branch 'vue-vite-default-ts' of github.com:chakAs3/storybook in…
chakAs3 Dec 31, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion code/renderers/vue3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"@digitak/esrun": "^3.2.2",
"@vue/vue3-jest": "29",
"typescript": "~4.9.3",
"vue": "^3.2.41",
"vue": "^3.2.45",
"vue-tsc": "^1.0.8"
},
"peerDependencies": {
Expand Down
52 changes: 52 additions & 0 deletions code/renderers/vue3/template/cli/ts-legacy/Button.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type { Meta, StoryObj } from '@storybook/vue3';

import Button from './Button.vue';

// More on how to set up stories at: https://storybook.js.org/docs/7.0/vue/writing-stories/introduction
const meta: Meta<typeof Button> = {
title: 'Example/Button',
component: Button,
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/7.0/vue/writing-docs/docs-page
tags: ['autodocs'],
argTypes: {
size: { control: 'select', options: ['small', 'medium', 'large'] },
backgroundColor: { control: 'color' },
onClick: { action: 'clicked' },
},
args: { primary: false }, // default value
};

export default meta;
type Story = StoryObj<typeof Button>;
/*
*👇 Render functions are a framework specific feature to allow you control on how the component renders.
* See https://storybook.js.org/docs/7.0/vue/api/csf
* to learn how to use render functions.
*/
export const Primary: Story = {
args: {
primary: true,
label: 'Button',
},
};

export const Secondary: Story = {
args: {
primary: false,
label: 'Button',
},
};

export const Large: Story = {
args: {
label: 'Button',
size: 'large',
},
};

export const Small: Story = {
args: {
label: 'Button',
size: 'small',
},
};
35 changes: 35 additions & 0 deletions code/renderers/vue3/template/cli/ts-legacy/Button.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<template>
<button type="button" :class="classes" @click="onClick" :style="style">{{ label }} </button>
</template>

<script lang="ts" setup>
import { computed } from 'vue';
type Props = {
label: string,
primary?: boolean,
size?: 'small' | 'medium' | 'large',
backgroundColor?: string,
}

const props = withDefaults(defineProps<Props>(), { primary: false });

const emit = defineEmits<{
(e: 'click', id: number): void;
}>();

const classes = computed(() => ({
'storybook-button': true,
'storybook-button--primary': props.primary,
'storybook-button--secondary': !props.primary,
[`storybook-button--${props.size || 'medium'}`]: true,
}));

const style = computed(() => ({
backgroundColor: props.backgroundColor
}));

const onClick = () => {
emit("click", 1)
};

</script>
42 changes: 42 additions & 0 deletions code/renderers/vue3/template/cli/ts-legacy/Header.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type { Meta, StoryObj } from '@storybook/vue3';

import MyHeader from './Header.vue';

const meta: Meta<typeof MyHeader> = {
/* 👇 The title prop is optional.
* See https://storybook.js.org/docs/7.0/vue/configure/overview#configure-story-loading
* to learn how to generate automatic titles
*/
title: 'Example/Header',
component: MyHeader,
render: (args: any) => ({
components: { MyHeader },
setup() {
return { args };
},
template: '<my-header :user="args.user" />',
}),
parameters: {
// More on how to position stories at: https://storybook.js.org/docs/7.0/react/configure/story-layout
layout: 'fullscreen',
},
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/7.0/vue/writing-docs/docs-page
tags: ['autodocs'],
};

export default meta;
type Story = StoryObj<typeof MyHeader>;

export const LoggedIn: Story = {
args: {
user: {
name: 'Jane Doe',
},
},
};

export const LoggedOut: Story = {
args: {
user: null,
},
};
37 changes: 37 additions & 0 deletions code/renderers/vue3/template/cli/ts-legacy/Header.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<template>
<header>
<div class="wrapper">
<div>
<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
<g fill="none" fill-rule="evenodd">
<path d="M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z" fill="#FFF" />
<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" />
<path d="M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z" fill="#91BAF8" />
</g>
</svg>
<h1>Acme</h1>
</div>
<div>
<span class="welcome" v-if="user">Welcome, <b>{{ user.name }}</b>!</span>
<my-button size="small" @click="$emit('logout')" label="Log out" v-if="user" />
<my-button size="small" @click="$emit('login')" label="Log in" v-if="!user" />
<my-button primary size="small" @click="$emit('createAccount')" label="Sign up" v-if="!user" />
</div>
</div>
</header>
</template>

<script lang="ts" setup>
import './header.css';
import MyButton from './Button.vue';

defineProps<{ user: { name: string } | null }>();

defineEmits<{
(event: 'createAccount'): void;
(event: 'login'): void;
(event: 'logout'): void;
}>();

</script>

34 changes: 34 additions & 0 deletions code/renderers/vue3/template/cli/ts-legacy/Page.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { Meta, StoryObj } from '@storybook/vue3';
import { within, userEvent } from '@storybook/testing-library';
import MyPage from './Page.vue';

const meta: Meta<typeof MyPage> = {
title: 'Example/Page',
component: MyPage,
render: () => ({
components: { MyPage },
template: '<my-page />',
}),
parameters: {
// More on how to position stories at: https://storybook.js.org/docs/7.0/vue/configure/story-layout
layout: 'fullscreen',
},
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/7.0/vue/writing-docs/docs-page
tags: ['autodocs'],
};

export default meta;
type Story = StoryObj<typeof MyPage>;

// More on interaction testing: https://storybook.js.org/docs/7.0/vue/writing-tests/interaction-testing
export const LoggedIn: Story = {
play: async ({ canvasElement }: any) => {
const canvas = within(canvasElement);
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
await userEvent.click(loginButton);
},
};

export const LoggedOut: Story = {};
70 changes: 70 additions & 0 deletions code/renderers/vue3/template/cli/ts-legacy/Page.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<template>
<article>
<my-header :user="user" @login="onLogin" @logout="onLogout" @create-account="onCreateAccount" />

<section>
<h2>Pages in Storybook</h2>
<p>
We recommend building UIs with a
<a href="https://componentdriven.org" target="_blank" rel="noopener noreferrer">
<strong>component-driven</strong>
</a>
process starting with atomic components and ending with pages.
</p>
<p>
Render pages with mock data. This makes it easy to build and review page states without
needing to navigate to them in your app. Here are some handy patterns for managing page data
in Storybook:
</p>
<ul>
<li>
Use a higher-level connected component. Storybook helps you compose such data from the
"args" of child component stories
</li>
<li>
Assemble data in the page component from your services. You can mock these services out
using Storybook.
</li>
</ul>
<p>
Get a guided tutorial on component-driven development at
<a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer">Storybook tutorials</a>
. Read more in the
<a href="https://storybook.js.org/docs" target="_blank" rel="noopener noreferrer">docs</a>
.
</p>
<div class="tip-wrapper">
<span class="tip">Tip</span>
Adjust the width of the canvas with the
<svg width="10" height="10" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg">
<g fill="none" fill-rule="evenodd">
<path
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"
id="a" fill="#999" />
</g>
</svg>
Viewports addon in the toolbar
</div>
</section>
</article>
</template>

<script lang="ts" setup>
import './page.css';
import MyHeader from './Header.vue';

import { ref } from 'vue';

const user = ref<{ name: string } | null>(null)

const onLogin = () => {
user.value = { name: 'Jane Doe' };
};
const onLogout = () => {
user.value = null;
};
const onCreateAccount = () => {
user.value = { name: 'Jane Doe' };
};

</script>
52 changes: 52 additions & 0 deletions code/renderers/vue3/template/cli/ts/Button.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type { Meta, StoryObj } from '@storybook/vue3';

import Button from './Button.vue';

// More on how to set up stories at: https://storybook.js.org/docs/7.0/vue/writing-stories/introduction
chakAs3 marked this conversation as resolved.
Show resolved Hide resolved
const meta = {
title: 'Example/Button',
component: Button,
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/7.0/vue/writing-docs/docs-page
tags: ['autodocs'],
argTypes: {
size: { control: 'select', options: ['small', 'medium', 'large'] },
backgroundColor: { control: 'color' },
onClick: { action: 'clicked' },
},
args: { primary: false }, // default value
} satisfies Meta<typeof Button>;

export default meta;
type Story = StoryObj<typeof meta>;
/*
*👇 Render functions are a framework specific feature to allow you control on how the component renders.
* See https://storybook.js.org/docs/7.0/vue/api/csf
* to learn how to use render functions.
*/
export const Primary: Story = {
args: {
primary: true,
label: 'Button',
},
};

export const Secondary: Story = {
args: {
primary: false,
label: 'Button',
},
};

export const Large: Story = {
args: {
label: 'Button',
size: 'large',
},
};

export const Small: Story = {
args: {
label: 'Button',
size: 'small',
},
};
35 changes: 35 additions & 0 deletions code/renderers/vue3/template/cli/ts/Button.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<template>
<button type="button" :class="classes" @click="onClick" :style="style">{{ label }} </button>
</template>

<script lang="ts" setup>
import { computed } from 'vue';
type Props = {
label: string,
primary?: boolean,
size?: 'small' | 'medium' | 'large',
backgroundColor?: string,
}

const props = withDefaults(defineProps<Props>(), { primary: false });

const emit = defineEmits<{
(e: 'click', id: number): void;
}>();

const classes = computed(() => ({
'storybook-button': true,
'storybook-button--primary': props.primary,
'storybook-button--secondary': !props.primary,
[`storybook-button--${props.size || 'medium'}`]: true,
}));

const style = computed(() => ({
backgroundColor: props.backgroundColor
}));

const onClick = () => {
emit("click", 1)
};

</script>
Loading