preview.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import 'focus-visible';
  2. import '../docs-ui/index.js';
  3. import React from 'react';
  4. import {addDecorator, addParameters} from '@storybook/react';
  5. import {ThemeProvider} from 'emotion-theming';
  6. import GlobalStyles from '../static/app/styles/global';
  7. import {darkTheme, lightTheme} from '../static/app/utils/theme';
  8. const withTheme = (Story, context) => {
  9. const isDark = context.globals.theme === 'dark';
  10. const currentTheme = isDark ? darkTheme : lightTheme;
  11. // Set @storybook/addon-backgrounds current color based on theme
  12. if (context.globals.theme) {
  13. context.globals.backgrounds = {value: currentTheme.bodyBackground};
  14. }
  15. return (
  16. <ThemeProvider theme={currentTheme}>
  17. <GlobalStyles isDark={isDark} theme={currentTheme} />
  18. <Story {...context} />
  19. </ThemeProvider>
  20. );
  21. };
  22. addDecorator(withTheme);
  23. // Option defaults:
  24. addParameters({
  25. options: {
  26. /**
  27. * show story component as full screen
  28. * @type {Boolean}
  29. */
  30. isFullscreen: false,
  31. /**
  32. * display panel that shows a list of stories
  33. * @type {Boolean}
  34. */
  35. showNav: true,
  36. /**
  37. * display panel that shows addon configurations
  38. * @type {Boolean}
  39. */
  40. showPanel: true,
  41. /**
  42. * where to show the addon panel
  43. * @type {('bottom'|'right')}
  44. */
  45. panelPosition: 'bottom',
  46. /**
  47. * regex for finding the hierarchy separator
  48. * @example:
  49. * null - turn off hierarchy
  50. * /\// - split by `/`
  51. * /\./ - split by `.`
  52. * /\/|\./ - split by `/` or `.`
  53. * @type {Regex}
  54. */
  55. hierarchySeparator: /\/|\./,
  56. /**
  57. * regex for finding the hierarchy root separator
  58. * @example:
  59. * null - turn off multiple hierarchy roots
  60. * /\|/ - split by `|`
  61. * @type {Regex}
  62. */
  63. hierarchyRootSeparator: /\|/,
  64. /**
  65. * sidebar tree animat
  66. * ions
  67. * @type {Boolean}
  68. */
  69. sidebarAnimations: true,
  70. /**
  71. * enable/disable shortcuts
  72. * @type {Boolean}
  73. */
  74. enableShortcuts: true,
  75. /**
  76. * show/hide tool bar
  77. * @type {Boolean}
  78. */
  79. isToolshown: true,
  80. /**
  81. * function to sort stories in the tree view
  82. * common use is alphabetical `(a, b) => a[1].id.localeCompare(b[1].id)`
  83. * if left undefined, then the order in which the stories are imported will
  84. * be the order they display
  85. * @type {Function}
  86. */
  87. storySort: {
  88. order: [
  89. 'Core',
  90. 'Forms',
  91. 'UI',
  92. 'Layouts',
  93. 'Charts',
  94. 'DataVisualization',
  95. 'Features',
  96. 'Utilities',
  97. 'Deprecated',
  98. ],
  99. },
  100. },
  101. });
  102. export const globalTypes = {
  103. theme: {
  104. name: 'Theme',
  105. description: 'Global theme for components',
  106. defaultValue: 'light',
  107. toolbar: {
  108. icon: 'circlehollow',
  109. // array of plain string values or MenuItem shape (see below)
  110. items: [
  111. {value: 'light', icon: 'circlehollow', title: 'light'},
  112. {value: 'dark', icon: 'circle', title: 'dark'},
  113. ],
  114. },
  115. },
  116. };
  117. export const parameters = {
  118. /**
  119. * @storybook/addon-backgrounds background is controlled via theme
  120. */
  121. backgrounds: {
  122. grid: {
  123. disable: true,
  124. },
  125. default: 'light',
  126. values: [
  127. {
  128. name: 'light',
  129. value: lightTheme.background,
  130. },
  131. {
  132. name: 'dark',
  133. value: darkTheme.background,
  134. },
  135. ],
  136. },
  137. };