diff --git a/.storybook/decorator-theme.js b/.storybook/decorator-theme.js new file mode 100644 index 0000000000..c3a60f8386 --- /dev/null +++ b/.storybook/decorator-theme.js @@ -0,0 +1,53 @@ +import { upperFirst } from 'lodash'; +import React from 'react'; +import styled, { ThemeProvider } from 'styled-components'; +import theme, { prop } from '../client/theme'; + +const PreviewArea = styled.div` + background: ${prop('backgroundColor')}; + flex-grow: 1; + padding: 2rem; + & > h4 { + margin-top: 0; + color: ${prop('primaryTextColor')}; + } +`; + +const themeKeys = Object.keys(theme); + +export const withThemeProvider = (Story, context) => { + const setting = context.globals.theme; + if (setting === 'all') { + return ( +
+ {Object.keys(theme).map((themeName) => ( + + +

{upperFirst(themeName)}

+ +
+
+ ))} +
+ ); + } else { + const themeName = setting; + return ( + + + + + + ); + } +}; + +export const themeToolbarItem = { + description: 'Global theme for components', + defaultValue: 'all', + toolbar: { + title: 'Theme', + icon: 'mirror', + items: [...themeKeys, 'all'] + } +}; diff --git a/.storybook/preview.js b/.storybook/preview.js index 8c29a24faa..9260b91c98 100644 --- a/.storybook/preview.js +++ b/.storybook/preview.js @@ -2,10 +2,10 @@ import React from 'react'; import { Provider } from 'react-redux'; import { MemoryRouter } from 'react-router'; -import ThemeProvider from '../client/modules/App/components/ThemeProvider'; import configureStore from '../client/store'; import '../client/i18n-test'; import '../client/styles/storybook.css' +import { withThemeProvider, themeToolbarItem } from './decorator-theme'; const initialState = window.__INITIAL_STATE__; @@ -21,5 +21,9 @@ export const decorators = [ ), -] + withThemeProvider +]; +export const globalTypes = { + theme: themeToolbarItem +};