-
-
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
Theming: Add theme variable to set the preview background color #24575
Theming: Add theme variable to set the preview background color #24575
Conversation
@yannbf I've changed the loader to now also have the preview background. This doesn't eliminate the flash of white entirely unfortunately. The flow is this:
So if you set
In this video I'm demonstrating loading a story a few times, then loading docs, and finally I "slow it down" by enabling the debugger to pause at each step outlined above. Export-1698270790261.mp4I think this is the best we can do right now, and it's an improvement over what we have. |
I think this needs some eyes from @MichaelArestad and @cdedreuille |
The solution seems good to me as a quick fix for now but this highlight how crucial it it for us to simplify how to manage theming. If we move away from using JS to set colors, then you would never have any flashing problems. I really hope we can bring the Theming 2.0 project to Storybook 8.0 #24344 Regarding naming, I'm not 100% convinced that people will understand the difference between |
I agree the naming is not perfect, because now |
Closes #22029
What I did
This PR introduces a new theming variable,
appPreviewBg
to explicitly set the preview background color. This was previously possible withappContentBg
in 6.5, but that was problematic as documented in #21080.We generally recommend setting explicit backgrounds in the rendered stories directly (eg. with a decorator in
preview.ts
), but doing this directly in the manager is now also possible withappPreviewBg
.an open question is whether or not the "loading preview" element should have the same preview background or maintain the current app background. in dark mode, the current app background is dark so the loading screen will be dark for a short period of time before going white. if we changed it to match, it would be white all the time.
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
See this demonstrated in different scenarios in this sandbox: https://stackblitz.com/edit/github-u7boko?file=.storybook%2Fpreview.ts
@storybook/addon-themes
has been added to demonstrate that any background set using that addon will still override whatever background set in the manager with the theme variable. Story/preview level styles should always override manager styles. You need to disable this addon to experience the next two scenarios.storybook-dark-mode
has been added to demonstrate that it still works to set manager backgrounds from addons, if the user specifies the new theme variable in the parameters (as documented by the addon). You need to disable this addon to experience the next scenarioaddons.setConfig
API. (Changing this requires restarting the SB server)Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal
,ci:merged
orci:daily
GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli/src/sandbox-templates.ts
Make sure this PR contains one of the labels below:
Available labels
bug
: Internal changes that fixes incorrect behavior.maintenance
: User-facing maintenance tasks.dependencies
: Upgrading (sometimes downgrading) dependencies.build
: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup
: Minor cleanup style change. Will not show up in release changelog.documentation
: Documentation only changes. Will not show up in release changelog.feature request
: Introducing a new feature.BREAKING CHANGE
: Changes that break compatibility in some way with current major version.other
: Changes that don't fit in the above categories.🦋 Canary release
This pull request has been released as version
0.0.0-pr-24575-sha-94eee1ff
. Install it by pinning all your Storybook dependencies to that version.More information
0.0.0-pr-24575-sha-94eee1ff
22029-bug-preview-always-has-a-white-background
94eee1ff
1698270371
)To request a new release of this pull request, mention the
@storybookjs/core
team.core team members can create a new canary release here or locally with
gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=24575