Storybook
Storybook is a tool for developing and testing UI components in isolation. It provides a sandboxed environment where you can build, view, and test components without running the full Electron application.
Starting Storybook
This will start the Storybook development server at http://localhost:6006.
Building Static Storybook
To build a static version of Storybook that can be deployed:
The output will be in storybook-static/.
Writing Stories
Stories are colocated with their components. For example, ErrorMessage.tsx has its stories in ErrorMessage.stories.tsx in the same directory.
Basic Story Structure
Component Examples
See the existing stories for reference:
src/components/ErrorMessage.stories.tsx- Simple component with multiple statessrc/components/Modal.stories.tsx- Complex component with children and multiple variants
Global Styles
Storybook automatically applies the same global styles as the main app:
- Color variables (
GlobalColors) - Font definitions (
GlobalFonts) - Scrollbar styles (
GlobalScrollbars)
These are configured in .storybook/preview.tsx.
Handling Electron APIs
Some components depend on window.api for Electron IPC communication. For these components:
- Preferred: Extract the component logic to accept props instead of calling IPC directly
- Alternative: Mock the
window.apiobject in.storybook/preview.tsx
Example mock structure:
Benefits
- Isolated Development: Build components without running the full Electron app
- Visual Testing: See all component states at once
- Documentation: Stories serve as living documentation with
autodocs - Faster Iteration: Hot reload is faster than Electron rebuilds
- Accessibility: Storybook addons can check accessibility issues
Configuration
.storybook/main.ts- Main Storybook configuration.storybook/preview.tsx- Global decorators and parameterstsconfig.json- Includes.storybook/**/*.tsfor type checking
Tips
- Keep stories simple and focused on visual states
- Use Storybook's Controls addon to make props interactive
- Add multiple stories for different states (loading, error, success, etc.)
- Use the
tags: ["autodocs"]option to generate automatic documentation