Skip to content

Commit c1259da

Browse files
committed
feat: install storybook
1 parent 4da3ed9 commit c1259da

13 files changed

+2930
-108
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ node_modules
88
dist
99
coverage
1010
# sonarqube
11-
.scannerwork
11+
.scannerwork
12+
*storybook.log

.storybook/auto-imports.d.ts

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/* eslint-disable */
2+
/* prettier-ignore */
3+
// @ts-nocheck
4+
// noinspection JSUnusedGlobalSymbols
5+
// Generated by unplugin-auto-import
6+
// biome-ignore lint: disable
7+
export {}
8+
declare global {
9+
const EffectScope: typeof import('vue')['EffectScope']
10+
const FieldContextKey: typeof import('vee-validate')['FieldContextKey']
11+
const FormContextKey: typeof import('vee-validate')['FormContextKey']
12+
const acceptHMRUpdate: typeof import('pinia')['acceptHMRUpdate']
13+
const computed: typeof import('vue')['computed']
14+
const configure: typeof import('vee-validate')['configure']
15+
const createApp: typeof import('vue')['createApp']
16+
const createPinia: typeof import('pinia')['createPinia']
17+
const customRef: typeof import('vue')['customRef']
18+
const defineAsyncComponent: typeof import('vue')['defineAsyncComponent']
19+
const defineComponent: typeof import('vue')['defineComponent']
20+
const defineRule: typeof import('vee-validate')['defineRule']
21+
const defineStore: typeof import('pinia')['defineStore']
22+
const effectScope: typeof import('vue')['effectScope']
23+
const getActivePinia: typeof import('pinia')['getActivePinia']
24+
const getCurrentInstance: typeof import('vue')['getCurrentInstance']
25+
const getCurrentScope: typeof import('vue')['getCurrentScope']
26+
const h: typeof import('vue')['h']
27+
const inject: typeof import('vue')['inject']
28+
const isProxy: typeof import('vue')['isProxy']
29+
const isReactive: typeof import('vue')['isReactive']
30+
const isReadonly: typeof import('vue')['isReadonly']
31+
const isRef: typeof import('vue')['isRef']
32+
const mapActions: typeof import('pinia')['mapActions']
33+
const mapGetters: typeof import('pinia')['mapGetters']
34+
const mapState: typeof import('pinia')['mapState']
35+
const mapStores: typeof import('pinia')['mapStores']
36+
const mapWritableState: typeof import('pinia')['mapWritableState']
37+
const markRaw: typeof import('vue')['markRaw']
38+
const nextTick: typeof import('vue')['nextTick']
39+
const onActivated: typeof import('vue')['onActivated']
40+
const onBeforeMount: typeof import('vue')['onBeforeMount']
41+
const onBeforeRouteLeave: typeof import('vue-router')['onBeforeRouteLeave']
42+
const onBeforeRouteUpdate: typeof import('vue-router')['onBeforeRouteUpdate']
43+
const onBeforeUnmount: typeof import('vue')['onBeforeUnmount']
44+
const onBeforeUpdate: typeof import('vue')['onBeforeUpdate']
45+
const onDeactivated: typeof import('vue')['onDeactivated']
46+
const onErrorCaptured: typeof import('vue')['onErrorCaptured']
47+
const onMounted: typeof import('vue')['onMounted']
48+
const onRenderTracked: typeof import('vue')['onRenderTracked']
49+
const onRenderTriggered: typeof import('vue')['onRenderTriggered']
50+
const onScopeDispose: typeof import('vue')['onScopeDispose']
51+
const onServerPrefetch: typeof import('vue')['onServerPrefetch']
52+
const onUnmounted: typeof import('vue')['onUnmounted']
53+
const onUpdated: typeof import('vue')['onUpdated']
54+
const onWatcherCleanup: typeof import('vue')['onWatcherCleanup']
55+
const provide: typeof import('vue')['provide']
56+
const reactive: typeof import('vue')['reactive']
57+
const readonly: typeof import('vue')['readonly']
58+
const ref: typeof import('vue')['ref']
59+
const resolveComponent: typeof import('vue')['resolveComponent']
60+
const setActivePinia: typeof import('pinia')['setActivePinia']
61+
const setMapStoreSuffix: typeof import('pinia')['setMapStoreSuffix']
62+
const shallowReactive: typeof import('vue')['shallowReactive']
63+
const shallowReadonly: typeof import('vue')['shallowReadonly']
64+
const shallowRef: typeof import('vue')['shallowRef']
65+
const storeToRefs: typeof import('pinia')['storeToRefs']
66+
const toRaw: typeof import('vue')['toRaw']
67+
const toRef: typeof import('vue')['toRef']
68+
const toRefs: typeof import('vue')['toRefs']
69+
const toValue: typeof import('vue')['toValue']
70+
const triggerRef: typeof import('vue')['triggerRef']
71+
const unref: typeof import('vue')['unref']
72+
const useAttrs: typeof import('vue')['useAttrs']
73+
const useCssModule: typeof import('vue')['useCssModule']
74+
const useCssVars: typeof import('vue')['useCssVars']
75+
const useField: typeof import('vee-validate')['useField']
76+
const useFieldArray: typeof import('vee-validate')['useFieldArray']
77+
const useFieldError: typeof import('vee-validate')['useFieldError']
78+
const useFieldValue: typeof import('vee-validate')['useFieldValue']
79+
const useForm: typeof import('vee-validate')['useForm']
80+
const useFormErrors: typeof import('vee-validate')['useFormErrors']
81+
const useFormValues: typeof import('vee-validate')['useFormValues']
82+
const useId: typeof import('vue')['useId']
83+
const useIsFieldDirty: typeof import('vee-validate')['useIsFieldDirty']
84+
const useIsFieldTouched: typeof import('vee-validate')['useIsFieldTouched']
85+
const useIsFieldValid: typeof import('vee-validate')['useIsFieldValid']
86+
const useIsFormDirty: typeof import('vee-validate')['useIsFormDirty']
87+
const useIsFormTouched: typeof import('vee-validate')['useIsFormTouched']
88+
const useIsFormValid: typeof import('vee-validate')['useIsFormValid']
89+
const useIsSubmitting: typeof import('vee-validate')['useIsSubmitting']
90+
const useLink: typeof import('vue-router')['useLink']
91+
const useModel: typeof import('vue')['useModel']
92+
const useResetForm: typeof import('vee-validate')['useResetForm']
93+
const useRoute: typeof import('vue-router')['useRoute']
94+
const useRouter: typeof import('vue-router')['useRouter']
95+
const useSlots: typeof import('vue')['useSlots']
96+
const useSubmitCount: typeof import('vee-validate')['useSubmitCount']
97+
const useSubmitForm: typeof import('vee-validate')['useSubmitForm']
98+
const useTemplateRef: typeof import('vue')['useTemplateRef']
99+
const useValidateField: typeof import('vee-validate')['useValidateField']
100+
const useValidateForm: typeof import('vee-validate')['useValidateForm']
101+
const validate: typeof import('vee-validate')['validate']
102+
const watch: typeof import('vue')['watch']
103+
const watchEffect: typeof import('vue')['watchEffect']
104+
const watchPostEffect: typeof import('vue')['watchPostEffect']
105+
const watchSyncEffect: typeof import('vue')['watchSyncEffect']
106+
}
107+
// for type re-export
108+
declare global {
109+
// @ts-ignore
110+
export type { Component, ComponentPublicInstance, ComputedRef, DirectiveBinding, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, MaybeRef, MaybeRefOrGetter, VNode, WritableComputedRef } from 'vue'
111+
import('vue')
112+
}

.storybook/components.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* eslint-disable */
2+
// @ts-nocheck
3+
// Generated by unplugin-vue-components
4+
// Read more: https://github.com/vuejs/core/pull/3399
5+
export {}
6+
7+
/* prettier-ignore */
8+
declare module 'vue' {
9+
export interface GlobalComponents {
10+
BaseTextInput: typeof import('./../src/components/atoms/BaseTextInput.vue')['default']
11+
RouterLink: typeof import('vue-router')['RouterLink']
12+
RouterView: typeof import('vue-router')['RouterView']
13+
}
14+
}

.storybook/main.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import path from 'path'
2+
import type { StorybookConfig } from '@storybook/vue3-vite'
3+
import AutoImportFunctions from 'unplugin-auto-import/vite'
4+
import AutoImportComponents from 'unplugin-vue-components/vite'
5+
6+
const config: StorybookConfig = {
7+
viteFinal: async (config) => {
8+
if (config?.plugins) {
9+
// 以下を追加
10+
config.plugins.push(
11+
AutoImportFunctions ({ imports: [
12+
'vue',
13+
'vee-validate',
14+
'vue-router',
15+
'pinia',
16+
], dts: '.storybook/auto-imports.d.ts' }),
17+
)
18+
// 以下を追加
19+
config.plugins.push(
20+
AutoImportComponents({
21+
// 自動インポートするコンポーネントが存在するディレクトリを指定
22+
dirs: ['src/components'],
23+
dts: '.storybook/components.d.ts',
24+
}),
25+
)
26+
}
27+
if (config?.resolve?.alias) {
28+
config.resolve.alias = {
29+
...config.resolve.alias,
30+
'@': path.resolve(__dirname, '../src'),
31+
'~': path.resolve(__dirname, '../src'),
32+
}
33+
}
34+
return config
35+
},
36+
staticDirs: ['../public'],
37+
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
38+
addons: [
39+
'@storybook/addon-onboarding',
40+
'@storybook/addon-essentials',
41+
'@chromatic-com/storybook',
42+
'@storybook/experimental-addon-test'
43+
],
44+
framework: {
45+
name: '@storybook/vue3-vite',
46+
options: {},
47+
},
48+
}
49+
export default config

.storybook/preview.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { type Preview, setup } from '@storybook/vue3'
2+
import type { App } from 'vue'
3+
import { createPinia } from 'pinia'
4+
import { localize, setLocale } from '@vee-validate/i18n'
5+
import ja from '@vee-validate/i18n/dist/locale/ja.json'
6+
import { all } from '@vee-validate/rules'
7+
import { defineRule, configure } from 'vee-validate'
8+
import { initialize, mswLoader } from 'msw-storybook-addon'
9+
import { createMemoryHistory, createRouter } from 'vue-router'
10+
import Form from '../src/pages/formScript.vue'
11+
import MyPage from '../src/pages/myPage.vue'
12+
13+
// MSWの有効化
14+
initialize({
15+
onUnhandledRequest: 'bypass',
16+
})
17+
18+
configure({
19+
generateMessage: localize({
20+
// エラーメッセージの日本語化
21+
ja,
22+
}),
23+
})
24+
25+
// すべてのルールをインポート
26+
Object.entries(all).forEach(([name, rule]) => {
27+
defineRule(name, rule)
28+
})
29+
30+
// エラーメッセージの日本語化
31+
setLocale('ja')
32+
33+
const routes = [
34+
{
35+
path: '/',
36+
name: 'Form',
37+
component: Form,
38+
},
39+
{
40+
path: '/myPage',
41+
name: 'MyPage',
42+
component: MyPage,
43+
},
44+
]
45+
const router = createRouter({
46+
history: createMemoryHistory(),
47+
routes,
48+
})
49+
const pinia = createPinia()
50+
51+
setup((app: App) => {
52+
app.use(pinia)
53+
app.use(router)
54+
})
55+
56+
const preview: Preview = {
57+
// MSWローダーの設定
58+
loaders: [mswLoader],
59+
parameters: {
60+
controls: {
61+
matchers: {
62+
color: /(background|color)$/i,
63+
date: /Date$/i,
64+
},
65+
},
66+
},
67+
}
68+
69+
export default preview

.storybook/vitest.setup.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { beforeAll } from 'vitest';
2+
import { setProjectAnnotations } from '@storybook/vue3';
3+
import * as projectAnnotations from './preview';
4+
5+
// This is an important step to apply the right configuration when testing your stories.
6+
// More info at: https://storybook.js.org/docs/api/portable-stories/portable-stories-vitest#setprojectannotations
7+
const project = setProjectAnnotations([projectAnnotations]);
8+
9+
beforeAll(project.beforeAll);

nuxt.config.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
// https://nuxt.com/docs/api/configuration/nuxt-config
22
export default defineNuxtConfig({
3-
modules: [
4-
'@nuxt/eslint',
5-
['@pinia/nuxt',
6-
{
7-
autoImports: [
8-
// defineStoreの自動インポート
9-
'defineStore',
10-
],
11-
// vuexも併用する場合は以下を追加
12-
// disableVuex: false ,
13-
},
14-
],
15-
],
3+
modules: ['@nuxtjs/storybook', '@nuxt/eslint', ['@pinia/nuxt',
4+
{
5+
autoImports: [
6+
// defineStoreの自動インポート
7+
'defineStore',
8+
],
9+
// vuexも併用する場合は以下を追加
10+
// disableVuex: false ,
11+
},
12+
], '@nuxtjs/storybook'],
1613
components: [
1714
{ path: '~/components/', pathPrefix: false },
1815
],
@@ -31,4 +28,8 @@ export default defineNuxtConfig({
3128
},
3229
},
3330
},
31+
storybook: {
32+
host: 'http://localhost',
33+
port: 6006,
34+
},
3435
})

0 commit comments

Comments
 (0)