liveBook · Manning

Storybook

As explained in React in Depth

Storybook is a development environment for building, testing, and documenting UI components in isolation.

Storybook is a development environment for browsing, exercising, and documenting UI components in isolation. It exposes components with different property and input combinations, shows the implementation behind each visualization, and can provide live controls for interaction. section 13.1.1

A practical Storybook workflow includes:

  • Run the existing setup with npm run storybook -w ch13/base; the default browser address is localhost:6006, with the port configurable in package.json. section 13.1.1
  • Create a correctly formatted Button.stories.js, .jsx, .ts, or .tsx file; Storybook does not discover components automatically. section 13.1.1

Button variants as a component contract

A Button story can expose its label through a text control, its variant through a select containing regular, outline, and ghost, and disabled and icon placement through boolean controls. Exported variants then become both visual reference points and reusable test fixtures. A test can compose Default, render it with an onClick mock, click the accessible button named Regular button, and verify one call.

Storybook also scales beyond isolated buttons: a Wordle implementation uses it to expose base components and variants, while XState handles the game's main logic separately. section 14.4

How React in Depth covers it

How deep it goes
Demonstrates story-file configuration, controls, variants, visual inspection, and story-based interaction tests without covering Storybook internals.
Examples
Uses button stories, configurable controls, variant grids, composed click tests, and Wordle component previews.
What it assumes
Assumes React components and testing fundamentals while teaching story-file structure, component controls, variants, and story composition.
What you can do after
Build it from scratch by adding story files, configuring controls and variants, browsing components, and reusing stories in tests.
How it connects
Connects UI components, component variants, props, visual testing, interaction testing, React Testing Library, Vitest, and XState.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of React in Depth. The section links point to the parts of the book it draws on.