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

setup storybook #122

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 8 additions & 12 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,22 @@ module.exports = {
browser: true,
es2021: true
},
extends: [
'plugin:vue/vue3-essential',
'standard-with-typescript'
],
overrides: [
],
extends: ['plugin:vue/vue3-essential', 'standard-with-typescript', 'plugin:storybook/recommended'],
overrides: [],
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: 'tsconfig.json'
},
plugins: [
'vue'
],
rules: {
},
plugins: ['vue'],
rules: {},
ignorePatterns: [
'dist/*',
'.output/*',
'.nuxt/*',
'node_modules/*'
'node_modules/*',
'stories/*',
'storybook-static/*',
'.storybook/*'
]
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ node_modules
.env
dist
.DS_Store

# Storybook
storybook-static
17 changes: 17 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { StorybookConfig } from "@storybook/vue3-vite";
const config: StorybookConfig = {
stories: ["../stories/**/*.mdx", "../stories/**/*.stories.@(js|jsx|ts|tsx)"],
addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-interactions",
],
framework: {
name: "@storybook/vue3-vite",
options: {},
},
docs: {
autodocs: "tag",
},
};
export default config;
15 changes: 15 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { Preview } from "@storybook/vue3";

const preview: Preview = {
parameters: {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
},
};

export default preview;
15 changes: 14 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"postinstall": "nuxt prepare",
"lint": "eslint --fix . --ext .js,.vue,.ts",
"test": "vitest",
"coverage": "vitest run --coverage"
"coverage": "vitest run --coverage",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
"dependencies": {
"@pinia-orm/nuxt": "^1.6.7",
Expand All @@ -25,6 +27,13 @@
"devDependencies": {
"@mdi/font": "^7.2.96",
"@nuxt/test-utils": "^3.4.2",
"@storybook/addon-essentials": "^7.0.7",
"@storybook/addon-interactions": "^7.0.7",
"@storybook/addon-links": "^7.0.7",
"@storybook/blocks": "^7.0.7",
"@storybook/testing-library": "^0.0.14-next.2",
"@storybook/vue3": "^7.0.7",
"@storybook/vue3-vite": "^7.0.7",
"@types/node": "^18.16.1",
"@types/webfontloader": "^1.6.35",
"@typescript-eslint/eslint-plugin": "^5.59.1",
Expand All @@ -33,8 +42,12 @@
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-n": "^15.0.0",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-storybook": "^0.6.11",
"eslint-plugin-vue": "^9.10.0",
"nuxt": "^3.4.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"storybook": "^7.0.7",
"typescript": "5.0.4",
"vitest": "^0.30.1",
"vue-tsc": "^1.6.0",
Expand Down
52 changes: 52 additions & 0 deletions stories/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/vue/writing-stories/introduction
const meta = {
title: 'Example/Button',
component: Button,
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/vue/writing-docs/autodocs
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/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',
},
};
48 changes: 48 additions & 0 deletions stories/Button.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<template>
<button type="button" :class="classes" @click="onClick" :style="style">{{ label }} </button>
</template>

<script lang="ts" setup>
import './button.css';
import { computed } from 'vue';

const props = withDefaults(defineProps<{
/**
* The label of the button
*/
label: string,
/**
* primary or secondary button
*/
primary?: boolean,
/**
* size of the button
*/
size?: 'small' | 'medium' | 'large',
/**
* background color of the button
*/
backgroundColor?: string,

}>(), { 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 stories/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 = {
/* 👇 The title prop is optional.
* See https://storybook.js.org/docs/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/react/configure/story-layout
layout: 'fullscreen',
},
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/vue/writing-docs/autodocs
tags: ['autodocs'],
} satisfies Meta<typeof MyHeader>;

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

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

export const LoggedOut: Story = {
args: {
user: null,
},
};
37 changes: 37 additions & 0 deletions stories/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>

Loading