question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

addon-knobs select knob with list of functions

See original GitHub issue

Describe the bug I have a component that is passed a function as a prop that determines how the component behaves under certain CSS breakpoints. There is a finite list of functions that can be passed, one for each site breakpoint in fact. When I pass an object of functions they are not rendered in the dropdown To Reproduce Steps to reproduce the behavior:

  1. Create a select knob for a prop like so
select('Disable From', { fromExtraLarge: () => null })

Expected behavior ‘Disable From’ to appear in the dropdown list

System:

  • OS: MacOS
  • Device: Macbook Pro 2018
  • Browser: chrome
  • Framework:react
  • Addons: addon-knobs
  • Version: 4.1.11

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
c-moss-talkcommented, Feb 16, 2019

There’s a way you can accomplish this:

const onChangeDict = {foo: console.log('foo'), bar: console.log('bar'}}
const onChange = select('onChange', ['foo', 'bar']);
return <Input onChange={onChangeDict[onChange]}

It would be nice to display function signatures though. It’s common to have function props so I’d like to work toward a way to support them as their own knob type; however, my search hasn’t found much in the issues.

1reaction
gptt916commented, Sep 13, 2019

@shilman

I’m also interested in a knob that displays function signatures. I am in the process of building a reusable library and quite a few of them require some sort of callback as a prop, it would be nice if it could be included with the rest of the props in the knobs tab to show potential users what to expect, right there in the same page.

Currently I have left the functions out of the knobs tab and are replying on a readme for users to understand what callbacks to provide to the component.

Maybe something simple that signifies the prop is a function, and I could provide the signature to be displayed, and the field will be there to inform users that this is a prop for the component?

Read more comments on GitHub >

github_iconTop Results From Across the Web

addon-knobs select knob with list of functions #5616 - GitHub
Describe the bug I have a component that is passed a function as a prop that determines how the component behaves under certain...
Read more >
Knobs Addon | Storybook: Frontend workshop for UI ...
Storybook Addon Knobs allow you to edit props dynamically using the Storybook UI. You can also use Knobs as a dynamic variable inside...
Read more >
Anyone knows the inner working of select knob in React ...
My question is: How does the storybook Knob select work to set the same component prop successfully but my setting it from the...
Read more >
Top 5 @storybook/addon-knobs Code Examples - Snyk
To help you get started, we've selected a few @storybook/addon-knobs examples, based on popular ways it is used in public projects.
Read more >
Addons | Knobs . withKnobs - complex select ⋅ Storybook
Knobs. with decorators. withKnobs. tweaks static values · tweaks static values organized in groups · dynamic knobs · complex select · Options Knob....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found