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-controls: Add custom user-defined controls

See original GitHub issue

We are currently documenting our React components in Storybook, and decided to go straight to version 6.0 to make use of the new Args and Controls addons. During that work, we realised that the choice of controls is very limited.

Here are some examples:

  • We want users to select from a pre-defined list of colors. The "select" control can only display text but we want to preview the color next to it.
  • We want users to select from a list of icons. The control should display a list of all icons and clicking on an icon selects it.
  • One prop may allow for string[], so we want to allow the user to add strings to the list, or remove existing strings.

Any chance to allow users to specify custom controls in argTypes that are not built into addon-controls?

Here’s how this could look like in React code, where ColorPicker is a custom control we’d build:

const ColorPicker = ({ value, setValue }) => {
  return (
    <select value={value} onChange={setValue}>
      <option>red</option>
      <option>blue</option>
    </select>
  );
}

export default {
  title: "ExampleComponent",
  component: ExampleComponent,
  argTypes: {
    color: {
      control: ColorPicker,
    },
  },
};

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:89
  • Comments:28 (7 by maintainers)

github_iconTop GitHub Comments

23reactions
nathanielkscommented, Apr 30, 2021

One generic thing that would be good is nested controls.

I would also be interested in adding controls for args with nested properties.

19reactions
WebTerminatorcommented, Oct 26, 2021

is there any update on this? Thank you

Read more comments on GitHub >

github_iconTop Results From Across the Web

Controls - Storybook - JS.ORG
Customize the controls and interactive data to suit your exact needs. To use the Controls addon, you need to write your stories using...
Read more >
Next-level component showcasing with Storybook controls
Learn about controls, a new Storybook addon that lets you dynamically interact with your React components for demo and testing purposes.
Read more >
@storybook/addon-controls - npm
npm install @storybook/addon-controls -D # or yarn ... If you ONLY want to use custom argTypes , don't set a component .
Read more >
Solved: Can I add custom controls into Confluence Addon Pr...
Register panel initialization through. AJS. · Inside handler the first patameter would be macro placeholder, and teh second is buttons array. · If ......
Read more >
How to make interactive components in Storybook (ReactJS ...
You can make it even cooler by defining custom controls for each of ... Use propTypes and defaultProps in your components to get...
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