Storybook Component Workflow
Full workflow for Figma-to-Storybook UI development: design inspection, stateless extraction, story writing, browser verification, and design diff resolution.
Dev Server Reference
Check the terminals folder before starting any server -- reuse existing sessions.
| Context | Port | Start Command |
|---------|------|---------------|
| lib/ui Storybook | 6006 | yarn workspace @lib/ui storybook |
| core/ui Storybook | 6007 | yarn workspace @core/ui storybook |
Never start a server if one is already running. Reuse existing browser tabs.
Workflow Order
For any UI component work (especially from Figma):
- Fetch design specs (Figma MCP if a link is provided)
- Build the component with all states as props
- Write the Storybook story -- show all meaningful states in a single story view so the user can review at a glance
- Start Storybook (or reuse existing) and verify visuals in the browser
- Integrate into the app
Build and verify in Storybook before integrating into the app. Storybook is the agent's primary UI verification environment -- it's fast, isolated, and doesn't require authentication or navigation.
For app-level verification after integration: use judgment. If the target view is easy to reach (no auth, simple navigation), verify it yourself. If it requires authentication, multi-step navigation, or device pairing, tell the user the integration is done and ask them to verify in the app.
Storybook Location Decision
| Component depends on | Story goes in |
|----------------------|---------------|
| Only @lib/ui + @lib/utils | lib/ui/ (next to the component) |
| @core/ui, @core/config, @core/chain, or other @core/* | core/ui/ (next to the component) |
Both packages have Storybook fully configured. Use the existing setup.
Storybook Setup Reference
Both lib/ui and core/ui already have complete Storybook configurations. If a new package needs Storybook, follow the core/ui/.storybook/ pattern:
main.ts-- Vite framework via@storybook/react-vite,staticDirsfor fonts/images fromcore/ui/public.preview.tsx--styled-componentsThemeProviderwithdarkTheme,GlobalStylefor global styles. Forcore/ui, also wrap withI18nextProviderfor translations.package.json-- Addstorybookandbuild-storybookscripts. Add@storybook/addon-docs,@storybook/react-vite,storybookas devDependencies.knip.json-- Ensure**/*.{ts,tsx}in the package's project globs covers.stories.tsxfiles (already the case).eslint.config.mjs--eslint-plugin-storybookis already configured globally withstorybook.configs['flat/recommended'].
Styling
This codebase uses styled-components (not Tailwind). All components use:
styled-componentsfor component stylingdarkThemefrom@lib/ui/theme/darkThemefor themingGlobalStylefrom@lib/ui/css/GlobalStylefor global stylesgetColor()helper for theme-aware colors- Layout primitives:
HStack,VStackfrom@lib/ui/layout/Stack
Stateless Extraction Pattern
To make a component Storybook-friendly, extract a stateless version:
- Create
form.tsx(orcontent.tsx) -- a pure component with props for all external data:
```
value, onChange, onSubmit
```
No hooks for persistent state, no route params, no auth context.
- Refactor the parent -- becomes a thin wrapper:
```tsx
<Modal title="...">
<StatelessForm value={...} onChange={...} onSubmit={...} />
</Modal>
```
- Do not export the stateless component from the package index unless it has external consumers. Stories import directly from the file.
Story Structure
import type { Meta, StoryObj } from '@storybook/react-vite'
import { MyComponent } from '.'
const meta: Meta<typeof MyComponent> = {
title: 'Category/ComponentName',
component: MyComponent,
tags: ['autodocs'],
parameters: { layout: 'centered' },
}
export default meta
type Story = StoryObj<typeof MyComponent>
export const Default: Story = {
args: {
// default props
},
}
Interactive stories with local state
When a story needs local state (e.g., modals that open/close), use a render function:
import { Button } from '@lib/ui/buttons/Button'
import { Modal } from '@lib/ui/modal'
import type { Meta, StoryObj } from '@storybook/react-vite'
import { useState } from 'react'
// Use untyped Meta when render functions use wrapper components
const meta = {
title: 'Category/ComponentName',
} satisfies Meta
export default meta
type Story = StoryObj
function Interactive({ initial }: { initial?: ValueType }) {
const [value, setValue] = useState<ValueType | undefined>(initial)
const [open, setOpen] = useState(false)
return (
<>
<Button kind="primary" onClick={() => setOpen(true)}>
Open
</Button>
{open && (
<Modal title="..." onClose={() => setOpen(false)}>
<StatelessForm value={value} onChange={setValue} onSubmit={() => {}} />
</Modal>
)}
</>
)
}
export const NoneSelected: Story = {
render: () => <Interactive />,
}
export const OptionASelected: Story = {
render: () => <Interactive initial="optionA" />,
}
Key rules:
- Import types from
@storybook/react-vite(not@storybook/react). - Use untyped
Meta/StoryObj(no generic) when stories use wrapper render functions -- avoids Storybook 10's requiredargstype error. - For modal components, wrap in
<Modal>so the content is visible. - Cover all meaningful states as separate story exports.
Browser Verification
After starting Storybook:
- Navigate to the story URL in the browser tool.
- Test at three viewports:
- Desktop (1280px+) -- full layout with all panes
- Tablet (~800px) -- breakpoint transitions, check pane visibility
- Mobile (~375px) -- collapsed layout, check padding
- Compare against Figma -- use
get_screenshoton the same Figma node for side-by-side reference.
If blocked from browser access, state: "Browser check not performed -- {reason}"
Browser Tool Notes
- The Cursor browser tab shares editor space -- the effective viewport is smaller than the set dimensions.
- Use Storybook's viewport addon (the toolbar dropdown) to simulate responsive sizes rather than resizing the browser window. The Storybook iframe does not respond to outer browser resizing.
- For full-viewport screenshots, navigate directly to the iframe URL:
http://localhost:{port}/iframe.html?id={story-id}&viewMode=story. This bypasses Storybook's sidebar/toolbar and gives the full viewport to the component. - Always verify decorative elements and z-index at mobile viewport using Storybook's viewport control before reporting completion.
Debugging: Iframe Access
Storybook renders stories inside an iframe. Browser snapshots show the shell UI (sidebar, toolbar), not the story content.
Option 1: Direct iframe URL (preferred)
Navigate to: http://localhost:{port}/iframe.html?globals=&id={story-id}&viewMode=story
Story ID format: lowercase with hyphens, e.g., screens-backupoverviewscreen--four-devices (title segments joined by -, variant after --).
Option 2: Isolation mode
In Storybook UI, click Share > Open in isolation mode, then take a snapshot of the new tab.
Option 3: Ask user
If browser tools fail, ask the user to inspect in DevTools and share:
- DOM path
- Element dimensions
- Computed styles (especially overflow)
Figma Design Comparison Checklist
When implementing or verifying a Figma design:
- Styled components -- Match every element against the project's
styled-componentspatterns. UsegetColor()for theme colors, not raw hex values. - Colors -- Use theme tokens from
darkTheme(e.g.,getColor('primary'),getColor('text')). Cross-reference Figma's color variables with the theme scale. - Font weights -- Figma "Regular" =
weight="400", "Medium" =weight="500", "SemiBold" =weight="600". Use theTextcomponent'sweightprop. - Spacing -- Check padding and gaps against the Figma layout. Use layout primitives (
HStack,VStackwithgapprop). - Interactive states -- Verify selected, disabled, hover, and focus states match the design.
- Responsive behavior -- Check where panes hide/show, how padding changes, and whether the layout scales correctly at each breakpoint.