-
-
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
[Bug]: themes.normal not working for docs pages #28664
Comments
Hello bot. I tried what you suggested and it just caused the following error when viewing the page: "Passed an incorrect argument to a color function, please pass a string representation of a color." |
Hi @jackocnr ! From what I see in the code, In the meantime, here's a workaround you can use: // Copied from https://github.com/storybookjs/storybook/blob/v8.2.5/code/core/src/theming/utils.ts
const { window: globalWindow } = global;
export const getPreferredColorScheme = () => {
if (!globalWindow || !globalWindow.matchMedia) return 'light';
const isDarkThemePreferred = globalWindow.matchMedia('(prefers-color-scheme: dark)').matches;
if (isDarkThemePreferred) return 'dark';
return 'light';
};
// In your preview.js
const preview = {
parameters: {
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
docs: {
theme: themes[getPreferredColorScheme()],
},
},
}; |
That worked a charm, thanks so much for the quick reply @elisezhg 💐 |
@kylegach This is a documentation issue in Chan's video. AFAIK |
Was just about to mention that Chan's video is explictly mentioning the @shilman I think that as long as the developers get access to the Another problem that this would solve is to create a custom theme that responses to the browser's theme pref (e.g different logo according to the browser pref). |
Describe the bug
I have a hosted storybook site which only shows docs pages, and I want the whole site (sidebar, preview etc) to all respect the user's system settings for light/dark mode.
On the Storybook Theming page, there is a video which states that you can use
themes.normal
(from @storybook/theming package) in your custom theme to respect the user's system setting for light/dark mode. This works fine in my custom theme (in manager.js), but not for my docs pages content.From that same Theming page: it says you can theme docs pages by putting the following in preview.js:
This works fine, but I want to respect the user's system settings, so I try using
themes.normal
again, this time it doesn't work - it just always shows the light theme. You can see this in action here: https://intl-tel-input.com/storybookIs there a way to get the docs preview panel to respect the user's system settings?
I found two relevant addons:
https://storybook.js.org/addons/storybook-dark-mode
https://storybook.js.org/addons/@storybook/addon-themes
But they both seem to be concerned with giving the user the ability to manually toggle the theme, which is not what I want - I just want it to automatically respect the user's system settings.
Reproduction link
https://stackblitz.com/edit/github-ctbu1e?file=.storybook%2Fpreview.js
Reproduction steps
Put the following in your preview.js:
I expected this to respect the user's system setting for light/dark mode, but it just always used light mode.
System
Additional context
No response
The text was updated successfully, but these errors were encountered: