UNPKG

storybook-react-intl

Version:
1 lines 3.08 kB
{"version":3,"sources":["../src/withReactIntl.tsx","../src/preview.ts"],"names":["withReactIntl","StoryFn","context","locale","useGlobals","reactIntl","defaultLocale","currentLocale","formats","messages","defaultRichTextElements","timeZone","safeFormats","React","IntlProvider","i18nDecorators","i18n","preview","preview_default"],"mappings":"mTASO,IAAMA,CAAgB,CAAA,CACzBC,CACAC,CAAAA,CAAAA,GACC,CACD,GAAM,CAAC,CAAC,MAAAC,CAAAA,CAAM,CAAC,CAAA,CAAIC,qBAAW,EAAA,CACxB,CACF,UAAY,CAAA,CAAC,SAAAC,CAAAA,CAAAA,CAAW,MAAQC,CAAAA,CAAa,CACjD,CAAA,CAAIJ,CACEK,CAAAA,CAAAA,CAAgBJ,CAAUG,EAAAA,CAAAA,CAEhC,GAAIC,CAAAA,EAAiBF,CAAW,CAAA,CAC5B,GAAM,CAAC,OAAAG,CAAAA,CAAAA,CAAS,QAAAC,CAAAA,CAAAA,CAAU,uBAAAC,CAAAA,CAAAA,CAAyB,QAAAC,CAAAA,CAAQ,CACvDN,CAAAA,CAAAA,CACEO,CAAcJ,CAAAA,CAAAA,CAAUA,EAAQD,CAAa,CAAA,CAAI,MACvD,CAAA,GAAIE,CACA,CAAA,OACII,kBAAA,CAAA,aAAA,CAACC,sBAAA,CAAA,CACG,QAAUH,CAAAA,CAAAA,CACV,GAAKR,CAAAA,CAAAA,CACL,QAASS,CACT,CAAA,QAAA,CAAUH,CAASF,CAAAA,CAAa,CAChC,CAAA,MAAA,CAAQA,CACR,CAAA,aAAA,CAAeD,CACf,CAAA,uBAAA,CAAyBI,CAEzBG,CAAAA,CAAAA,kBAAAA,CAAA,aAAAA,CAAAA,kBAAAA,CAAA,cAAGZ,CAAQC,CAAAA,CAAO,CAAE,CACxB,CAGZ,CACA,OAAOD,CAAAA,CAAQC,CAAO,CAC1B,CCnCA,CAAA,IAAMa,CAAiBC,CAAAA,kBAAAA,EAAM,UAAc,EAAA,EAErCC,CAAAA,CAAAA,CAAwC,CAC1C,GAAGD,kBACH,CAAA,UAAA,CAAY,CAAC,GAAGD,CAAgBf,CAAAA,CAAa,CACjD,CAAA,CAEOkB,CAAQD,CAAAA","file":"preview.cjs","sourcesContent":["import React from 'react';\nimport type {\n Renderer,\n PartialStoryFn as StoryFunction,\n StoryContext,\n} from 'storybook/internal/types';\nimport {IntlProvider} from 'react-intl';\nimport {useGlobals} from 'storybook/preview-api';\n\nexport const withReactIntl = (\n StoryFn: StoryFunction<Renderer>,\n context: StoryContext<Renderer>,\n) => {\n const [{locale}] = useGlobals();\n const {\n parameters: {reactIntl, locale: defaultLocale},\n } = context;\n const currentLocale = locale || defaultLocale;\n\n if (currentLocale && reactIntl) {\n const {formats, messages, defaultRichTextElements, timeZone} =\n reactIntl;\n const safeFormats = formats ? formats[currentLocale] : undefined;\n if (messages) {\n return (\n <IntlProvider\n timeZone={timeZone}\n key={locale}\n formats={safeFormats}\n messages={messages[currentLocale]}\n locale={currentLocale}\n defaultLocale={defaultLocale}\n defaultRichTextElements={defaultRichTextElements}\n >\n <>{StoryFn(context)}</>\n </IntlProvider>\n );\n }\n }\n return StoryFn(context);\n};\n","import type {Renderer, ProjectAnnotations} from 'storybook/internal/types';\nimport i18n from 'storybook-i18n/preview';\nimport {withReactIntl} from './withReactIntl';\n\n// @ts-ignore\nconst i18nDecorators = i18n?.decorators || [];\n\nconst preview: ProjectAnnotations<Renderer> = {\n ...i18n,\n decorators: [...i18nDecorators, withReactIntl],\n};\n\nexport default preview;\n"]}