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

Addon Knobs - Add function type #11

Open
AndyOGo opened this issue Jan 5, 2021 · 4 comments
Open

Addon Knobs - Add function type #11

AndyOGo opened this issue Jan 5, 2021 · 4 comments

Comments

@AndyOGo
Copy link

AndyOGo commented Jan 5, 2021

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
Copy link
Member

shilman commented Feb 27, 2021

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
Copy link
Author

AndyOGo commented Feb 27, 2021

@shilman
Sounds great. Does it support functions?

@shilman
Copy link
Member

shilman commented Feb 27, 2021

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
Copy link
Author

AndyOGo commented Feb 27, 2021

@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.

@shilman shilman transferred this issue from storybookjs/storybook May 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants