This file provides context for AI assistants working on the Storybook integration in superdesk-ui-framework.
Storybook 10.1.11 is fully integrated with the main documentation site (Angular-based, running on webpack-dev-server at port 9100). This is NOT a standalone Storybook deployment.
-
Build Integration (package.json:24)
npm run buildruns: tsc → webpack → tsc → build-storybook → copy-storybook- Storybook builds to
storybook-static/ - Copy script moves it to
dist/storybook/ - Single deployment artifact in
dist/includes both docs and Storybook
-
Development Mode
- Main docs:
npm start→ http://localhost:9100/ - Standalone Storybook:
npm run storybook→ http://localhost:6006/ - webpack-dev-server configured to serve
storybook-static/at/storybookpath (tasks/webpack.dev.js:23-26)
- Main docs:
-
Navigation
- Storybook link in main docs navigation opens in new tab (target="_blank")
- Located at: http://localhost:9100/storybook/index.html (in dev)
- No custom back navigation needed - new tab keeps original context
.storybook/main.ts- Main config, stories pattern, addons (uses Babel compiler), webpack customization for SCSS.storybook/preview.ts- Global parameters, imports app.scss for styling.babelrc- Babel configuration with TypeScript, React, and env presets (required for Babel compiler addon)app-typescript/components/*.stories.tsx- Component stories (CSF 3.0 format)
package.json- Build scripts with Storybook integrationtasks/webpack.dev.js- Dev server config to serve Storybook static filesexamples/pages/main.html- Main docs page with Storybook nav linkexamples/index.js- Angular routing (no Storybook route needed)
STORYBOOK_MIGRATION.md- Human-readable migration guideREADME.md- Updated with Storybook section
-
Why New Tab Instead of Embedded?
- Simpler: No iframe complexity or custom navigation code
- Better UX: Users can easily switch between docs and Storybook
- Cleaner: No JavaScript hacks needed
-
Why Integrated Build?
- Single deployment:
dist/contains everything - Consistent versioning: Docs and Storybook always in sync
- Simpler CI/CD: One build, one deploy
- Single deployment:
-
Why Not manager-api/theming packages?
- Incompatible: These are for Storybook 8.x, project uses 10.x
- Not needed: New tab approach doesn't require customization
-
Why Babel Compiler Instead of SWC?
- CI Compatibility: SWC native bindings fail in GitHub Actions and other CI environments
- Stability: Babel doesn't require platform-specific native bindings
- Compatibility: Works reliably across different platforms (macOS, Linux, Windows)
- Trade-off: Slightly slower build times, but more reliable deployments
Reference implementation: app-typescript/components/Button.stories.tsx
IMPORTANT: With Babel compiler and React 16, you MUST import React in every story file that uses JSX:
import React from 'react';
import type {Meta, StoryObj} from '@storybook/react';Required structure:
- Meta object with title, component, parameters, tags, argTypes
- Default export of meta
- Story type from StoryObj
- Playground story (required) - interactive with all controls
- Additional example stories as needed
- Create
ComponentName.stories.tsxinapp-typescript/components/ - Follow the pattern in Button.stories.tsx
- Stories auto-discovered by pattern:
app-typescript/**/*.stories.@(ts|tsx) - No config changes needed
- Edit
.storybook/main.tsfor addons, webpack, stories pattern - Edit
.storybook/preview.tsfor global styles, parameters - Restart
npm run storybookto see changes
npm run build
# Outputs to dist/ including dist/storybook/npm start # Main docs at :9100
# Navigate to Storybook link - should open in new tab at :9100/storybook/- Storybook: 10.1.11 with React webpack5 framework
- Compiler: Babel (via @storybook/addon-webpack5-compiler-babel) with TypeScript, React, and env presets
- React: 16.14.0 (legacy version, some React 18 hooks unavailable)
- TypeScript: 5.9.3 with react-docgen-typescript
- Build: webpack 5 with custom SCSS support
- Docs: Angular 1.7.9 with hash-based routing
- React 16: No useId, useInsertionEffect, useDeferredValue, etc.
- No Storybook 8 packages: manager-api, theming only exist for 8.x
- Angular routing: Main docs use Angular + hash routing, Storybook is separate
- SCSS required: Must maintain SCSS support in Storybook webpack config
- ✅ Storybook 10 installed and configured
- ✅ SCSS/styles working
- ✅ Button component migrated as reference
- ✅ Build integration complete
- ✅ Dev server integration complete
- ✅ Documentation updated
- 🔄 Additional components to migrate (see STORYBOOK_MIGRATION.md)
- Check for TypeScript errors: Stories must have valid TS
- Verify story files match pattern in .storybook/main.ts
- Ensure component imports are correct
- Verify
import '../app/styles/app.scss'in .storybook/preview.ts - Check webpack config in .storybook/main.ts has SCSS loaders
- Ensure
npm run build-storybookwas run after changes - Verify
storybook-static/directory exists - Check webpack-dev-server config serves /storybook path
If you see "ReferenceError: React is not defined" in stories:
- Cause: Story files using JSX without importing React
- Fix: Add
import React from 'react';at the top of the story file - Why: React 16 requires explicit React import for JSX (unlike React 17+ with automatic runtime)
- Example: See
app-typescript/components/Button.stories.tsx
If you see "Failed to load native binding" errors:
- This is why we use Babel compiler instead of SWC
- Verify
.storybook/main.tsuses@storybook/addon-webpack5-compiler-babel(not swc) - Ensure
.babelrcexists with correct presets - Required packages:
@babel/preset-env,@babel/preset-react,@babel/preset-typescript
- Component Migration: Gradually migrate more components to Storybook
- React 18 Upgrade: Would unlock more Storybook features
- Automated Testing: Consider adding interaction tests
- Visual Regression: Consider adding Chromatic or similar