Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@storybook/addon-controls: howto not auto-generate control for a certain prop

@storybook/addon-controls is fun, however I cannot find a way to disable control generation for a given arg. Lets say I have a component prop that is an event handler and I obviously do not want it to have a control. So I want it to appear in the list of props with the name, type and description, but no control. How do I do that?

like image 531
jayarjo Avatar asked Jun 29 '20 15:06

jayarjo


People also ask

How do you add controls in storybook?

To use the Controls addon, you need to write your stories using args. Storybook will automatically generate UI controls based on your args and what it can infer about your component. Still, you can configure the controls further using argTypes, see below.

What is ArgTypes storybook?

ArgTypes are a first-class feature in Storybook for specifying the behaviour of Args. By specifying the type of an arg, you constrain the values that it can take and provide information about args that are not explicitly set (i.e., not required).

Which add on allows storybook users to change the data within a component?

The React Context addon allows you to provide and manipulate context inside Storybook.


1 Answers

this was recently added: https://github.com/storybookjs/storybook/pull/11388 Essentially you should be able to use control.disable within argTypes for a given arg.

Suppose you have a story with foo and bar properties (auto-generated or otherwise) and you want to hide the foo row completely and disable controls for the bar row on a specific story:

MyStory.argTypes = {
  foo: { table: { disable: true } },
  bar: { control: { disable: true } },
};

Here's the entry in the docs.

Cheers

like image 199
Dangoo Avatar answered Oct 27 '22 11:10

Dangoo