-
-
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
Controls: Add conditional controls #17536
Conversation
☁️ Nx Cloud ReportCI ran the following commands for commit 1a37df7. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this branch ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
Other cases:
|
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.
Nice stuff! I wonder about the relation from this change to
https://storybook.js.org/docs/react/essentials/controls#filtering-controls and if we need to differentiate them to avoid confusion. The controls.include|exclude
was introduced to make table.disable
simpler and allow for regex based exclusion (though I believe it wouldn't affect the argstable in docs so that's one key difference)
Maybe we should rename the new ones to like allow/reject, add/remove, keep/?
Hey @tmeasday just to verify, the snapshots are failing because the |
I think that sounds right, what do you think? Can't think of any reason you'd want one. |
Nah it was just to double check before removing the code! |
What about including/excluding when another arg is a certain value, e.g. only render API idea: argTypes: {
appearance: {
options: ['primary', 'outline'],
},
color: { includeIf: ['appearance', 'primary'] } // enable when appearance = 'primary'
} |
@yannbf I'm not happy about the API for hiding controls. Currently there are two ways to do this:
@tmeasday and I had discussed a Some options:
Another option would be to move all this under TLDR: I feel the current naming is inconsistent and it would be nice to agree on some conventions here since we're going to have to live with this for years. |
I'm fine with option 2 and would be happy to write a codemod for it. There's also another option: use both the concept of exclude/include and hide/show, both doing what they semantically mean. I'm not sure if there is a use case for this, but just want to throw it out there for us to consider: With targetedArgs one might also want to tweak it in the UI. For example an addon that requires 5 args but the user only wants to allow changing one. In that case hide/show or enabled:true|false would be needed in argTypes. I guess things might get more convoluted and we might need to have the "if" variants for show, hide, include, exclude, enable, disable. Maybe another spin to this is to change the api to become more flexible like: {
conditional: {
condition: "foo",
not: true,
type: "hide" // or show, exclude, include, enable, disable
}
} |
Hi, it would be great to have this feature. Great work so far, and to be honest, I would manage to work with any of the patterns proposed. Perhaps I'm late to suggest another option, but worth sharing, just in case. Disclaimer, I have no understanding whatsoever of how storybook's wiring. The pattern is basically out of https://github.com/pmndrs/leva. Essentially, each key could have a It can be used for
Cheers |
That's a much better API for non-boolean cases than the one I proposed. 👍 |
@a7sc11u @kylegach unfortunately functions are currently problematic in storybook since (1) they need to be serialized over the channel, (2) they are impossible for ecosystem tools to statically analyze, so that's why we're using an awkward declarative format. |
title: 'Button', | ||
argTypes: { | ||
label: { control: 'text' }, // always shows | ||
advanced: { control: 'boolean' }, |
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.
So, users have to opt into the advanced controls in this case right?
table: { | ||
disable: true, | ||
}, | ||
removeIf: true, |
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.
Does this mean we no longer have to pass diable to the table object?
We will use removeIf
and addIf
everywhere?
self-merging @tmeasday @yannbf to get this unstuck. still did not figure out the various permutations of visibility & read-only etc but i've timeboxed this and will come back to it @ethriel3695 i've reverted the |
Unfortunately this still doesn't enable us to use dynamic controls in their full potential. |
@GeorgiMoskov please check out the reworked version #17883 -- you might be able to hack something because it does allow to show & hide based on the state of globals. it won't do exactly what you did in dynamic knobs, but it's not intended to replace fully dynamic knobs. rather, it is just enabling some of the more common use cases. |
@shilman If it's not intended to fully replace the dynamic knobs but knobs are being deprecated. What is the alternative of the dynamic knobs then? As you mentioned this solutions does not actually close the issue it is just adding a conditional logic over static values. Can you give us an example how can we "hack"/implement such functionality? |
Issue: #11984
What I did
Revive & update #13890
This PR adds/removes ArgsTable rows and their corresponding Args data conditionally based on the value of other args:
Some examples:
How to test
See updated stories & unit tests