Skip to content
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

Addon-controls: Handle no-args stories gracefully. #10976

Closed
3 tasks
shilman opened this issue May 29, 2020 · 17 comments
Closed
3 tasks

Addon-controls: Handle no-args stories gracefully. #10976

shilman opened this issue May 29, 2020 · 17 comments

Comments

@shilman
Copy link
Member

shilman commented May 29, 2020

Why

Currently, no-args stories offer a poor experience in addon-controls. We disable the controls because the story is not making use of the args anyway, so nothing would happen if they were available to the user. Unfortunately, ALL pre-6.0 stories are no-args stories, so this is a bad out-of-box experience for users who are upgrading from an older storybook:

Addons___A11y___BaseButton_-_Default_⋅_Storybook

What

We should provide a better UI in this case:

  • Explain why there are no controls in a mouseover?
  • Show the expanded version of the table (type / defaultValue / description) even if the addon is in collapsed mode
  • Other ideas?
@matheo
Copy link
Member

matheo commented May 29, 2020

A visible warning in the ControlsPanel is the ideal one,
but I guess that the StoryFn is not accessible there right?

IMO showing the controls by default makes you realize that you need to process them in the Story to make something happen, or if you don't want them then you proceed to disable the tab for the Story with controls: { disable: true } :)

@domyen
Copy link
Member

domyen commented May 29, 2020

Good point @shilman.

Strawman:

  • When there are no controls for a component, show a yellow warning bar above the props table that says "No controls found for this component. Learn how to add controls »"
  • Link to docs for controls

Notes:

  • If there is 1+ controls don't show the yellow bar

Show the expanded version of the table (type / defaultValue / description) even if the addon is in collapsed mode

I don't have much context on this. Can we switch between props table with and without controls?

@shilman
Copy link
Member Author

shilman commented May 29, 2020

@domyen Yes, the controls data is handled separately from the props table data, so when there is a no-args story function, we still have everything we need to show a standard 5.3-style props table if we wanted. I'll put together a quick POC for your suggestion and we can iterate from there. Thanks!

@shilman shilman self-assigned this May 29, 2020
@shilman
Copy link
Member Author

shilman commented May 29, 2020

Here's the POC in "compact" mode:

Addons___A11y___BaseButton_-_Default_⋅_Storybook

Here's the POC in "expanded" mode:

Addons___A11y___BaseButton_-_Default_⋅_Storybook

The user can toggle between the two modes using the controls.expanded parameter. However, my proposal is to always show the panel in expanded mode when there are no controls, just to make the thing more useful out of the box. WDYT?

@shilman
Copy link
Member Author

shilman commented May 29, 2020

@domyen @matheo Added the warning per @domyen 's design and created a PR at #10986

@matheo
Copy link
Member

matheo commented May 29, 2020

Looks really good!

@matheo
Copy link
Member

matheo commented May 29, 2020

perhaps, another way to say it, is that the Story is not configured to handle control args, and that's why there are no controls inferred. So another warning message could be:

This story is not configured to handle controls

@shilman
Copy link
Member Author

shilman commented May 29, 2020

Missed your comment but will tweak it for the next release. Good call

@shilman
Copy link
Member Author

shilman commented May 29, 2020

¡Ay Caramba!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.0.0-beta.19 containing PR #10986 that references this issue. Upgrade today to try it out!

You can find this prerelease on the @next NPM tag.

Closing this issue. Please re-open if you think there's still more to do.

@shilman shilman closed this as completed May 29, 2020
@jayarjo
Copy link

jayarjo commented Jun 29, 2020

@matheo how do you disable control for a given arg? Lets say I don't want to have control auto-generated for the Function type.

@matheo
Copy link
Member

matheo commented Jun 29, 2020

@jayarjo right now I don't see a way to remove rows

@shilman maybe do you know if this is possible?
or a new hidden property to be filtered by?

@jayarjo
Copy link

jayarjo commented Jun 29, 2020

@matheo not that I want to remove the whole row, I'd actually prefer for the name of the prop and its type and description to stay - just to hide the control for the given arg row.

@matheo
Copy link
Member

matheo commented Jun 29, 2020

@jayarjo you can try:

argTypes: {
  fieldName: {
    control: { type: null }
  },
}

@jayarjo
Copy link

jayarjo commented Jun 29, 2020

@matheo talking about argTypes - can't find a way to reference them in .mdx doc, is there one?

@matheo
Copy link
Member

matheo commented Jun 29, 2020

I found this one:

<Meta title="Button" args={{ a: 1, b: 2 }} argTypes={{ a: { name: 'A' }, b: { name: 'B' } }} />

in this PR

@jayarjo
Copy link

jayarjo commented Jun 30, 2020

@matheo wow, it works! Not sure how 'cause I was looking for it in type definition of the Meta and it definitely wasn't there. But huge thanks to you personally for the hint!

@matheo
Copy link
Member

matheo commented Jul 2, 2020

@jayarjo the latest v6.0.0 beta included a way to disable it ;)
#11388

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants