mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
4fe179f69e
Configure Storybook to render Docs stories in iframes GitOrigin-RevId: ef96a0fad445375fc33c5875958c4a3170f0818e
71 lines
1.8 KiB
JavaScript
71 lines
1.8 KiB
JavaScript
import React from 'react'
|
|
|
|
const DefaultTheme = React.lazy(() => import('./default-theme'))
|
|
const LightTheme = React.lazy(() => import('./light-theme'))
|
|
const IEEETheme = React.lazy(() => import('./ieee-theme'))
|
|
|
|
// Storybook does not (currently) support async loading of "stories". Therefore
|
|
// the strategy in frontend/js/i18n.js does not work (because we cannot wait on
|
|
// the promise to resolve).
|
|
// Therefore we have to use the synchronous method for configuring
|
|
// react-i18next. Because this, we can only hard-code a single language.
|
|
import i18n from 'i18next'
|
|
import { initReactI18next } from 'react-i18next'
|
|
import en from '../locales/en.json'
|
|
i18n.use(initReactI18next).init({
|
|
lng: 'en',
|
|
|
|
resources: {
|
|
en: { translation: en }
|
|
},
|
|
|
|
react: {
|
|
useSuspense: false
|
|
},
|
|
|
|
interpolation: {
|
|
prefix: '__',
|
|
suffix: '__',
|
|
unescapeSuffix: 'HTML',
|
|
skipOnVariables: true
|
|
}
|
|
})
|
|
|
|
export const parameters = {
|
|
// Automatically mark prop-types like onClick, onToggle, etc as Storybook
|
|
// "actions", so that they are logged in the Actions pane at the bottom of the
|
|
// viewer
|
|
actions: { argTypesRegex: '^on.*' },
|
|
docs: {
|
|
// render stories in iframes, to isolate modals
|
|
inlineStories: false
|
|
}
|
|
}
|
|
|
|
export const globalTypes = {
|
|
theme: {
|
|
name: 'Theme',
|
|
description: 'Editor theme',
|
|
defaultValue: 'default',
|
|
toolbar: {
|
|
icon: 'circlehollow',
|
|
items: ['default', 'light', 'IEEE']
|
|
}
|
|
}
|
|
}
|
|
|
|
const withTheme = (Story, context) => {
|
|
return (
|
|
<>
|
|
<React.Suspense fallback={<></>}>
|
|
{context.globals.theme === 'default' && <DefaultTheme />}
|
|
{context.globals.theme === 'light' && <LightTheme />}
|
|
{context.globals.theme === 'IEEE' && <IEEETheme />}
|
|
</React.Suspense>
|
|
<Story {...context} />
|
|
</>
|
|
)
|
|
}
|
|
export const decorators = [withTheme]
|
|
|
|
window.ExposedSettings = {}
|