preview.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. `!!to-string-loader!css-loader!less-loader!../frontend/stylesheets/${
  61. theme === 'default-' ? '' : theme
  62. }style.less`
  63. ),
  64. }
  65. },
  66. ]
  67. const withTheme = (Story, context) => {
  68. const { activeStyle } = context.loaded
  69. return (
  70. <>
  71. {activeStyle && <style>{activeStyle.default}</style>}
  72. <Story {...context} />
  73. </>
  74. )
  75. }
  76. export const decorators = [withTheme]
  77. window.ExposedSettings = {
  78. maxEntitiesPerProject: 10,
  79. maxUploadSize: 5 * 1024 * 1024,
  80. enableSubscriptions: true,
  81. textExtensions: [
  82. 'tex',
  83. 'latex',
  84. 'sty',
  85. 'cls',
  86. 'bst',
  87. 'bib',
  88. 'bibtex',
  89. 'txt',
  90. 'tikz',
  91. 'mtx',
  92. 'rtex',
  93. 'md',
  94. 'asy',
  95. 'latexmkrc',
  96. 'lbx',
  97. 'bbx',
  98. 'cbx',
  99. 'm',
  100. 'lco',
  101. 'dtx',
  102. 'ins',
  103. 'ist',
  104. 'def',
  105. 'clo',
  106. 'ldf',
  107. 'rmd',
  108. 'lua',
  109. 'gv',
  110. 'mf',
  111. ],
  112. }
  113. window.user = {
  114. id: 'storybook',
  115. }
  116. window.project_id = 'storybook-project'