Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
2d12889
add i18n module example to the showcase example
chakAs3 Dec 22, 2024
2c2bf78
create nuxtApp each time story vueApp is created, remove the check if…
chakAs3 Dec 22, 2024
295adc4
fix: add alias for Vue in Vite config to resolve bundler issues
chakAs3 Dec 22, 2024
fd23f72
fix start dev script
chakAs3 Dec 22, 2024
660d524
feat: add i18n support with multiple languages and example stories to…
chakAs3 Dec 22, 2024
2499c94
feat: add MyWelcome component and stories to showcase exmaples
chakAs3 Dec 22, 2024
8c38ac3
fix: update package name for nuxtjs/i18n to @nuxtjs/i18n in package.j…
chakAs3 Dec 22, 2024
0983fbe
refactor: rename I18n component to MyI18n and update references in st…
chakAs3 Dec 22, 2024
5a00ad2
style: clean up formatting and remove unnecessary whitespace in vario…
chakAs3 Dec 22, 2024
5b35771
fix: add vue as external dependencies in rollupOptions to avoid memo…
chakAs3 Dec 24, 2024
947658a
revert fix: add vue as external dependencies in rollupOptions to avo…
chakAs3 Dec 24, 2024
c739501
fix: add vue as a dependency in package.json and create a build task …
chakAs3 Dec 26, 2024
ab216db
fix: remove tasks.json
chakAs3 Dec 26, 2024
976b204
Merge branch 'chaks/fix-nuxtapp-for-rerendered-story' of https://gith…
chakAs3 Dec 26, 2024
d9c8a7c
fix: remove tasks.json as it is no longer needed
chakAs3 Dec 26, 2024
b58c7d8
Merge branch 'main' of https://github.com/nuxt-modules/storybook into…
chakAs3 Dec 27, 2024
11908e4
update lockfile
chakAs3 Dec 27, 2024
bc665ef
refactor: remove unused Vue alias and cleanup Nuxt app creation logic
chakAs3 Dec 27, 2024
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
36 changes: 36 additions & 0 deletions examples/showcase/components/MyI18n.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { Meta, StoryObj } from '@storybook/vue3'

import MyComponent from './MyI18n.vue'

// More on how to set up stories at: https://storybook.js.org/docs/vue/writing-stories/introduction

const meta = {
title: 'Modules/I18n',
component: MyComponent,
argTypes: {
lang: { control: 'select', options: ['en', 'fr', 'ar'] },
},

// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/vue/writing-docs/autodocs
tags: ['autodocs'],
} satisfies Meta<typeof MyComponent>

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 FrenchStory: Story = {
args: { lang: 'fr' },
}

export const EnglishStory: Story = {
args: { lang: 'en' },
}

export const ArabicStory: Story = {
args: { lang: 'ar' },
}
47 changes: 47 additions & 0 deletions examples/showcase/components/MyI18n.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<script lang="ts" setup>
import '../assets/button.css'

const props = defineProps<{
lang: string
message?: string
}>()
const { t, locale } = useI18n()
const rtl = computed(() => props.lang === 'ar')
locale.value = props.lang
watch(
() => props.lang,
(lang: unknown) => {
locale.value = lang
},
)
</script>

<template>
<div class="storybook lang-selector">
<button
class="storybook-button storybook-button--small"
@click="locale = 'en'"
>
en
</button>
<button
class="storybook-button storybook-button--small"
@click="locale = 'fr'"
>
fr
</button>
<button
class="storybook-button storybook-button--small"
@click="locale = 'ar'"
>
ar
</button>
</div>
<div class="storybook welcome" :style="{ direction: rtl ? 'rtl' : 'ltr' }">
<div>{{ t('welcome', { name: 'Storybook' }) }}</div>
<div>{{ t('welcome', { name: 'Nuxt' }) }}</div>
<div>{{ t('welcome', { name: 'I18n' }) }}</div>
</div>

<p>language : {{ lang }}</p>
</template>
19 changes: 19 additions & 0 deletions examples/showcase/components/MyNuxtWelcome.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { Meta, StoryObj } from '@storybook/vue3'

import MyNuxtWelcome from './MyWelcome.vue'

// More on how to set up stories at: https://storybook.js.org/docs/vue/writing-stories/introduction

const meta = {
title: 'Example/NuxtWelcome',
component: MyNuxtWelcome,
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/vue/writing-docs/autodocs
tags: ['autodocs'],
} satisfies Meta<typeof MyNuxtWelcome>

export default meta
type Story = StoryObj<typeof meta>

export const NuxtWelcomeStory: Story = {
args: {},
}
40 changes: 40 additions & 0 deletions examples/showcase/components/MyWelcome.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<template>
<h1>Welcome Nuxt to Storybook</h1>
<NuxtWelcome />
</template>

<style>
.readmore {
-webkit-text-size-adjust: 100%;
tab-size: 4;
box-sizing: border-box;
border-width: 0;
border-style: solid;
border-color: #e0e0e0;
--tw-ring-inset: var(--tw-empty,);
--tw-ring-offset-width: 0px;
--tw-ring-offset-color: #fff;
--tw-ring-color: rgba(14, 165, 233, 0.5);
--tw-ring-offset-shadow: 0 0 #0000;
--tw-ring-shadow: 0 0 #0000;
--tw-shadow: 0 0 #0000;
font-family:
'Nunito Sans',
-apple-system,
'.SFNSText-Regular',
'San Francisco',
BlinkMacSystemFont,
'Segoe UI',
'Helvetica Neue',
Helvetica,
Arial,
sans-serif;
margin: 0;
-webkit-font-smoothing: antialiased;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
line-height: 24px;
color: #029cfd;
text-decoration: none;
font-size: 14px;
}
</style>
16 changes: 16 additions & 0 deletions examples/showcase/i18n.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default defineI18nConfig(() => ({
legacy: false,
locale: 'en',
defaultLocale: 'en',
messages: {
en: {
welcome: 'Welcome to Storybook ❤️ {name} ',
},
fr: {
welcome: 'Bienvenue a Storybook ❤️ {name} ',
},
ar: {
welcome: ' ناكست ❤️ {name} ❤️ مرحبا بكم في ستوري بوك ',
},
},
}))
7 changes: 6 additions & 1 deletion examples/showcase/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
devtools: { enabled: true },
modules: ['@nuxtjs/storybook', '@nuxt/image', '@pinia/nuxt'],
modules: ['@nuxtjs/storybook', '@nuxt/image', '@pinia/nuxt', '@nuxtjs/i18n'],

pinia: {
autoImports: ['defineStore', 'acceptHMRUpdate'],
},

i18n: {
locales: ['en', 'fr', 'ar'],
defaultLocale: 'en',
},

imports: {
dirs: ['./stores'],
},
Expand Down
3 changes: 2 additions & 1 deletion examples/showcase/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"nuxt": "3.14.1592",
"pinia": "2.3.0",
"vue": "3.5.13",
"vue-router": "4.5.0"
"vue-router": "4.5.0",
"@nuxtjs/i18n": "8.3.1"
},
"devDependencies": {
"@chromatic-com/storybook": "3.2.3",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"playground:storybook:dev": "pnpm run --filter=./playground/** storybook",
"playground:storybook:build": "cd playground && pnpm run build-storybook",
"playground:storybook:publish": "chromatic --exit-zero-on-changes --build-script-name playground:storybook:build --project-token=chpt_d7cf5e98426e11e",
"example:starter:dev": "pnpm run --filter=./examples/starter/** examples/starter dev",
"example:starter:dev": "pnpm run --filter=./examples/starter/** dev",
"example:starter:build": "pnpm run --filter=./examples/starter/** build",
"example:starter:storybook:build": "pnpm run --filter=./examples/starter/** build-storybook",
"example:starter:storybook:publish": "chromatic --exit-zero-on-changes --build-script-name example:starter:storybook:build --project-token=chpt_dc04103f8a32bfa",
Expand Down
9 changes: 4 additions & 5 deletions packages/storybook-addon/src/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,17 @@ setup(async (vueApp, storyContext) => {
// This is not totally correct, since the storybook vue renderer actually uses the canvas element
// Also this doesn't allow to "forceRemount"
// TODO: Improve this (needs PR to storybook to pass the necessary infos to this function)
const key = storyContext?.id

// use storyContext.canvasElement.id as key as it's unique for each rendered story
// storyContext.id is same for 2 stories in Docs mode, Primary story and the first story in stories are the same story and have the same id
const key = storyContext?.canvasElement.id
if (!key) {
throw new Error('StoryContext is not provided')
}

// Create a new nuxt app for each story
const storyNuxtAppId = `nuxt-app-${key}`
const storyNuxtCtx = getContext(storyNuxtAppId)
if (storyNuxtCtx.tryUse()) {
// Nothing to do, the Nuxt app is already created
return
}

// Provide the config of the Nuxt app
// @ts-expect-error internal Nuxt property
Expand Down
16 changes: 16 additions & 0 deletions playground/i18n.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default defineI18nConfig(() => ({
legacy: false,
locale: 'en',
defaultLocale: 'en',
messages: {
en: {
welcome: 'Welcome to Storybook ❤️ {name} ',
},
fr: {
welcome: 'Bienvenue a Storybook ❤️ {name} ',
},
ar: {
welcome: ' ناكست ❤️ {name} ❤️ مرحبا بكم في ستوري بوك ',
},
},
}))
11 changes: 10 additions & 1 deletion playground/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
devtools: { enabled: true },
modules: ['../packages/nuxt-module/src/module', '@nuxt/test-utils/module'],
modules: [
'../packages/nuxt-module/src/module',
'@nuxt/test-utils/module',
'@nuxtjs/i18n',
],

storybook: {
// Very verbose logs for debugging
logLevel: Number.POSITIVE_INFINITY,
},

i18n: {
locales: ['en', 'fr', 'ar'],
defaultLocale: 'en',
},

compatibilityDate: '2024-08-03',
})
3 changes: 2 additions & 1 deletion playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"nuxt": "3.14.1592",
"vue": "3.5.13",
"storybook": "8.4.7",
"vite-plugin-inspect": "0.10.3"
"vite-plugin-inspect": "0.10.3",
"@nuxtjs/i18n": "^8.3.1"
}
}
36 changes: 36 additions & 0 deletions playground/stories/MyI18n.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { Meta, StoryObj } from '@storybook/vue3'

import MyComponent from './MyI18n.vue'

// More on how to set up stories at: https://storybook.js.org/docs/vue/writing-stories/introduction

const meta = {
title: 'Plugins/I18n',
component: MyComponent,
argTypes: {
lang: { control: 'select', options: ['en', 'fr', 'ar'] },
},

// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/vue/writing-docs/autodocs
tags: ['autodocs'],
} satisfies Meta<typeof MyComponent>

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 FrenchStory: Story = {
args: { lang: 'fr' },
}

export const EnglishStory: Story = {
args: { lang: 'en' },
}

export const ArabicStory: Story = {
args: { lang: 'ar' },
}
47 changes: 47 additions & 0 deletions playground/stories/MyI18n.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<script lang="ts" setup>
import './button.css'

const props = defineProps<{
lang: string
message?: string
}>()
const { t, locale } = useI18n()
const rtl = computed(() => props.lang === 'ar')
locale.value = props.lang
watch(
() => props.lang,
(lang: unknown) => {
locale.value = lang
},
)
</script>

<template>
<div class="storybook lang-selector">
<button
class="storybook-button storybook-button--small"
@click="locale = 'en'"
>
en
</button>
<button
class="storybook-button storybook-button--small"
@click="locale = 'fr'"
>
fr
</button>
<button
class="storybook-button storybook-button--small"
@click="locale = 'ar'"
>
ar
</button>
</div>
<div class="storybook welcome" :style="{ direction: rtl ? 'rtl' : 'ltr' }">
<div>{{ t('welcome', { name: 'Storybook' }) }}</div>
<div>{{ t('welcome', { name: 'Nuxt' }) }}</div>
<div>{{ t('welcome', { name: 'I18n' }) }}</div>
</div>

<p>language : {{ lang }}</p>
</template>
Loading
Loading