Skip to content

Commit c60d7e0

Browse files
committed
Add support to switch light/dark for storybook manager layout
1 parent 6a714e2 commit c60d7e0

1 file changed

Lines changed: 38 additions & 8 deletions

File tree

packages/oxygen-ui-docs/.storybook/manager.js

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,43 @@
2020
import { addons } from 'storybook/internal/manager-api';
2121
import { themes } from 'storybook/internal/theming';
2222

23-
addons.setConfig({
24-
theme: {
25-
...themes.dark,
26-
appBg: '#000000',
27-
barBg: '#000000',
28-
brandTitle: 'WSO2 Oxygen UI',
29-
brandUrl: 'https://github.com/wso2/oxygen-ui',
30-
brandImage: './oxygen-ui-react-logo-inverted.svg'
23+
const getThemeMode = () => {
24+
return localStorage.getItem('mui-mode') === 'light' ? 'light' : 'dark';
25+
};
26+
27+
const applyTheme = (mode) => {
28+
addons.setConfig({
29+
theme: {
30+
...(mode === 'light' ? themes.light : themes.dark),
31+
appBg: (mode === 'light' ? '#ffffff' : '#000000'),
32+
barBg: (mode === 'light' ? '#f0f0f0' : '#000000'),
33+
brandTitle: 'WSO2 Oxygen UI',
34+
brandUrl: 'https://github.com/wso2/oxygen-ui',
35+
brandImage: (mode === 'light' ? './oxygen-ui-react-logo.svg' : './oxygen-ui-react-logo-inverted.svg')
36+
}
37+
});
38+
};
39+
40+
// Apply initial theme
41+
let currentMode = getThemeMode();
42+
applyTheme(currentMode);
43+
44+
// Poll for changes in localStorage (checks every 500ms)
45+
setInterval(() => {
46+
const newMode = getThemeMode();
47+
if (newMode !== currentMode) {
48+
currentMode = newMode;
49+
applyTheme(currentMode);
50+
}
51+
}, 500);
52+
53+
// Also listen for storage events (works across tabs)
54+
window.addEventListener('storage', (e) => {
55+
if (e.key === 'mui-mode') {
56+
const newMode = getThemeMode();
57+
if (newMode !== currentMode) {
58+
currentMode = newMode;
59+
applyTheme(currentMode);
60+
}
3161
}
3262
});

0 commit comments

Comments
 (0)