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
First cut at documentation of project arg/argTypes for discussion #16992
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
```js | ||
// preview.js | ||
|
||
// All stories expect a theme arg | ||
export const argTypes = { theme: { control: { options: ['light', 'dark'] } } }; | ||
|
||
// The default value of the theme arg to all stories | ||
export const args = { theme: 'light' }; | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ Learn how and why to write stories in [the introduction](./introduction.md#using | |
|
||
## Args object | ||
|
||
The `args` object can be defined at the [story](#story-args) and [component level](#component-args). It is a JSON serializable object composed of string keys with matching valid value types that can be passed into a component for your framework. | ||
The `args` object can be defined at the [story](#story-args), [component](#component-args) and [project level](#project-args). It is a JSON serializable object composed of string keys with matching valid value types that can be passed into a component for your framework. | ||
tmeasday marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Story args | ||
|
||
|
@@ -76,6 +76,20 @@ You can also define args at the component level; they will apply to all the comp | |
|
||
<!-- prettier-ignore-end --> | ||
|
||
## Project args | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I personally like the clarity of "project" rather than "global" here, but we currently use the term "global" for parameters and decorators. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes! We changed this internally in 6.4, as it was super confusing to have "global args" and "globals" (which once upon a time were actually called We should transition to using project everywhere I think. What's your recommendation in the meantime? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this PR should use "global". Then we can make another PR to update it to "project" everywhere, possibly only including that change in |
||
|
||
You can also define args at the project level; they will apply to every component's stories unless you overwrite them. To do so, export the `args` key in your `preview.js`: | ||
|
||
<!-- prettier-ignore-start --> | ||
|
||
<CodeSnippets | ||
paths={[ | ||
'react/button-story-project-args-theme.js.mdx', | ||
]} | ||
/> | ||
|
||
<!-- prettier-ignore-end --> | ||
|
||
## Args composition | ||
|
||
You can separate the arguments to a story to compose in other stories. Here's how you can combine args for multiple stories of the same component. | ||
|
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.
Perhaps we should add similar docs for
argTypes
to https://storybook.js.org/docs/react/api/argtypes?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.
@kylegach sounds reasonable to me!
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.
Yeah, I got a bit hung up on the fact that we don't actually document story-level
argTypes
there (I guessargTypes
at the story level generally speaking don't make a heap of sense, although it can be done). But I'll add something.