If you group any Stories (i.e. Group|Folder/Story) in your Storybook, Stories without a defined group will now appear in an automatically-generated "Others" group in the sidebar.
The most basic Story
import React from 'react';
import { storiesOf } from '@storybook/react';
import MyComponent from './MyComponent';
storiesOf('Group|Folder/MyComponent', module)
.add('default', () => (
<MyComponent />
));
You can have multiple storiesOf blocks if it helps you stay organized; any blocks that share a name string will be combined in the sidebar as a single collection of Stories.
The Knobs addon lets us change the props passed into our component inside Storybook’s UI. It’s super helpful to quickly test out component appearance against different values.
import React from 'react';
import { storiesOf } from '@storybook/react';
import { withKnobs, boolean, text } from '@storybook/addon-knobs';
import TextInput from './TextInput';
storiesOf('Form Elements|Inputs/TextInput', module)
.addDecorator(withKnobs)
.add('default', () => (
<TextInput
label={text('Label text', 'Standard text input')}
placeholder={text('Placeholder text', '')}
small={boolean('Small variant', false)}
required={boolean('Required', false)}
disabled={boolean('Disabled', false)}
error={boolean('Error', false)}
/>
));
Add/remove options from a <select>
import React from 'react';
import { storiesOf } from '@storybook/react';
import { withKnobs, array, text } from '@storybook/addon-knobs';
import SelectDropdown from './SelectDropdown';
storiesOf('Form Elements|SelectDropdown', module)
.addDecorator(withKnobs)
.add('default', () => (
<SelectDropdown
label={text('Label text', 'Default Dropdown')}
options={array('Options', ['Apples', 'Oranges', 'Pears'])}
/>
));
Simulate performing an action
You can also use Knobs to add buttons that trigger a change in UI: