Find code pattern for knob reuse #556
Labels
✨ enhancement
New feature or request
👷 environment
Setup, build tools, configuration, etc.
✍️ help wanted
Extra attention is needed
The Problem
Storybook knobs allow us to pass props into code demos. This is really cool for allowing users to interact with code examples and try out different options! It works great for pattern modifiers, pattern content, and more.
I was recently working on a new Table pattern. I wanted to have several demos showing all the different modifiers and options. I wanted each demo to show all of the options. However, for each demo I wanted to hard code the value of a specific knob.
For example, for the Striped Table example, I wanted to hard code the
rowModifier
knob too-table--striped
. This was my first, quick and dirty implementation:This quickly became ungainly as I added more examples and it seemed like there was an opportunity to DRY this up. Here's what I'd like to be able to do:
This almost works. The striped demo renders with the custom knob value I passed in. However, the
rowModifier
knob still shows, but no longer does anything 🤔. I would like therowModifier
knob to be completely hidden for the striped demo.I tried a handful of other solutions:
defaultKnobs()
function that returned a brand new object each time and then spreading thatreturn { ...defaultKnobs(), ...customKnobs()}
defaultKnobs
from a separate filedefaultKnobs
properties into anonymous functions that return the knobNone of these things worked. It seems like this should be doable. I feel like I'm missing something obvious, but I don't want to let this hold up my current design work any longer.
Any ideas?
The text was updated successfully, but these errors were encountered: