Skip to content

Commit 239c4cc

Browse files
authored
React Storybook - fix theme change (#32270)
1 parent f3e38d7 commit 239c4cc

File tree

1 file changed

+33
-16
lines changed

1 file changed

+33
-16
lines changed

apps/react-storybook/.storybook/themes/themes.tsx

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ export const themeToolbarItems = [
1111
{ title: 'Generic Dark Violet', value: 'darkviolet' },
1212
{ title: 'Generic Green Mist', value: 'greenmist' },
1313
{ title: 'Generic Contrast', value: 'contrast' },
14-
{ title: 'Material Blue Light', value: 'material.blue.light' },
15-
{ title: 'Material Blue Dark', value: 'material.blue.dark' },
16-
{ title: 'Material Lime Light', value: 'material.lime.light' },
17-
{ title: 'Material Lime Dark', value: 'material.lime.dark' },
18-
{ title: 'Material Orange Light', value: 'material.orange.light' },
19-
{ title: 'Material Orange Dark', value: 'material.orange.dark' },
20-
{ title: 'Material Purple Light', value: 'material.purple.light' },
21-
{ title: 'Material Purple Dark', value: 'material.purple.dark' },
22-
{ title: 'Material Teal Light', value: 'material.teal.light' },
23-
{ title: 'Material Teal Dark', value: 'material.teal.dark' },
24-
{ title: 'Fluent Blue Light', value: 'fluent.blue.light' },
25-
{ title: 'Fluent Blue Dark', value: 'fluent.blue.dark' },
26-
{ title: 'Fluent Saas Light', value: 'fluent.saas.light' },
27-
{ title: 'Fluent Saas Dark', value: 'fluent.saas.dark' },
14+
{ title: 'Material Blue Light', value: 'material-blue-light' },
15+
{ title: 'Material Blue Dark', value: 'material-blue-dark' },
16+
{ title: 'Material Lime Light', value: 'material-lime-light' },
17+
{ title: 'Material Lime Dark', value: 'material-lime-dark' },
18+
{ title: 'Material Orange Light', value: 'material-orange-light' },
19+
{ title: 'Material Orange Dark', value: 'material-orange-dark' },
20+
{ title: 'Material Purple Light', value: 'material-purple-light' },
21+
{ title: 'Material Purple Dark', value: 'material-purple-dark' },
22+
{ title: 'Material Teal Light', value: 'material-teal-light' },
23+
{ title: 'Material Teal Dark', value: 'material-teal-dark' },
24+
{ title: 'Fluent Blue Light', value: 'fluent-blue-light' },
25+
{ title: 'Fluent Blue Dark', value: 'fluent-blue-dark' },
26+
{ title: 'Fluent Saas Light', value: 'fluent-saas-light' },
27+
{ title: 'Fluent Saas Dark', value: 'fluent-saas-dark' },
2828
];
2929

3030
export const compact = [
@@ -33,9 +33,26 @@ export const compact = [
3333
]
3434

3535
export const ThemeDecorator: Decorator = (Story, ctx) => {
36-
const { theme, compact } = ctx.globals;
36+
const { theme: rawTheme, compact } = ctx.globals;
37+
const theme = rawTheme.replaceAll('-', '.');
38+
39+
const [prevTheme, setPrevTheme] = React.useState<string | null>(null);
40+
const [prevCompact, setPrevCompact] = React.useState<boolean | null>(null);
41+
42+
React.useEffect(() => {
43+
if (prevTheme !== null && prevCompact !== null) {
44+
if (prevTheme !== rawTheme || prevCompact !== compact) {
45+
window.location.reload();
46+
}
47+
}
48+
49+
setPrevTheme(rawTheme);
50+
setPrevCompact(compact);
51+
}, [rawTheme, compact]);
52+
3753
const themeName = theme.split('.').length < 3 ? 'generic' : theme.split('.')[0];
38-
const cssFileHref = `css/dx.${theme}${compact ? '.compact' : ''}.css`
54+
const cssFileHref = `css/dx.${theme}${compact ? '.compact' : ''}.css`;
55+
3956
return (
4057
<div className={`dx-theme-${themeName}-typography storybook-theme-decorator`}>
4158
<link rel="stylesheet" href={cssFileHref} />

0 commit comments

Comments
 (0)