Overview
The Openlane UI library uses Storybook for component development, testing, and documentation. Storybook provides an isolated environment to build and test components independently from your application.Running Storybook
Storybook is set up in theapps/storybook directory of the monorepo.
Start Storybook
Storybook Configuration
The Storybook setup uses Vite for fast builds and hot module replacement:.storybook/main.ts
Installed Addons
Accessibility
@storybook/addon-a11y - Test components for accessibility issuesTheming
@storybook/addon-themes - Toggle between light and dark themesDocumentation
@storybook/addon-docs - Auto-generate component documentationLinks
@storybook/addon-links - Navigate between storiesWriting Stories
Stories are written using the Component Story Format (CSF) 3.0:Basic Story Example
Here’s how the Button component stories are structured:button.stories.tsx
Story Organization
Stories are organized by category:Interactive Controls
Storybook provides interactive controls for component props:- Text Controls
- Select Controls
- Boolean Controls
Testing Components
Visual Testing
Use Storybook to visually test components in isolation:- Test all variants: Create stories for each variant
- Test states: Loading, disabled, error states
- Test interactions: Click handlers, form submissions
- Test responsive behavior: Resize viewport
Accessibility Testing
The@storybook/addon-a11y addon automatically checks for accessibility issues:
Dark Mode Testing
Test components in both light and dark modes:- Click the theme toggle in the Storybook toolbar
- Switch between light, dark, and side-by-side views
- Verify colors and contrast in both themes
.storybook/preview.tsx
Documentation
Storybook auto-generates documentation from your stories:Component Description
Prop Documentation
Creating New Stories
Follow these steps to create a new story:Best Practices
Create Comprehensive Stories
Create Comprehensive Stories
Cover all important variants and states:
Use Meaningful Story Names
Use Meaningful Story Names
Story names should clearly describe what they demonstrate:
Document Component Behavior
Document Component Behavior
Add descriptions to help users understand the component:
Test Edge Cases
Test Edge Cases
Create stories for edge cases:
Building Storybook
Build a static version of Storybook for deployment:storybook-static/.
Available Scripts
Troubleshooting
Stories not appearing
Stories not appearing
Check that your story file matches the glob pattern in
main.ts:Styles not loading
Styles not loading
Ensure styles are imported in
.storybook/preview.tsx:Dark mode not working
Dark mode not working
Verify the theme addon is configured:
Component Examples in Storybook
Here are some example components you can explore in Storybook:Button
10+ variants including primary, secondary, loading states
Input
Variants with icons, prefixes, suffixes
Select
Form select with multiple styles
Dialog
Modal dialogs with different layouts
Table
Sortable data tables
Toast
Toast notifications with variants
Tabs
Tabbed navigation
Badge
Status badges and labels
Switch
Toggle switches
Next Steps
Component Overview
View all available components
Usage Guide
Learn how to use components
Theming
Customize component themes
Installation
Setup the component library