I am making a PWA using light and dark themes, and I want to create my Storybook light and dark themes to reflect those.
So I created a function that will return a new Storybook theme object to me if I pass it a Material UI Theme and a base name.
But how do I pass these 2 objects to Storybook as themes?
I have found out that I am supposed to go to manager.js and add the following code
import theme from '../src/theme/theme'
import createThemeFromMUITheme from './create-theme-from-mui-theme'
import addons from '@storybook/addons'
addons.setConfig({
theme: createThemeFromMUITheme('light', theme.light),
})
But how do I set theme for both light and dark?
I have tried
import theme from '../src/theme/theme'
import createThemeFromMUITheme from './create-theme-from-mui-theme'
import addons from '@storybook/addons'
addons.setConfig({
theme: {
light: createThemeFromMUITheme('light', theme.light),
dark: createThemeFromMUITheme('dark', theme.dark)
},
})
But that makes the storybook show nothing (it does not fail however)
Help please :-)
EDIT: I have also tried the following
import theme from '../src/theme/theme'
import createThemeFromMUITheme from './create-theme-from-mui-theme'
import addons from '@storybook/addons'
addons.setConfig({
theme: createThemeFromMUITheme('light', theme.light),
})
addons.setConfig({
theme: createThemeFromMUITheme('dark', theme.dark),
})
EDIT #2: The returned theme config object from createThemeFromMUITheme is valid BTW
And if anyone should want the function I made to convert a MUI theme object into a SB theme object - then this is it...
(I did not mess with form colors yet...)
import { create } from '@storybook/theming/create'
const createThemeFromMUITheme = (name, theme) => {
return create({
base: name,
colorPrimary: theme.palette.primary.main,
colorSecondary: theme.palette.secondary.main,
// UI
appBg: theme.palette.background.default,
appContentBg: theme.palette.background.paper,
appBorderColor: theme.palette.background.paper,
appBorderRadius: theme.shape.borderRadius,
// Typography
fontBase: theme.typography.fontFamily,
fontCode: 'monospace',
// Text colors
textColor: theme.palette.text.primary,
textInverseColor: theme.palette.text.secondary,
// Toolbar default and active colors
barTextColor: theme.palette.text.primary,
barSelectedColor: theme.palette.text.secondary,
barBg: theme.palette.background.default,
brandTitle: 'Add your brand title here',
brandUrl: 'https://yourbrandurl.com',
brandImage: 'https://placehold.it/350x150',
})
}
export default createThemeFromMUITheme

