1
0

manager.js 1.1 KB

123456789101112131415161718192021222324252627282930
  1. import React from 'react'
  2. import { addons, types } from '@storybook/manager-api'
  3. import { FORCE_RE_RENDER } from '@storybook/core-events'
  4. addons.register('my/toolbar', () => {
  5. addons.add('my-toolbar-addon/toolbar', {
  6. title: 'Example Storybook toolbar',
  7. //👇 Sets the type of UI element in Storybook
  8. type: types.TOOL,
  9. //👇 Shows the Toolbar UI element if either the Canvas or Docs tab is active
  10. match: ({ viewMode }) => !!(viewMode && viewMode.match(/^(story|docs)$/)),
  11. render: ({ active }) => {
  12. const defaultTheme = window.localStorage.getItem('__ls-theme-color__')
  13. return (
  14. <div style={{ display: 'flex', alignItems: 'center', padding: 15 }}>
  15. <select onChange={(e) => {
  16. const value = e.target.value
  17. window.localStorage.setItem('__ls-theme-color__', value)
  18. addons.getChannel().emit(FORCE_RE_RENDER)
  19. }} defaultValue={defaultTheme || 'default'}>
  20. {['default', 'blue', 'orange', 'green'].map(it => {
  21. return <option value={it} key={it}>{it}</option>
  22. })}
  23. </select>
  24. </div>
  25. )
  26. },
  27. })
  28. })