From ed3f1a9f17b4e43d3f19cbc916cbcb595e17175a Mon Sep 17 00:00:00 2001 From: EnzoVezzaro Date: Thu, 13 Oct 2022 11:34:45 -0400 Subject: [PATCH] handle darkmode + color schema --- .storybook/preview.js | 48 +++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/.storybook/preview.js b/.storybook/preview.js index 4fcd1bf48..57120fc35 100644 --- a/.storybook/preview.js +++ b/.storybook/preview.js @@ -1,26 +1,14 @@ import '@oceanprotocol/typographies/css/ocean-typo.css' import '../src/stylesGlobal/styles.css' import { ThemeProvider } from 'styled-components' +import { useDarkMode } from 'storybook-dark-mode' +import addons from '@storybook/addons' -export const globalTypes = { +export const globalSetup = { theme: { name: 'Ocean Market', description: 'Global theme for Ocean Market', - defaultValue: 'light', - toolbar: { - icon: 'circlehollow', - items: [ - { value: 'light', title: 'Light' }, - { value: 'dark', title: 'Dark' } - ] - } - }, - backgrounds: { - default: 'light', - values: [ - { name: 'dark', value: 'rgb(10, 10, 10)' }, - { name: 'light', value: '#fcfcfc' } - ] + defaultValue: 'light' }, actions: { argTypesRegex: '^on[A-Z].*' }, controls: { @@ -31,17 +19,29 @@ export const globalTypes = { } } +const channel = addons.getChannel() + +channel.on('DARK_MODE', (isDark) => { + if (isDark) { + document.body.classList.add('dark') + } else { + document.body.classList.remove('dark') + } +}) + +const themeSelection = (mode) => { + return { + mode: mode, + ...globalSetup + } +} + const withThemeProvider = (Story, context) => { - const theme = context.globals.theme - - var storyBody = document.getElementById('story-body') - - storyBody && theme === 'dark' - ? storyBody.classList.add('dark') - : storyBody.classList.remove('dark') + const mode = useDarkMode() ? 'dark' : 'light' + const currentTheme = themeSelection(mode) return ( - + )