-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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]: Preview always has a white background #22029
Comments
It’s this issue #21798 |
I think here is the root cause: 9148c66 |
That's an unrelated issue. |
Any updates on this? It doesn't look like it's just a background colour issue on our end, but like the preview ignores the theming entirely: text colour, font, background colour, none of them have any effect on the look of the preview which makes it really difficult to use for an app like ours that only has dark mode |
I‘m using the following workaround (for now): <!-- .storybook/manager-head.html -->
<style>
#storybook-preview-iframe {
background-color: transparent !important;
}
</style> Tested with Maybe this helps someone else too until the issue got addressed. |
The solution we're proposing to this in #24575 is to introduce a new separate theming variable, The PR is released as canary version There's also a StackBlitz that demonstrates how it behaves with/without Let me know what you think @Jasperrr91 @sekeidesign |
I am still experiencing it, I tried many workarounds, downloaded storybook-dark-mode, followed the steps, tweaked a lot of files and nothing... just gonna leave it all white... |
This might help. Gotta say, setting up storybook properly with dark mode take a serious amount of effort to get it right. The useDarkMode hook is no longer usable with the DocsContainer, but i found an alternative. There are also plenty of inconsistencies that are easily fixed, but i assume they would cause backward compatibility issues upstream. If someone is looking for css overrides, let me know. import * as React from 'react';
import {
DocsContainer as BaseContainer,
DocsContainerProps,
} from '@storybook/blocks';
import { addons } from '@storybook/preview-api';
import { themes } from '@storybook/theming';
import { DARK_MODE_EVENT_NAME } from 'storybook-dark-mode';
const channel = addons.getChannel();
export const DocsContainer: React.FC<
React.PropsWithChildren<DocsContainerProps>
> = ({ children, context }) => {
const [isDark, setDark] = React.useState(() => {
const channel = addons.getChannel();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error data is private
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
return (channel.data?.DARK_MODE?.[0] as boolean | undefined) ?? false;
});
const theme = React.useMemo(
() => ({
...(isDark ? themes.dark : themes.light),
fontBase: 'Proxima Nova',
}),
[isDark]
);
React.useEffect(() => {
channel.on(DARK_MODE_EVENT_NAME, setDark);
return () => channel.off(DARK_MODE_EVENT_NAME, setDark);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [channel]);
return (
<BaseContainer
context={context}
theme={theme}
>
{children}
</BaseContainer>
);
}; |
I fixed it by adding appPreviewBg (per the Storybook 7.6 release on appPreviewBg)
|
Describe the bug
Hi there, this recent pull request: #21593 seems to have broken
@storybook/theming
. Looking at the PR description the change was verified with the default backgrounds addon but it looks like@storybook/theming
slipped through. This package is used by many addons to customise the styling, for instance https://www.npmjs.com/package/storybook-dark-mode with 190k weekly downloads.We used to be able to set the Preview background with
appContentBg
. This is then converted totheme.background.content
by: https://github.com/storybookjs/storybook/blob/latest-release/code/lib/theming/src/convert.ts#L117It is then applied to the iFrame wrapper
<div id="storybook-preview-wrapper">
at:https://github.com/storybookjs/storybook/blob/next/code/ui/manager/src/components/preview/utils/components.ts
However, the underlying iFrame
storybook-preview-iframe
now has this newly introducedbackgroundColor: white
which renders the customisedappContentBg
useless:https://github.com/storybookjs/storybook/blob/next/code/ui/manager/src/components/preview/iframe.tsx
I'm not entirely sure about the problem that @JReinhold tried to solve (maybe you could elaborate more Jeppe) but it was desired behaviour to be able to set the background color. Maybe a change caused the
appContentBg
to unexpectedly be overwritten in dark mode. In that case we should probably look over there to solve that bug.Optionally, the
backgroundColor: white
could also be replaced by abackgroundColor: theme.background.content
but this seems like it won't solve your bug as the iFrame wrapper already had that color applied to it.To Reproduce
appContentBg
with@storybook/theming
, for example with storybook-dark-modeSystem
Additional context
No response
The text was updated successfully, but these errors were encountered: