-
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
Docs is always in light mode #180
Comments
Trying to upgrade storybook on our repo (https://github.com/traefik/faency), which is publicly accessible here: https://traefik.github.io/faency/ I notice the following:
|
Here is a workaround by editing your preview.js import React from 'react';
import addons from '@storybook/addons';
import { DocsContainer } from '@storybook/addon-docs';
import { themes } from '@storybook/theming';
import { DARK_MODE_EVENT_NAME } from 'storybook-dark-mode';
const channel = addons.getChannel();
export const parameters = {
darkMode: {
dark: { ...themes.dark },
light: { ...themes.light },
},
docs: {
container: props => {
const [isDark, setDark] = React.useState();
React.useEffect(() => {
channel.on(DARK_MODE_EVENT_NAME, setDark);
return () => channel.off(DARK_MODE_EVENT_NAME, setDark);
}, [channel, setDark]);
+ const { id: storyId, storyById } = props.context;
+ const {
+ parameters: { docs = {} },
+ } = storyById(storyId);
+ docs.theme = isDark ? themes.dark : themes.light;
return (
<DocsContainer {...props} />
);
},
},
}; |
For anyone struggling with this, this is what worked best for me (building upon the answer by @frassinier): import React from 'react';
import { DocsContainer } from '@storybook/addon-docs';
import { themes } from '@storybook/theming';
import { useDarkMode } from 'storybook-dark-mode'
export const parameters = {
docs: {
container: (props) => {
const isDark = useDarkMode();
const { id: storyId, storyById } = props.context;
const {
parameters: { docs = {} },
} = storyById(storyId);
docs.theme = isDark ? themes.dark : themes.light;
return React.createElement(DocsContainer, props);
},
},
};
|
Thank you very much @TUTAMKHAMON It seems to me that in version 7 api has changed a bit.
|
Also addon addon-docs adds styles for "preview-loading". Because of what in the dark theme - there are white loading screens. I didn't find a better solution than to override styles like this:
|
At least for storybook 7, I think I've managed to partially track down the issue to the |
This worked for me thank you ! |
The workaround above doesn't completely work for me. I'm on Kinda hard to believe that an official addon doesn't support a basic feature like this. |
It’s not an official addon, and we’re working hard with the storybook team to find a solution. storybookjs/storybook#21798 The number of breaking changes in v7 are extremely high and it’s been very difficult for addon authors to properly migrate because some functionality disappeared without a replacement. |
I phrased that wrong. I'm not trying to blame you. On the contrary, it's a great addon! What I meant is that If you need any information from me to test solutions for this problem just let me know! |
@pgr3931 can you try in 7.0.7 or later? If you are still seeing a problem can you let me know? |
I've upgraded today, sorry to tell you still issues :( |
Can you give a bit more detail @joshuaellis? Ideally with a reproduction I can look at that demonstrates a regression in the addon from 6.5 -> 7.0? |
I was able to get everything working as expected with 7.0.8. Make sure you run If you had any custom styling in I also added some code in |
So is there anything to fix here? Will happily merge PRs if there is! |
For everyone having issues with the first render not applying the theme, this approach worked great for me while using the
|
The workarounds here seem to be for react - can anyone point me in the right direction for getting them to work with Svelte? |
#180 (comment) Works. README should be updated! |
@d9k wanna make a PR? |
Since storybook 8.1.11, it seems the method with |
Created ticket in storybook: storybookjs/storybook#28758 |
All docs as rendered by
addon-docs
, an official essentials-addon mind you, are always in light mode. No specific configuration has been added to colour anything - it just renders in light mode no matter what.The text was updated successfully, but these errors were encountered: