Storybook

Using Storybook to develop and document UI components

Storybook lets us:

  • quickly build UI components in isolation

  • mock out a component’s different states/variations

  • experiment and test with different props (i.e. what happens if the text for a label is really, really long?)

It also:

Writing Stories

circle-check

Setting where a Story should be organized in the sidebar

CompatibilityWarningContent.stories.tsx
storiesOf('Notifications|CompatibilityWarningContent', module)
StatusModal.stories.tsx
storiesOf('Notifications|Modals/StatusModal', module)
Result
circle-info

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

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.

Using a visual wrapper component

Good for components that stretch too wide without a container. Using addDecoratorarrow-up-right, all of the Stories will be children of the wrapper component.

Allowing for quick prop changes

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.

Documentation: https://github.com/storybooks/storybook/tree/master/addons/knobsarrow-up-right

Result

Add/remove options from a <select>

Result

Simulate performing an action

You can also use Knobs to add buttons that trigger a change in UI:

Result

Last updated

Was this helpful?