UNPKG

storybook-next-intl

Version:
1 lines 2.6 kB
{"version":3,"sources":["../src/withNextIntl.tsx","../src/preview.ts"],"names":["withNextIntl","StoryFn","context","locale","useGlobals","nextIntl","defaultLocale","messagesByLocale","currentLocale","currentMessages","React","NextIntlClientProvider","i18nDecorators","i18n","preview","preview_default"],"mappings":"iTASO,IAAMA,CAAe,CAAA,CACxBC,EACAC,CACC,GAAA,CACD,GAAM,CAAC,CAAC,MAAA,CAAAC,CAAM,CAAC,CAAA,CAAIC,uBACb,CAAA,CACF,WAAY,CAAC,QAAA,CAAAC,CAAQ,CACzB,CAAIH,CAAAA,CAAAA,CAEJ,GAAIG,CAAa,GAAA,MAAA,CACb,eAAQ,KACJ,CAAA,qHACJ,EACOJ,CAAQC,CAAAA,CAAO,CAG1B,CAAA,GAAM,CAAC,aAAA,CAAAI,EAAe,gBAAAC,CAAAA,CAAgB,EAAIF,CAAY,EAAA,GAEhDG,CAAgBL,CAAAA,CAAAA,EAAUG,EAC1BG,CAAkBF,CAAAA,CAAAA,CAAiBC,CAAa,CAAK,EAAA,GAE3D,OACIE,kBAAAA,CAAA,cAACC,+BAAA,CAAA,CACI,GAAGN,CAAAA,CACJ,MAAQG,CAAAA,CAAAA,CACR,SAAUC,CAETR,CAAAA,CAAAA,CAAAA,CAAQC,CAAO,CACpB,CAER,EClCMU,IAAAA,CAAAA,CAAiBC,kBAAK,CAAA,UAAA,EAAc,EAAC,CAErCC,EAAwC,CAC1C,GAAGD,mBACH,UAAY,CAAA,CAAC,GAAGD,CAAgBZ,CAAAA,CAAY,CAChD,CAAA,CAEOe,CAAQD,CAAAA","file":"preview.cjs","sourcesContent":["import React, {ReactNode} from 'react';\nimport {useGlobals} from 'storybook/preview-api';\nimport type {\n PartialStoryFn as StoryFunction,\n Renderer,\n StoryContext,\n} from 'storybook/internal/types';\nimport {NextIntlClientProvider} from 'next-intl';\n\nexport const withNextIntl = (\n StoryFn: StoryFunction<Renderer>,\n context: StoryContext<Renderer>,\n) => {\n const [{locale}] = useGlobals();\n const {\n parameters: {nextIntl},\n } = context;\n\n if (nextIntl === undefined) {\n console.error(\n `The 'nextIntl' parameter is missing in 'parameters' configuration of preview.js. Check the README for instructions.`,\n );\n return StoryFn(context);\n }\n\n const {defaultLocale, messagesByLocale} = nextIntl || {};\n\n const currentLocale = locale || defaultLocale;\n const currentMessages = messagesByLocale[currentLocale] || {};\n\n return (\n <NextIntlClientProvider\n {...nextIntl}\n locale={currentLocale}\n messages={currentMessages}\n >\n {StoryFn(context) as ReactNode | null}\n </NextIntlClientProvider>\n );\n};\n","import type {Renderer, ProjectAnnotations} from 'storybook/internal/types';\nimport i18n from 'storybook-i18n/preview';\nimport {withNextIntl} from './withNextIntl';\n\n// @ts-ignore\nconst i18nDecorators = i18n.decorators || [];\n\nconst preview: ProjectAnnotations<Renderer> = {\n ...i18n,\n decorators: [...i18nDecorators, withNextIntl],\n};\n\nexport default preview;\n"]}