-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Addon Docs: dark mode toggle #9301
Comments
I tried to solve it by creating a custom switch in a portal in And than override the background : addDecorator((story, options) => {
const [dark, setDark] = useState(false);
return (
<Fragment>
<Global
styles={css`
.sbdocs-content > div[id^='anchor--'] > div {
background: ${dark ? '#000' : '#fff'} !important;
}
`}
/>
<SwitchDarkMode checked={dark} onChange={() => setDark(!dark)} />
</Fragment>
);
}); With this approach each story has the dark mode but storybook itself stays in the chosen theme. My idea to solve also this part would be like this: addDecorator((story, options) => {
const [dark, setDark] = useState(false);
useEffect(() => {
addParameters({
options: {
theme: dark ? themes.dark : themes.normal,
},
});
}, [dark]);
return (
<Fragment>
<Global
styles={css`
.sbdocs-content > div[id^='anchor--'] > div {
background: ${dark ? '#000' : '#fff'} !important;
}
`}
/>
<SwitchDarkMode checked={dark} onChange={() => setDark(!dark)} />
</Fragment>
);
}); But this is not working. |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook! |
Does this Storybook darkmode addon solve your issue? You can integrate it with your own theme provider or however else you apply the dark mode. |
@connor-baer @angelolucas |
So there's no way to integrate toggle with Docs https://stackoverflow.com/a/67365473/343900 ? Here is an example https://storybook.js.org/addons/storybook-dark-mode 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,
UPDATE_DARK_MODE_EVENT_NAME
} from 'storybook-dark-mode';
const channel = addons.getChannel();
export const parameters = {
darkMode: {
current: 'light',
dark: { ...themes.dark },
light: { ...themes.light }
},
docs: {
container: props => {
const [isDark, setDark] = React.useState();
const onChangeHandler = () => {
channel.emit(UPDATE_DARK_MODE_EVENT_NAME);
};
React.useEffect(() => {
channel.on(DARK_MODE_EVENT_NAME, setDark);
return () => channel.removeListener(DARK_MODE_EVENT_NAME, setDark);
}, [channel, setDark]);
return (
<div>
<input type="checkbox" onChange={onChangeHandler} />
<DocsContainer {...props} />
</div>
);
}
}
}; |
I found solution here hipstersmoothie/storybook-dark-mode#127 (comment) |
Is your feature request related to a problem? Please describe.
While implementing a design system which supports dark mode it's not yet possible to toggle into the dark mode in docs. I added a toggle for each single story which works fine in Canvas but don't work in docs because a story is not an iFrame there.
Describe the solution you'd like
A Quite good example on how this could look like is the Zeit design system
The text was updated successfully, but these errors were encountered: