Skip to content

Commit

Permalink
docs: set Storybook dark mode correctly when switching VitePress theme (
Browse files Browse the repository at this point in the history
#234)

The embedded Storybook component docs did not correctly switch to dark
mode when the theme is toggled in VitePress.
  • Loading branch information
larsrickert authored Feb 1, 2024
1 parent 01efe4c commit 92c2f96
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/storybook-utils/src/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ export const createPreview = <T extends Preview = Preview>(overrides?: T) => {
const isDark = themeParam
? themeParam === "dark"
: parent.document.body.classList.contains("dark");

if (isDark) {
document.body.classList.remove("light");
document.body.classList.add("dark");
} else {
document.body.classList.remove("dark");
document.body.classList.add("light");
}

return isDark ? themes.dark : themes.light;
},
source: {
Expand Down

0 comments on commit 92c2f96

Please sign in to comment.