Adds theming to Storybook (#37562)
This commit is contained in:
parent
22e438d7bd
commit
6897475f9b
@ -50,9 +50,19 @@ const preview: Preview = {
|
|||||||
dynamicTitle: true,
|
dynamicTitle: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
theme: {
|
||||||
|
description: 'Theme for the story',
|
||||||
|
toolbar: {
|
||||||
|
title: 'Theme',
|
||||||
|
icon: 'circlehollow',
|
||||||
|
items: [{ value: 'light' }, { value: 'dark' }],
|
||||||
|
dynamicTitle: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
initialGlobals: {
|
initialGlobals: {
|
||||||
locale: 'en',
|
locale: 'en',
|
||||||
|
theme: 'light',
|
||||||
},
|
},
|
||||||
decorators: [
|
decorators: [
|
||||||
(Story, { parameters, globals, args, argTypes }) => {
|
(Story, { parameters, globals, args, argTypes }) => {
|
||||||
@ -135,6 +145,13 @@ const preview: Preview = {
|
|||||||
</IntlProvider>
|
</IntlProvider>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
(Story, { globals }) => {
|
||||||
|
const theme = (globals.theme as string) || 'light';
|
||||||
|
useEffect(() => {
|
||||||
|
document.body.setAttribute('data-color-scheme', theme);
|
||||||
|
}, [theme]);
|
||||||
|
return <Story />;
|
||||||
|
},
|
||||||
(Story) => (
|
(Story) => (
|
||||||
<MemoryRouter>
|
<MemoryRouter>
|
||||||
<Story />
|
<Story />
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user