From b383c1749ee644ee9cd2789ecd696ae0d49f207a Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Thu, 25 Jun 2020 19:15:46 +0200 Subject: [PATCH] IMPROVE the double theming --- examples/official-storybook/preview.js | 123 ++++++++++++------ .../components/sidebar/Sidebar.stories.tsx | 13 -- 2 files changed, 80 insertions(+), 56 deletions(-) diff --git a/examples/official-storybook/preview.js b/examples/official-storybook/preview.js index 93ec936ee9ee..4ac7e6cc767e 100644 --- a/examples/official-storybook/preview.js +++ b/examples/official-storybook/preview.js @@ -1,7 +1,15 @@ -import React, { Fragment } from 'react'; +import React, { Fragment, useEffect } from 'react'; import { isChromatic } from 'chromatic'; import { addDecorator, addParameters } from '@storybook/react'; -import { Global, ThemeProvider, themes, createReset, convert, styled } from '@storybook/theming'; +import { + Global, + ThemeProvider, + themes, + createReset, + convert, + styled, + useTheme, +} from '@storybook/theming'; import { withCssResources } from '@storybook/addon-cssresources'; import { DocsPage } from '@storybook/addon-docs/blocks'; @@ -26,18 +34,6 @@ addHeadWarning('dotenv-file-not-loaded', 'Dotenv file not loaded'); addDecorator(withCssResources); -const themeDecorator = (storyFn, { globalArgs: { theme } }) => { - const selectedTheme = theme === 'dark' ? themes.dark : themes.light; - return ( - - - {storyFn()} - - ); -}; - -addDecorator(themeDecorator); - const ThemeBlock = styled.div( { position: 'absolute', @@ -66,27 +62,75 @@ const ThemeBlock = styled.div( } ); -addDecorator((storyFn) => - isChromatic() ? ( - - - - - - {storyFn()} - - - {storyFn()} - - - ) : ( - - - {storyFn()} - - ) +const ThemeStack = styled.div( + { + position: 'relative', + minHeight: 'calc(50vh - 15px)', + }, + ({ theme }) => ({ + background: theme.background.app, + color: theme.color.defaultText, + }) ); +const ThemedSetRoot = () => { + const theme = useTheme(); + + useEffect(() => { + document.body.style.background = theme.background.app; + document.body.style.color = theme.defaultText; + return () => { + // + }; + }); + + return null; +}; + +addDecorator((storyFn, { globalArgs: { theme = 'light' } }) => { + switch (theme) { + case 'side-by-side': { + return ( + + + + + + {storyFn()} + + + {storyFn()} + + + ); + } + case 'stacked': { + return ( + + + + + + {storyFn()} + + + {storyFn()} + + + ); + } + default: { + return ( + + + + {storyFn()} + + ); + } + } +}); + addParameters({ a11y: { config: {}, @@ -99,14 +143,6 @@ addParameters({ storySort: (a, b) => a[1].kind === b[1].kind ? 0 : a[1].id.localeCompare(b[1].id, undefined, { numeric: true }), }, - backgrounds: { - default: 'storybook app', - values: [ - { name: 'storybook app', value: themes.light.appBg }, - { name: 'light', value: '#eeeeee' }, - { name: 'dark', value: '#222222' }, - ], - }, docs: { theme: themes.light, page: () => `Subtitle: ${kind}`} />, @@ -127,13 +163,14 @@ export const globalArgTypes = { theme: { name: 'Theme', description: 'Global theme for components', - defaultValue: null, + defaultValue: isChromatic() ? 'stacked' : 'light', toolbar: { icon: 'circlehollow', - // items: ['light', 'dark'], items: [ { value: 'light', icon: 'circlehollow', title: 'light' }, { value: 'dark', icon: 'circle', title: 'dark' }, + { value: 'side-by-side', icon: 'sidebar', title: 'side by side' }, + { value: 'stacked', icon: 'bottombar', title: 'stacked' }, ], }, }, diff --git a/lib/ui/src/components/sidebar/Sidebar.stories.tsx b/lib/ui/src/components/sidebar/Sidebar.stories.tsx index 572f48418ff6..9dd246b0a739 100644 --- a/lib/ui/src/components/sidebar/Sidebar.stories.tsx +++ b/lib/ui/src/components/sidebar/Sidebar.stories.tsx @@ -123,16 +123,3 @@ export const isEmpty = () => ( export const withRefs = () => ( ); - -export const darkWithRefs = () => ( - - - -); - -darkWithRefs.parameters = { - backgrounds: { - default: 'dark', - values: [{ name: 'dark', value: '#222222', default: true }], - }, -};