-
-
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
Docs: Add ArgTypes API reference #22970
Conversation
|
||
Specifies the type of control used to change the arg value with the [controls addon](../essentials/controls.md). Here are the available types, `ControlType`, grouped by the type of data they handle: | ||
|
||
| Data type | ControlType | Description | |
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 the same table as in the old argtypes.md
, organized more sensibly.
docs/api/arg-types.md
Outdated
|
||
Default: [Inferred](#automatic-argtype-inference) | ||
|
||
TK <!-- TODO: Not sure how this differs from `table.type.summary` --> |
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.
Highlighting this TODO, for which I need an answer, please.
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.
TLDR: The type
field is semantic and the table.type.summary
is what's shown in the UI.
It's a little convoluted and I hope we can streamline this in 8.0.
- The component is analyzed using some kind of docgen (
react-docgen
/compodoc
/etc.) All of these tools have different formats. - Those all get summarized in the
type
field. Users can also specify thetype
field themselves, in case docgen got it wrong, or there is no docgen for your particular framework/renderer. - Storybook uses the
type
field to auto-generate thecontrol
field (which can also be manually overwritten/refined) - Storybook also uses the
type
field to autogenerate thetable.type.summary/details
fields for display (which can also be manually overwritten/refined)
There are two ways of specifying type:
// longhand
export default {
argTypes: {
foo: { type: { name: 'number' } },
}
}
// shorthand
export default {
argTypes: {
foo: { type: 'number' },
}
}
Why not just use the shorthand? Well, there is some support for structured types like Object/Array. This was overengineered in retrospect since we don't take advantage of that data yet. We will in the future, but I don't know when. If I could turn back time, I would just use the shorthand.
Also worth noting that we're planning on introducing an even shorter shorthand in 7.2 which will look like:
export default {
argTypes: {
foo: 'number',
bar: 'action', // <= this is new
}
}
We'll probably create an RFC for this change. The rationale behind it is a bit complex but it has to do with performance, story portability, etc. (making it easier to not have to run docgen at all in some cases). Should not affect the current docs, but just wanted to give the full picture that this will be changing soon.
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.
Why not just use the shorthand? Well, there is some support for structured types like Object/Array. This was overengineered in retrospect since we don't take advantage of that data yet. We will in the future, but I don't know when. If I could turn back time, I would just use the shorthand.
I agree with you @shilman for a long time it was confusing for me, I thought it is a new API. I think we need to normalize and simplify the API, and it should be always an option to override values.
Another important point @shilman, should we separate the docgen plugins, right you are kind of normalizing react and vue, the caveat here is not all renderers have the same architecture
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.
Thank you for the detailed answer! 👏
Updates pushed in 55bfceb.
3d4a32c
to
c237479
Compare
Hi @kylegach is this just for react or agnostic ? |
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 PR is important for me. we may be depending on each other, with my last 2 PRs that deal with ArgTypes even if it is just docs
@chakAs3 —
It's intended to be agnostic. The |
@chakAs3 —
Thanks for the heads up and your review! If you link them here, I'm happy to take a look to confirm whether we need to be concerned about any overlap. |
c237479
to
d4dfbd6
Compare
Hi @kylegach this is the PR #22912, |
@chakAs3 — Interesting! Looks like all that will be necessary docs-wise is a new row in the table of allowable control types. Thanks! |
Yes, it is union control, so now you switch between allowable controls, I pick the one you want in case you have an Arg of type union ( number | string | boolean | ....) may be we need to limit the number or come up with a layout that can accommodate numerous controls. |
d4dfbd6
to
55bfceb
Compare
- Remove previous ArgTypes guide - Add/update relevant snippets
- Remove now-empty Stories sub-section
55bfceb
to
9e44678
Compare
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.
Thanks for addressing the feedback so promptly. Appreciate it. I'm good with it.
docs/api/arg-types.md
Outdated
type?: { summary?: string; detail?: string }; | ||
}, | ||
type?: SBType | SBScalarType['name']; | ||
defaultValue?: any; |
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.
As the defaultValue
is deprecated, probably not a bad idea to reference it as such and point directly to the section or remove it. WDYT?
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.
Thanks for addressing the feedback so promptly. Appreciate it. All good on my end
Docs: Add ArgTypes API reference (cherry picked from commit e39cc9f)
Docs: Add ArgTypes API reference (cherry picked from commit e39cc9f)
Docs: Add ArgTypes API reference (cherry picked from commit e39cc9f)
Docs: Add ArgTypes API reference (cherry picked from commit e39cc9f)
Docs: Add ArgTypes API reference (cherry picked from commit e39cc9f)
Docs: Add ArgTypes API reference (cherry picked from commit e39cc9f)
Docs: Add ArgTypes API reference (cherry picked from commit e39cc9f)
Docs: Add ArgTypes API reference (cherry picked from commit e39cc9f)
Docs: Add ArgTypes API reference (cherry picked from commit e39cc9f)
Docs: Add ArgTypes API reference (cherry picked from commit e39cc9f)
Docs: Add ArgTypes API reference (cherry picked from commit e39cc9f)
Docs: Add ArgTypes API reference (cherry picked from commit e39cc9f)
Docs: Add ArgTypes API reference (cherry picked from commit e39cc9f)
Docs: Add ArgTypes API reference (cherry picked from commit e39cc9f)
Docs: Add ArgTypes API reference (cherry picked from commit e39cc9f)
Closes #17681
What I did
How to test
api-reference-arg-types
a. Completeness
- Is every property documented fully?
b. Correctness
- Types
- Required or not
- Default values
- Descriptions
- Example snippets
c. Consistency in structure
Checklist
MIGRATION.MD
Maintainers
make sure to add the
ci:merged
orci:daily
GH label to it.["cleanup", "BREAKING CHANGE", "feature request", "bug", "documentation", "maintenance", "dependencies", "other"]