-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
CSF: Allow overridding globals at the story level #26654
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 49d0155. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! We might want to do the other addons in a separate PR or separate PRs to scrutinize each one a little more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fwiw, I'm good with the globalOverrides
name. It's perhaps a bit clunky, relative to globals
, but I think it's necessary to communicate that the behavior is different.
@tmeasday — Should this PR contain docs?
6539f37
to
3e29715
Compare
Co-authored-by: Michael Shilman <[email protected]>
Co-authored-by: Valentin Palkovic <[email protected]>
3e29715
to
5356849
Compare
This means we don't need to do any complex checks in addon toolbars to tell if it should be disabled
What are the implications on the docs page? Currently, it seems that globally set globals via the toolbar either don’t have an effect, are invisible in doc mode, or are applied to all stories simultaneously. Is it considered to apply story-specific globals also on the docs page (especially for autodocs)? How do we/addon authors communicate if particular globals only apply in the story view and not in the docs view? |
If a story sets
I think generally speaking globals do apply in docs view. It would only be specific addons (the one I am thinking of is viewports) that do things in the manager that don't "work" in docs mode. |
…emes to template stories, and to main storybook.
CSF: Add addon-themes for testing to sandboxes & main storybook
…kjs/storybook into tom/23347-story-globals
Closes: #23347 #27709 #27524 #27523
What I did
userGlobals
andstoryGlobals
are separate in state.userGlobals
are globals set via toolbars/addons etc. These are dynamic and change-able.userGlobals
are initialized usinginitialGlobals
.storyGlobals
are set via a.globals
property on themeta
orstory
inside*.stories.*
files.storyGlobals
are fixed in place, and cannot be changed.initialGlobals
is introduced as a concept.preview.*
file. Addons can set them too.initialGlobals
are used to determine if a global's value should appear in the URL or not.globals
is still available and results from shallow-merginguserGlobals
andstoryGlobals
.useGlobals
hook now return a third value:storyGlobals
.storyGlobals
.MIGRATION.md
).MIGRATION.md
).disable
, allowing the disabling of the tool per story.Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
localhost:6006/?path=/story/lib-preview-api-globals--overrides
to see basicslocalhost:6006/?path=/story/addons-toolbars-globals--override
to see toolbar behaviourstorybook/MIGRATION.md
Lines 429 to 463 in 6141b5b
preview.ts
and change the default value. example: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-26654-sha-49d01553
. Try it out in a new sandbox by runningnpx [email protected] sandbox
or in an existing project withnpx [email protected] upgrade
.More information
0.0.0-pr-26654-sha-49d01553
tom/23347-story-globals
49d01553
1722599196
)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=26654