-
-
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
Core: Add args feature #10014
Merged
Merged
Core: Add args feature #10014
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tmeasday
requested review from
shilman,
theinterned,
thomasbertet and
usulpro
as code owners
March 2, 2020 12:08
wKich
reviewed
Mar 3, 2020
Co-Authored-By: Dmitriy Lazarev <w@kich.dev>
shilman
approved these changes
Mar 4, 2020
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.
Looks great aside from a few naming issues!
Thanks @shilman! Co-Authored-By: Michael Shilman <shilman@users.noreply.github.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue: #9811
What I did
Added a new feature to stories called "args"
The idea of this feature is to allow addons to control rendering of stories via "inputs" (and capture "outputs"). Args are initialized by type inference (when available, eg. from TypeScript in your stories, or PropTypes on your components), or by user configuration (via
parameters
) and can be controlled in various ways in the Storybook UI.Args map to the rows in the props table in docs mode.
Basic DX of using args:
More info:
Naming
There has been a bit of back and forth on names and I thought it was useful to outline why we settled on "args" in this PR.
We wanted to capture the idea of "arguments to the story function". It is worth considering that in different frameworks there can be different "categories" of arguments of your component.
So, although we considered "inputs" it felt like it only captured one side of the picture.
"Properties" seemed a bit long, and "props" seemed a bit React-specific.
Another option considered was "controls" but that seemed too specific to the use case of wanting to change the value of these things via a UI element, which isn't the whole story here.
Sub features.
There are a few things in this PR that enable follow on features built using args:
Parameter enhancers -- allow an addon to generate parameters for a story at runtime. This allows complex configuration of arg "types" to be built up from the component type definitions, amongst other things
parameters.passArgsFirst
-- a new setting (currently defaulting tofalse
, although that may change in 6.0 based on feedback), which means args are seperated from the larger story context and passed first into stories.useArgs()
-- a simple hooks API available on client and server for addons to read and set arg values.