lookbook
lookbook copied to clipboard
Dynamic param values based on component properties
Lookbook sounds like a great project!
I am currently evaluating if we can move on from storybook-viewcomponent and one thing we use a lot is passing param values as a Ruby constant, e.g.:
story :button do
constructor(
..
variant: select(ButtonComponent::VARIANTS, :secondary),
..
)
end
The same has to be done with copying & pasting in Lookbook, e.g.:
# @param variant [Symbol] select [primary, secondary]
And I was thinking if it would be possible to evaluate Ruby for the values, e.g.:
# @param variant [Symbol] select `ButtonComponent::VARIANTS`
Is this possible?
Okay, I went ahead and tried it. It's possible.
So there should be a way to write a nicer patch and include it.
Hey @strzibny - yes the current static nature of the @params
tag arguments can be a bit limiting at times unfortunately. Addressing that by some sort of string evaluation is definitely possible - this issue is about potentially using ERB in comments which would just be just a slightly different syntax to achieve basically the same end result.
Up until now I've tried to steer away from any form of eval
ing of Ruby code just to try to avoid any obvious security gotchas. But it's something I'm actively looking into as I realise that it would be very useful to people.
I think ERB sounds good too.
Hey @strzibny, I've just shipped v1.1.0 that includes support for dynamically generating options (either via a method in the preview class itself or through arbitrary code evaluation).
Full details are in the docs - I'm going to close this issue down now but let me know if you run into any issues if you get a chance to try it out :-)