storybookjs / addon-knobs

Storybook addon prop editor component
MIT License
12 stars 17 forks source link

Addon Knobs - Add function type #11

Open AndyOGo opened 3 years ago

AndyOGo commented 3 years ago

Is your feature request related to a problem? Please describe I am discovering Knobs, I see many supported types (text, bool, number...) but nothing for functions.

How to create a knobs for a function ? showModal={() => {}}

I tried to pass it as object but get a console error (Invalid prop knob.value supplied) I also tried to pass as text with "() => {}" but of course it generates an error as the component propType want a function, not a string.

Describe the solution you'd like Maybe we could have something like showModal=func("showModal", () => {}) And the UI would convert it with an eval, but I am afraid this eval would bring security issues. Maybe something equivalent ?

Describe alternatives you've considered None.

Are you able to assist to bring the feature to reality? no

Additional context Storybook 6

Reopening of storybookjs/storybook#9265

SO: https://stackoverflow.com/questions/54072656/storybook-addon-knobs-callback-function-knob

shilman commented 3 years ago

FYI, we’ve released addon-controls in Storybook 6.0. Controls are portable, auto-generated knobs that are intended to replace addon-knobs, which are slated for deprecation.

Please upgrade and try out controls today!

AndyOGo commented 3 years ago

@shilman Sounds great. Does it support functions?

shilman commented 3 years ago

Nope. I'm just posting this on all knobs issues to let people know which way the wind is blowing. :)

What are some use cases for a function control?

AndyOGo commented 3 years ago

@shilman Thanks for your quick answer and your interest.

Use cases would be costum formatters or validators (e.g. if you would use form libraries like react-final-form). Render props or any functional props used to derive their values.

Basically any function which affects the rendering and does not fit for addon-actions.