A Cursor/VS Code extension that shows a live preview of React components when they have an associated Storybook story.
- 🎨 Automatic Detection: Automatically detects when you open a React component file that has a Storybook story
- 🔄 Live Updates: Preview updates automatically when story files change
- 🚀 Quick Access: Toggle preview on/off with a command
- 🎯 Smart Story Detection: Automatically extracts story IDs from Storybook story files
- Clone or copy this extension directory
- Install dependencies:
cd .vscode-storybook-preview npm install - Compile the extension:
npm run compile
- Press
F5in VS Code/Cursor to open a new window with the extension loaded - Or package and install:
Press
npm install -g vsce vsce package code --install-extension storybook-live-preview-0.1.0.vsix
Ctrl+Shift+Pand findInstall from VSIXoption in the IDE to install the extension.
Open Settings and search for "Storybook Preview" to configure:
- Storybook URL: The URL where Storybook is running (default:
http://localhost:6006) - Storybook Build & Run command: Commands to run and build storybook locally
- Auto Start: Automatically build and start Storybook if its not running
- Auto Show: Automatically show preview when opening components with stories
-
Start Storybook: Make sure Storybook is running in your project:
npm run storybook # or yarn storybook -
Open a Component: Open any React component file (
.tsx,.ts,.jsx,.js) that has a corresponding.stories.tsxfile -
View Preview: The preview will automatically appear (if auto-show is enabled) showing the first story for that component
-
Toggle Preview: Use the command palette (
Cmd+Shift+P/Ctrl+Shift+P) and search for "Toggle Storybook Preview"
The extension:
- Monitors the active editor for React component files
- Looks for corresponding
.stories.tsxor.stories.tsfiles in the same directory - Extracts the Storybook story ID from the story file's
titlefield or filename pattern. - Embeds Storybook's iframe in a webview panel
- Updates the preview when story files change
The extension extracts story IDs from:
- The
titlefield in the story's meta export (e.g.,title: "Design System/Atoms/Button") - Falls back to the file path if no title is found
Make sure your Storybook stories have a title field in the meta export for best results:
const meta: Meta<typeof Button> = {
component: Button,
title: "Design System/Atoms/Button", // This will be used to build the story ID
// ...
}- Make sure Storybook is running at the configured URL (default:
http://localhost:6006) - Check that the component file has a corresponding
.stories.tsxfile in the same directory - Verify the story file has a
titlefield in the meta export
- The extension uses the story's
titlefield to build the story ID - If multiple stories exist, it will show the first/default story
- You can manually navigate to other stories using Storybook's controls in the preview
- The extension watches for file changes, but there may be a delay
- Try clicking the "Refresh" button in the preview header
- Make sure the story file is saved
To contribute or modify this extension:
- Make changes to
src/extension.ts - Compile:
npm run compile - Reload the extension window (press
Ctrl+RorCmd+Rin the extension development host) - Or package the changes and raise a PR to this repo.