preview.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import '../src/radix.css'
  2. import '../src/radix-hsl.css'
  3. import './theme.css'
  4. import '../src/index.css'
  5. import { useEffect } from 'react'
  6. // require in this file to keep app state when HMR
  7. const { setupGlobals } = require('../src/ui')
  8. setupGlobals()
  9. // REPL
  10. if (process.env.NODE_ENV !== 'production') {
  11. require('./cljs/cljs_env')
  12. require('./cljs/shadow.cljs.devtools.client.browser')
  13. }
  14. function ThemeObserver(
  15. { children }
  16. ) {
  17. const theme = window.localStorage.getItem('__ls-theme-color__')
  18. useEffect(() => {
  19. const html = document.documentElement
  20. html.dataset.color = theme
  21. return () => (delete html.dataset.theme)
  22. }, [theme])
  23. return (
  24. <div className={'p-4'}>
  25. {children}
  26. </div>
  27. )
  28. }
  29. /** @type { import('@storybook/react').Preview } */
  30. const preview = {
  31. parameters: {
  32. actions: { argTypesRegex: '^on[A-Z].*' },
  33. controls: {
  34. matchers: {
  35. color: /(background|color)$/i,
  36. date: /Date$/i,
  37. },
  38. },
  39. },
  40. decorators: [
  41. (Story) => {
  42. return (
  43. <ThemeObserver>
  44. <Story/>
  45. </ThemeObserver>
  46. )
  47. }
  48. ],
  49. globalTypes: {
  50. theme: {
  51. // description: 'Global theme for components',
  52. // defaultValue: 'light',
  53. // toolbar: {
  54. // // The label to show for this toolbar item
  55. // title: 'Theme',
  56. // icon: 'circlehollow',
  57. // // Array of plain string values or MenuItem shape (see below)
  58. // items: ['light', 'dark'],
  59. // // Change title based on selected value
  60. // dynamicTitle: true,
  61. // },
  62. },
  63. },
  64. }
  65. export default preview