Skip to content

Commit a3579d8

Browse files
mauryapariParitosh Maurya
and
Paritosh Maurya
authored
Added example for storybook with vue3 and vite using vue-i18n (#2173)
Co-authored-by: Paritosh Maurya <[email protected]>
1 parent 07143af commit a3579d8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3747
-123
lines changed

examples/storybook/.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[*.{js,jsx,mjs,cjs,ts,tsx,mts,cts,vue,css,scss,sass,less,styl}]
2+
charset = utf-8
3+
indent_size = 2
4+
indent_style = space
5+
insert_final_newline = true
6+
trim_trailing_whitespace = true
7+
8+
end_of_line = lf
9+
max_line_length = 100

examples/storybook/.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

examples/storybook/.gitignore

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
.DS_Store
12+
dist
13+
dist-ssr
14+
coverage
15+
*.local
16+
17+
/cypress/videos/
18+
/cypress/screenshots/
19+
20+
# Editor directories and files
21+
.vscode/*
22+
!.vscode/extensions.json
23+
.idea
24+
*.suo
25+
*.ntvs*
26+
*.njsproj
27+
*.sln
28+
*.sw?
29+
30+
*.tsbuildinfo
31+
32+
*storybook.log

examples/storybook/.prettierrc.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"$schema": "https://json.schemastore.org/prettierrc",
3+
"semi": false,
4+
"singleQuote": true,
5+
"printWidth": 100
6+
}

examples/storybook/.storybook/main.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { StorybookConfig } from '@storybook/vue3-vite'
2+
3+
const config: StorybookConfig = {
4+
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
5+
addons: ['@storybook/addon-essentials', '@storybook/addon-interactions'],
6+
framework: {
7+
name: '@storybook/vue3-vite',
8+
options: {},
9+
},
10+
}
11+
export default config
+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import type { Preview } from '@storybook/vue3'
2+
import { setup } from '@storybook/vue3'
3+
import { createI18n } from 'vue-i18n'
4+
import en from '../src/locales/en.json'
5+
import fr from '../src/locales/fr.json'
6+
import type { I18n } from 'vue-i18n'
7+
8+
const i18n: I18n = createI18n({
9+
locale: 'en',
10+
fallbackLocale: 'en',
11+
messages: {
12+
en,
13+
fr,
14+
},
15+
})
16+
17+
setup((app) => {
18+
app.use(i18n)
19+
})
20+
21+
export const globalTypes = {
22+
locale: {
23+
name: 'Locale',
24+
description: 'Internationalization locale',
25+
defaultValue: 'en',
26+
toolbar: {
27+
icon: 'globe',
28+
items: [
29+
{ value: 'en', title: 'English' },
30+
{ value: 'fr', title: 'French' },
31+
],
32+
showName: true,
33+
},
34+
},
35+
}
36+
37+
// Decorator for updating locale
38+
export const decorators = [
39+
(story, { globals }) => {
40+
const currentLocale = globals.locale
41+
42+
if (i18n.global.locale.value !== currentLocale) {
43+
i18n.global.locale.value = currentLocale
44+
}
45+
46+
return {
47+
components: { story },
48+
template: '<story />',
49+
}
50+
},
51+
]
52+
53+
const preview: Preview = {
54+
parameters: {
55+
controls: {
56+
matchers: {
57+
color: /(background|color)$/i,
58+
date: /Date$/i,
59+
},
60+
},
61+
},
62+
}
63+
64+
export default preview

examples/storybook/README.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# storybook
2+
3+
This template should help get you started developing with Vue 3 in Vite.
4+
5+
## Recommended IDE Setup
6+
7+
[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
8+
9+
## Type Support for `.vue` Imports in TS
10+
11+
TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) to make the TypeScript language service aware of `.vue` types.
12+
13+
## Customize configuration
14+
15+
See [Vite Configuration Reference](https://vite.dev/config/).
16+
17+
## Project Setup
18+
19+
```sh
20+
pnpm install
21+
```
22+
23+
### Compile and Hot-Reload for Development
24+
25+
```sh
26+
pnpm dev
27+
```
28+
29+
### Type-Check, Compile and Minify for Production
30+
31+
```sh
32+
pnpm build
33+
```
34+
35+
### Lint with [ESLint](https://eslint.org/)
36+
37+
```sh
38+
pnpm lint
39+
```

examples/storybook/env.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="vite/client" />

examples/storybook/eslint.config.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { globalIgnores } from 'eslint/config'
2+
import { defineConfigWithVueTs, vueTsConfigs } from '@vue/eslint-config-typescript'
3+
import pluginVue from 'eslint-plugin-vue'
4+
import skipFormatting from '@vue/eslint-config-prettier/skip-formatting'
5+
6+
// To allow more languages other than `ts` in `.vue` files, uncomment the following lines:
7+
// import { configureVueProject } from '@vue/eslint-config-typescript'
8+
// configureVueProject({ scriptLangs: ['ts', 'tsx'] })
9+
// More info at https://github.com/vuejs/eslint-config-typescript/#advanced-setup
10+
11+
export default defineConfigWithVueTs(
12+
{
13+
name: 'app/files-to-lint',
14+
files: ['**/*.{ts,mts,tsx,vue}'],
15+
},
16+
17+
globalIgnores(['**/dist/**', '**/dist-ssr/**', '**/coverage/**']),
18+
19+
pluginVue.configs['flat/essential'],
20+
vueTsConfigs.recommended,
21+
skipFormatting,
22+
)

examples/storybook/index.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="">
3+
<head>
4+
<meta charset="UTF-8">
5+
<link rel="icon" href="/favicon.ico">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Vite App</title>
8+
</head>
9+
<body>
10+
<div id="app"></div>
11+
<script type="module" src="/src/main.ts"></script>
12+
</body>
13+
</html>

examples/storybook/package.json

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "storybook",
3+
"version": "0.0.0",
4+
"private": true,
5+
"type": "module",
6+
"scripts": {
7+
"dev": "vite",
8+
"build": "run-p type-check \"build-only {@}\" --",
9+
"preview": "vite preview",
10+
"build-only": "vite build",
11+
"type-check": "vue-tsc --build",
12+
"lint": "eslint . --fix",
13+
"format": "prettier --write src/",
14+
"storybook": "storybook dev -p 6006",
15+
"build-storybook": "storybook build"
16+
},
17+
"dependencies": {
18+
"vue": "^3.5.13",
19+
"vue-i18n": "workspace:*"
20+
},
21+
"devDependencies": {
22+
"@storybook/addon-essentials": "^8.6.12",
23+
"@storybook/addon-interactions": "^8.6.12",
24+
"@storybook/addon-onboarding": "^8.6.12",
25+
"@storybook/blocks": "^8.6.12",
26+
"@storybook/test": "^8.6.12",
27+
"@storybook/vue3": "^8.6.12",
28+
"@storybook/vue3-vite": "^8.6.12",
29+
"@tsconfig/node22": "^22.0.1",
30+
"@types/node": "^22.14.0",
31+
"@vitejs/plugin-vue": "^5.2.3",
32+
"@vue/eslint-config-prettier": "^10.2.0",
33+
"@vue/eslint-config-typescript": "^14.5.0",
34+
"@vue/tsconfig": "^0.7.0",
35+
"eslint": "^9.22.0",
36+
"eslint-plugin-storybook": "^0.12.0",
37+
"eslint-plugin-vue": "~10.0.0",
38+
"jiti": "^2.4.2",
39+
"npm-run-all2": "^7.0.2",
40+
"prettier": "3.5.3",
41+
"storybook": "^8.6.12",
42+
"typescript": "~5.8.0",
43+
"vite": "^6.2.4",
44+
"vite-plugin-vue-devtools": "^7.7.2",
45+
"vue-tsc": "^2.2.8"
46+
},
47+
"eslintConfig": {
48+
"extends": [
49+
"plugin:storybook/recommended"
50+
]
51+
}
52+
}

examples/storybook/public/favicon.ico

4.19 KB
Binary file not shown.

examples/storybook/src/App.vue

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<script setup lang="ts">
2+
import HelloWorld from './components/HelloWorld.vue'
3+
import TheWelcome from './components/TheWelcome.vue'
4+
</script>
5+
6+
<template>
7+
<header>
8+
<img alt="Vue logo" class="logo" src="./assets/logo.svg" width="125" height="125" />
9+
10+
<div class="wrapper">
11+
<HelloWorld msg="You did it!" />
12+
</div>
13+
</header>
14+
15+
<main>
16+
<TheWelcome />
17+
</main>
18+
</template>
19+
20+
<style scoped>
21+
header {
22+
line-height: 1.5;
23+
}
24+
25+
.logo {
26+
display: block;
27+
margin: 0 auto 2rem;
28+
}
29+
30+
@media (min-width: 1024px) {
31+
header {
32+
display: flex;
33+
place-items: center;
34+
padding-right: calc(var(--section-gap) / 2);
35+
}
36+
37+
.logo {
38+
margin: 0 2rem 0 0;
39+
}
40+
41+
header .wrapper {
42+
display: flex;
43+
place-items: flex-start;
44+
flex-wrap: wrap;
45+
}
46+
}
47+
</style>
+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/* color palette from <https://github.com/vuejs/theme> */
2+
:root {
3+
--vt-c-white: #ffffff;
4+
--vt-c-white-soft: #f8f8f8;
5+
--vt-c-white-mute: #f2f2f2;
6+
7+
--vt-c-black: #181818;
8+
--vt-c-black-soft: #222222;
9+
--vt-c-black-mute: #282828;
10+
11+
--vt-c-indigo: #2c3e50;
12+
13+
--vt-c-divider-light-1: rgba(60, 60, 60, 0.29);
14+
--vt-c-divider-light-2: rgba(60, 60, 60, 0.12);
15+
--vt-c-divider-dark-1: rgba(84, 84, 84, 0.65);
16+
--vt-c-divider-dark-2: rgba(84, 84, 84, 0.48);
17+
18+
--vt-c-text-light-1: var(--vt-c-indigo);
19+
--vt-c-text-light-2: rgba(60, 60, 60, 0.66);
20+
--vt-c-text-dark-1: var(--vt-c-white);
21+
--vt-c-text-dark-2: rgba(235, 235, 235, 0.64);
22+
}
23+
24+
/* semantic color variables for this project */
25+
:root {
26+
--color-background: var(--vt-c-white);
27+
--color-background-soft: var(--vt-c-white-soft);
28+
--color-background-mute: var(--vt-c-white-mute);
29+
30+
--color-border: var(--vt-c-divider-light-2);
31+
--color-border-hover: var(--vt-c-divider-light-1);
32+
33+
--color-heading: var(--vt-c-text-light-1);
34+
--color-text: var(--vt-c-text-light-1);
35+
36+
--section-gap: 160px;
37+
}
38+
39+
@media (prefers-color-scheme: dark) {
40+
:root {
41+
--color-background: var(--vt-c-black);
42+
--color-background-soft: var(--vt-c-black-soft);
43+
--color-background-mute: var(--vt-c-black-mute);
44+
45+
--color-border: var(--vt-c-divider-dark-2);
46+
--color-border-hover: var(--vt-c-divider-dark-1);
47+
48+
--color-heading: var(--vt-c-text-dark-1);
49+
--color-text: var(--vt-c-text-dark-2);
50+
}
51+
}
52+
53+
*,
54+
*::before,
55+
*::after {
56+
box-sizing: border-box;
57+
margin: 0;
58+
font-weight: normal;
59+
}
60+
61+
body {
62+
min-height: 100vh;
63+
color: var(--color-text);
64+
background: var(--color-background);
65+
transition:
66+
color 0.5s,
67+
background-color 0.5s;
68+
line-height: 1.6;
69+
font-family:
70+
Inter,
71+
-apple-system,
72+
BlinkMacSystemFont,
73+
'Segoe UI',
74+
Roboto,
75+
Oxygen,
76+
Ubuntu,
77+
Cantarell,
78+
'Fira Sans',
79+
'Droid Sans',
80+
'Helvetica Neue',
81+
sans-serif;
82+
font-size: 15px;
83+
text-rendering: optimizeLegibility;
84+
-webkit-font-smoothing: antialiased;
85+
-moz-osx-font-smoothing: grayscale;
86+
}
+1
Loading

0 commit comments

Comments
 (0)