mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-28 18:02:28 +00:00
f5449dc4b0
Set up Storybook and add Outline stories GitOrigin-RevId: 2635ad142ef152a5ee8023c10cf31f344fbd7e8d
65 lines
1.7 KiB
JavaScript
65 lines
1.7 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.*' }
|
|
}
|
|
|
|
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]
|