-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathstorybook.preview.js.template
44 lines (40 loc) · 1.23 KB
/
storybook.preview.js.template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import * as React from 'react'
import { I18nextProvider } from 'react-i18next'
import i18n from 'web/src/i18n'
/** @type { import("@storybook/csf").GlobalTypes } */
export const globalTypes = {
locale: {
name: 'Locale',
description: 'Internationalization locale',
defaultValue: 'en',
toolbar: {
icon: 'globe',
items: [
{ value: 'en', right: '🇺🇸', title: 'English' },
{ value: 'fr', right: '🇫🇷', title: 'Français' },
],
},
},
}
/**
* We're following Storybook's naming convention here. See for example
* https://github.com/storybookjs/addon-kit/blob/main/src/withGlobals.ts
* Unfortunately that will make eslint complain, so we have to disable it when
* using a hook below
*
* @param { import("@storybook/addons").StoryFn} StoryFn
* @param { import("@storybook/addons").StoryContext} context
* @returns a story wrapped in an I18nextProvider
*/
const withI18n = (StoryFn, context) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
React.useEffect(() => {
i18n.changeLanguage(context.globals.locale)
}, [context.globals.locale])
return (
<I18nextProvider i18n={i18n}>
<StoryFn />
</I18nextProvider>
)
}
export const decorators = [withI18n]