mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
handle darkmode + color schema
This commit is contained in:
parent
6f093fec24
commit
ed3f1a9f17
@ -1,26 +1,14 @@
|
|||||||
import '@oceanprotocol/typographies/css/ocean-typo.css'
|
import '@oceanprotocol/typographies/css/ocean-typo.css'
|
||||||
import '../src/stylesGlobal/styles.css'
|
import '../src/stylesGlobal/styles.css'
|
||||||
import { ThemeProvider } from 'styled-components'
|
import { ThemeProvider } from 'styled-components'
|
||||||
|
import { useDarkMode } from 'storybook-dark-mode'
|
||||||
|
import addons from '@storybook/addons'
|
||||||
|
|
||||||
export const globalTypes = {
|
export const globalSetup = {
|
||||||
theme: {
|
theme: {
|
||||||
name: 'Ocean Market',
|
name: 'Ocean Market',
|
||||||
description: 'Global theme for Ocean Market',
|
description: 'Global theme for Ocean Market',
|
||||||
defaultValue: 'light',
|
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' }
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
actions: { argTypesRegex: '^on[A-Z].*' },
|
actions: { argTypesRegex: '^on[A-Z].*' },
|
||||||
controls: {
|
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 withThemeProvider = (Story, context) => {
|
||||||
const theme = context.globals.theme
|
const mode = useDarkMode() ? 'dark' : 'light'
|
||||||
|
const currentTheme = themeSelection(mode)
|
||||||
var storyBody = document.getElementById('story-body')
|
|
||||||
|
|
||||||
storyBody && theme === 'dark'
|
|
||||||
? storyBody.classList.add('dark')
|
|
||||||
: storyBody.classList.remove('dark')
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ThemeProvider theme={globalTypes}>
|
<ThemeProvider theme={currentTheme}>
|
||||||
<Story {...context} />
|
<Story {...context} />
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user