preview.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import './preview.css'
  2. // Storybook does not (currently) support async loading of "stories". Therefore
  3. // the strategy in frontend/js/i18n.js does not work (because we cannot wait on
  4. // the promise to resolve).
  5. // Therefore we have to use the synchronous method for configuring
  6. // react-i18next. Because this, we can only hard-code a single language.
  7. import i18n from 'i18next'
  8. import { initReactI18next } from 'react-i18next'
  9. import en from '../locales/en.json'
  10. i18n.use(initReactI18next).init({
  11. lng: 'en',
  12. resources: {
  13. en: { translation: en },
  14. },
  15. react: {
  16. useSuspense: false,
  17. },
  18. interpolation: {
  19. prefix: '__',
  20. suffix: '__',
  21. unescapeSuffix: 'HTML',
  22. skipOnVariables: true,
  23. defaultVariables: {
  24. appName: 'Overleaf',
  25. },
  26. },
  27. })
  28. export const parameters = {
  29. // Automatically mark prop-types like onClick, onToggle, etc as Storybook
  30. // "actions", so that they are logged in the Actions pane at the bottom of the
  31. // viewer
  32. actions: { argTypesRegex: '^on.*' },
  33. docs: {
  34. // render stories in iframes, to isolate modals
  35. inlineStories: false,
  36. },
  37. }
  38. export const globalTypes = {
  39. theme: {
  40. name: 'Theme',
  41. description: 'Editor theme',
  42. defaultValue: 'default-',
  43. toolbar: {
  44. icon: 'circlehollow',
  45. items: [
  46. { value: 'default-', title: 'Default' },
  47. { value: 'light-', title: 'Light' },
  48. { value: 'ieee-', title: 'IEEE' },
  49. ],
  50. },
  51. },
  52. }
  53. export const loaders = [
  54. async ({ globals }) => {
  55. const { theme } = globals
  56. return {
  57. // NOTE: this uses `${theme}style.less` rather than `${theme}.less`
  58. // so that webpack only bundles files ending with "style.less"
  59. activeStyle: await import(
  60. `../frontend/stylesheets/${theme === 'default-' ? '' : theme}style.less`
  61. ),
  62. }
  63. },
  64. ]
  65. const withTheme = (Story, context) => {
  66. const { activeStyle } = context.loaded
  67. return (
  68. <>
  69. {activeStyle && <style>{activeStyle.default}</style>}
  70. <Story {...context} />
  71. </>
  72. )
  73. }
  74. export const decorators = [withTheme]
  75. window.ExposedSettings = {
  76. maxEntitiesPerProject: 10,
  77. maxUploadSize: 5 * 1024 * 1024,
  78. enableSubscriptions: true,
  79. textExtensions: [
  80. 'tex',
  81. 'latex',
  82. 'sty',
  83. 'cls',
  84. 'bst',
  85. 'bib',
  86. 'bibtex',
  87. 'txt',
  88. 'tikz',
  89. 'mtx',
  90. 'rtex',
  91. 'md',
  92. 'asy',
  93. 'latexmkrc',
  94. 'lbx',
  95. 'bbx',
  96. 'cbx',
  97. 'm',
  98. 'lco',
  99. 'dtx',
  100. 'ins',
  101. 'ist',
  102. 'def',
  103. 'clo',
  104. 'ldf',
  105. 'rmd',
  106. 'lua',
  107. 'gv',
  108. 'mf',
  109. ],
  110. }
  111. window.user = {
  112. id: 'storybook',
  113. }