-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Storybook v7: dark mode is not applied anymore on the story main body #235
Comments
As a workaround, you can hack that on your a main story decorator like that: diff --git a/.storybook/components/StoryDecorator.tsx b/.storybook/components/StoryDecorator.tsx
index e801979..7ac380c 100644
--- a/.storybook/components/StoryDecorator.tsx
+++ b/.storybook/components/StoryDecorator.tsx
@@ -7,6 +7,9 @@ import React, {
import {
DecoratorFn,
} from '@storybook/react';
+import {
+ themes,
+} from '@storybook/theming';
import {
useDarkMode,
} from 'storybook-dark-mode';
@@ -45,6 +48,11 @@ export const StoryDecorator: DecoratorFn = (Story: any, {
}) => {
const dark = useDarkMode();
+ useEffect(() => {
+ const backgroundColor = dark ? themes.dark.appBg : themes.light.appBg;
+ document.body.style.backgroundColor = backgroundColor || 'inherit';
+ }, [dark]);
+
return (
<React.StrictMode>
<Suspense fallback="loading..."> Also ensure it is configured globally: // .storybook/preview.ts
export const decorators: DecoratorFn[] = [
StoryDecorator,
]; |
Experiencing the same issue, although the plugin for me applies the desired background color on the |
Alright, I figured out what's going on. For the full rundown check out: storybookjs/storybook#22029 |
I notice this on the overview page (i.e. mdx files). The class is not added to the body in the iframe. |
Once this is settled it should be fixed storybookjs/storybook#21798 |
Anything we can do here? |
maybe this will help |
The problem is very simple to solve. Inside .storybook > preview.ts, add the following excerpt, inside parameters:
For documentation/.mdx type files, use the configuration below:
The code should look like this:
|
Summary
Since v7, switching to dark mode does not have any effect to the preview body anymore:
Screenshot
Only the Storybook UI theme is changed.
Apparently, this plugin update the style of the
#storybook-preview-wrapper
DOM element, wrapping theiframe
However, since v7, the background color seems to be defined directly on the
body.sb-show-main
DOM element of the previewiframe
, resulting of an overriding of the storybook-dark-mode setting appliance.The text was updated successfully, but these errors were encountered: