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:
provides documentation of our components
is used by Percy to perform its visual diffs
works with Jest to do automatic code snapshot testing (StoryShots addon)
can catch simple a11y violations as soon as they occur (a11y addon)
Writing Stories
If you write a Story for every different use case or state of a component, Percy will take a snapshot and catch any visual changes later on.
Setting where a Story should be organized in the sidebar
storiesOf('Notifications|CompatibilityWarningContent', module)storiesOf('Notifications|Modals/StatusModal', module)
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 addDecorator, 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/knobs

Add/remove options from a <select>

Simulate performing an action
You can also use Knobs to add buttons that trigger a change in UI:

Last updated
Was this helpful?