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

Core: Hoist 'control.options', validate them in core and introduce 'control.labels' #14169

Merged
merged 12 commits into from
Mar 9, 2021

Conversation

ghengeveld
Copy link
Member

Issue: #13888

What I did

This gracefully replaces control.options with top-level options on argTypes. Top-level options are validated by the story store rather than the Controls addon. Contrary to control.options, options only accepts an array of primitives. Labels can be customized using control.labels.

argTypes: {
  foo: {
    options: [true, false, 42],
    control: {
      type: 'select',
      labels: {
        true: 'Yes',
        false: 'No'
      }
    }
  }
}

How to test

  • Is this testable with Jest or Chromatic screenshots? No
  • Does this need a new example in the kitchen sink apps? No
  • Does this need an update to the documentation? Yes

If your answer is yes to any of these, please make sure to include it in your PR.

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fantastic. We need to update the controls documentation also!

lib/client-api/src/args.ts Outdated Show resolved Hide resolved
Copy link
Member

@tmeasday tmeasday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great @ghengeveld

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me, modulo a few minor suggestions.

I'm also wondering whether we should have a link from the controls docs back into MIGRATION.md for existing controls users who read the updated docs and are confused?

@jonniebigodes can you take a look?

docs/essentials/controls.md Show resolved Hide resolved
validator: (obj: any) => Array.isArray(obj),
control: {
type: 'object',
validator: (obj: any) => Array.isArray(obj),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is validator documented?

Copy link
Member Author

@ghengeveld ghengeveld Mar 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you didn't document it when you added it.

I think this isn't used anymore, I think I removed it when we introduced the JSON editor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL almost zero memory of this 😭

Per our slack discussion, let's get rid of validators and also use the JSON editor UI for ALL arrays moving forward

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great!

@jonniebigodes
Copy link
Contributor

@shilman just did and it looks fantastic. I'm good with it.

@shilman shilman merged commit c398bc5 into next Mar 9, 2021
@shilman shilman deleted the options-labels branch March 9, 2021 22:04
This was referenced Mar 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants