ds-to-storybook/SKILL.md
Build or update token-backed Storybook foundations, shared UI components, and stories from an extracted design-system package. Use after design-system-extractor, or when Codex must read design-system Markdown and token files, automatically trace original design sources such as Figma URLs/nodes, UI images, rendered routes, and frontend folders, infer component dependency order so core primitives are built before composed components, map component specs into a product repo, create or update Storybook docs, plan component batches, and verify implementation with the bundled Figma export addon without bypassing tokens.
npx skillsauth add harrychuang/cursor-skills design-system-to-storybookInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use this skill to turn an already extracted design-system package into a product repo's Storybook implementation. The design-system documentation and tokens are the normative source of truth. Original Figma nodes, UI images, rendered routes, and frontend folders recorded by design-system-extractor are supporting evidence for implementation details, Storybook parity, and visual verification.
This is a downstream implementation skill. Do not re-extract a design system here. If the required design-system docs, token architecture, source evidence, or component specs are missing, ask to run or continue design-system-extractor first.
Work in short, resumable passes. Each pass must start from the extracted design-system docs, source trace, and dependency plan; implement only the selected scope; verify it; update the implementation map and queue; then stop with the next recommended pass. Do not keep expanding scope because more components are visible.
The default pass budget is:
If the user asks for "all components" or a full library, create the trace, dependency plan, and queue, then complete the first bounded batch only unless they explicitly request continuous multi-batch execution.
design-system/, tokens/, and generated docs under docs/design-system/.DESIGN_EVIDENCE_MAP.md, SESSION_STATE.md, component spec Evidence tables, component-review image links, and any Figma URLs/nodes, UI screenshots, rendered routes, or frontend folders listed there.typographic-*, including slot hierarchy, wrapping, alignment, content semantics, and component typography tokens.design-system/SESSION_STATE.md, DESIGN_EVIDENCE_MAP.md, TOKEN_ARCHITECTURE.md, COMPONENT_INVENTORY.md, DESIGN_ELEMENTS.md, and relevant design-system/components/*.md.node <skill-root>/scripts/trace_sources.mjs <design-system-package-root> --write.node <skill-root>/scripts/plan_component_batches.mjs <design-system-package-root> --write --queue.node <skill-root>/scripts/inspect_storybook_project.mjs <product-repo-root> --json.design-system/STORYBOOK_IMPLEMENTATION_MAP.md when the design-system package lives in the product repo; otherwise use docs/design-system/storybook-implementation.md. Use assets/storybook-implementation-map-template.md when starting a new map.Choose the smallest mode that satisfies the user request:
extracted or planned component specs as shared components with stories.Do not compose product screens before the required shared components and stories exist unless the user explicitly asks for a product route first.
If the user asks to install or share this skill with Claude Code, Codex, or Cursor, read references/agent-installation.md and use scripts/install_agent_skill.mjs. Install the full skill directory so SKILL.md, scripts, references, and the bundled Storybook addon asset remain together.
Confirm the extracted package is usable:
| Required file | Purpose |
|---|---|
| design-system/SESSION_STATE.md | extraction status, known gaps, and recommended next step |
| design-system/DESIGN_EVIDENCE_MAP.md | source inventory, source fingerprints, and evidence IDs |
| design-system/TOKEN_ARCHITECTURE.md | token layers and naming rules |
| tokens/tokens-ref.css | raw reference values |
| tokens/tokens-sys.css | reusable semantic roles |
| tokens/tokens-comp.css | component-facing slots |
| design-system/COMPONENT_INVENTORY.md | component priority and status |
| design-system/components/*.md | anatomy, variants, states, accessibility, and token contracts |
If a required file is absent, continue only for the modes that still have enough evidence. For example, foundations can proceed without component specs, but component implementation cannot.
Build a source trace before editing code:
node <skill-root>/scripts/trace_sources.mjs <design-system-package-root> --write
Default output is design-system/STORYBOOK_SOURCE_TRACE.md. Use it to connect component specs to original sources:
get_design_context for component-level nodes, get_metadata for pages/structure, get_variable_defs for token variables, and get_screenshot for visual parity references. If only a page is known, use metadata to find the most relevant frame/component before implementing.Use the Story Source URL Parameters section from STORYBOOK_SOURCE_TRACE.md when creating or updating stories. Run node <skill-root>/scripts/sync_story_source_parameters.mjs <design-system-package-root> --product-root <product-repo-root> --write after story files exist; it writes Figma URLs to parameters.figmaSourceUrl and other web URLs to parameters.design.url when it can patch safely. Do not invent a URL from a local image path or normalized Figma fingerprint unless the docs also provide the matching file URL.
If the trace finds source IDs in component specs that cannot be resolved, mark the affected component blocked or needs-extraction in the queue before writing component code. If the trace finds Figma or image evidence for a component, do not skip that source unless the source is unavailable; record the reason.
Use original sources to clarify implementation details, not to silently override extracted design decisions. When Figma/image/frontend evidence contradicts the extracted tokens or component spec, stop and update the implementation map with the conflict; ask whether to revise the extraction or implement the documented spec.
Build a dependency plan before selecting components or batches:
node <skill-root>/scripts/plan_component_batches.mjs <design-system-package-root> --write --queue
Default outputs are design-system/STORYBOOK_COMPONENT_PLAN.md and design-system/STORYBOOK_COMPONENT_QUEUE.md. Use them to decide which component should be built next. The planner reads COMPONENT_INVENTORY.md, component specs, and STORYBOOK_SOURCE_TRACE.md, then infers:
typographic-*, text lockups, headings, captions, metric pairs, price stacks, and pull quotes as primitive or low-level composition dependencies unless their spec explicitly marks them as page-only product patternsIconButton depending on Buttonuses, contains, renders, wraps, or depends onUse the recommended order unless product discovery proves that a dependency already exists and can be reused. Do not build a composite component before its listed dependencies are implemented, reused, or explicitly marked blocked with a reason. If the planner reports a cycle, pick the lowest-level reusable primitive in that cycle first, record the cycle in the implementation map, and update the queue after the first component breaks the cycle.
For any multi-component pass, create or update the queue from STORYBOOK_COMPONENT_PLAN.md. The next component should come from the earliest unfinished row in the recommended build order whose dependencies are done, reused, or blocked with an accepted decision.
Re-run the planner with --queue after dependency decisions change. It preserves existing queue statuses, product targets, story targets, and decisions while refreshing order, batch, dependency, and source URL data.
Find the local implementation pattern before adding files:
.storybook/, *.stories.*, *.mdx, docs pages, decorators, preview styles.src/components/, components/, src/ui/, src/design-system/, packages/ui/, or existing exports.src/pages/, pages/, src/screens/, route modules, or existing composed view folders.Do not install Storybook or unrelated dependencies unless the user asked for Storybook setup or approves it after discovery. The bundled Figma export addon in the next section is the default dependency exception for compatible projects.
Use the bundled inspector to make discovery repeatable:
node <skill-root>/scripts/inspect_storybook_project.mjs <product-repo-root> --json
Record the package manager, framework, Storybook major version, builder, story roots, component roots, token files, and addon readiness in the implementation map. If the inspector reports that addon setup is not ready, keep implementation moving without forcing Storybook installation or upgrades.
Use folder co-location for new implementation files. Do not create a separate root stories/ folder for component stories.
src/components/<ComponentName>/.<ComponentName>.tsx, <ComponentName>.css, and <ComponentName>.stories.tsx. Add index.ts, tests, or helpers only when the product convention calls for them.stories/<ComponentName>.stories.*, src/stories/<ComponentName>.stories.*, or other detached component-story targets for new files.stories/ or src/stories/, because they document tokens rather than a single component implementation.src/pages/<PageName>/.<PageName>.tsx, <PageName>.css, and <PageName>.stories.tsx.pages/ if they belong in the reusable component library.If the product has an established component or page root, use that root while preserving the co-located folder shape. When editing existing files, avoid moving unrelated stories unless the current component/page needs cleanup for this rollout.
Install and configure the bundled @harrychuang/storybook-addon-figma-export by default when all requirements are met:
^10.storybook/main.* and .storybook/preview.* can be updated safelyThe addon package is vendored in this skill at assets/figma-export-addon/, sourced from harrychuang/storybook-addons#main:packages/figma-export. Do not install it from GitHub during normal use.
Install it with the bundled installer:
node <skill-root>/scripts/install_figma_export_addon.mjs <product-repo-root>
Use --copy-only only when you need to inspect or manually install the vendored package. If the bundled addon asset is missing or incomplete, mark figma-export-addon as blocked; do not fall back to GitHub unless the user explicitly asks to refresh the vendored asset.
If Storybook is missing, not version 10, or the project is not React-based, do not force the addon. Mark figma-export-addon as blocked in the implementation map with the reason and ask before installing or upgrading Storybook.
Generate a project-local addon config before editing .storybook/main.* or .storybook/preview.*:
node <skill-root>/scripts/generate_figma_export_config.mjs <design-system-package-root> --product-root <product-repo-root> --write
node <skill-root>/scripts/generate_component_spec_modules.mjs <design-system-package-root> --product-root <product-repo-root> --write
Default outputs are .storybook/figma-export.config.ts and .storybook/figma-component-specs.ts. If stories live outside common roots, pass one or more --story-root <path> flags to the config generator. Keep project-specific class prefixes, token prefix, story title prefixes, review API settings, Figma file fallbacks, node overrides, and generated spec-module maps out of the addon package.
Do not hardcode project-specific Figma file URLs, node IDs, class prefixes, theme globals, local graphics, or token imports inside the addon package. Keep those in .storybook/figma-export.config.ts, .storybook/preview.*, or product code. The addon should only expose generic helpers.
Configuration rules:
"@harrychuang/storybook-addon-figma-export" to .storybook/main.* addons, preserving existing addons.figmaExportProjectConfig from .storybook/figma-export.config.ts and build figmaExportOptions from that config..storybook/preview.*, import:
createFigmaExportGlobalTypescreateFigmaExportInitialGlobalsFigmaExportAddonOptionscreateFigmaExportReviewDecorator from @harrychuang/storybook-addon-figma-export/reviewgetFigmaSourceUrl from @harrychuang/storybook-addon-figma-export/source@harrychuang/storybook-addon-figma-export/styles.css@harrychuang/storybook-addon-figma-export/review.csscreateFigmaExportReviewDecorator, globalTypes, and initialGlobals into the existing preview export. Do not overwrite existing decorators or globals. Use plain createFigmaExportDecorator only if the user explicitly opts out of review/Open source.figmaExportOptions from the generated config, extracted token architecture, and Storybook titles. Use storyTitlePrefix: false when the project has no established story namespace; otherwise include every relevant namespace such as "Components/", "Pages/", and "Foundations/"..storybook/main.*: import createFigmaReviewStatusPlugin from @harrychuang/storybook-addon-figma-export/review-server.storybook/preview.*: pass componentSpecModules, specModulePathForSlug, designSystemFileUrl, and nodeOverrides to getFigmaSourceUrlfigmaExport toolbar global is toggled onValidate addon wiring before marking setup complete:
node <skill-root>/scripts/validate_figma_export_setup.mjs <product-repo-root>
Fix every failed check that applies to the target builder. For non-Vite Storybook builders, the review overlay can still be configured, but persisted review-status middleware may remain blocked unless the project has an equivalent middleware hook.
If the Figma export toolbar is visible but the review overlay or Open source action is missing, read references/figma-export-review-setup.md and fix the missing preview/main wiring before marking addon setup complete.
Before editing code, create or update the implementation map. Use assets/storybook-implementation-map-template.md when starting a new map.
The map must include:
| Design-system item | Source file | Product target | Decision | Status | |---|---|---|---|---| | token layer or component | extracted doc/token path | target token/component/story path | reuse, extend, create, defer | planned, done, blocked |
Also record:
.storybook/figma-export.config.ts path and inferred project-specific valuesUse this section when implementing more than one component, when COMPONENT_INVENTORY.md contains more than 8 components, or when the user asks to build a full library.
Create or update design-system/STORYBOOK_COMPONENT_QUEUE.md when the design-system package lives in the product repo. Otherwise create docs/design-system/storybook-component-queue.md. Use assets/storybook-component-queue-template.md as the output shape when starting a new queue.
Plan before implementation:
STORYBOOK_COMPONENT_PLAN.md; do not manually invent the first batch while the planner output is available.needs-extraction, needs-source, needs-token, needs-api-decision, needs-existing-component-review, or out-of-scope.Each batch should produce a clean resumable state:
| Batch | Components | Dependencies | Design sources | Target files | Validation | Status |
|---|---|---|---|---|---|---|
| B01 | component names | tokens/components needed first | source IDs, Figma nodes, images, or routes | planned product files | checks to run | queued/done/blocked |
Use this protocol for every multi-component implementation pass and every resume after a long run:
STORYBOOK_COMPONENT_PLAN.md, STORYBOOK_COMPONENT_QUEUE.md, STORYBOOK_IMPLEMENTATION_MAP.md, and git status --short before editing.done, reused, or accepted blocked decisions.in-progress in the queue before code edits.If a check fails, a source is ambiguous, a token is missing, or an API decision is needed, stop on that component and mark it with the narrowest blocked status. Do not continue to downstream composed components until the blocked dependency is resolved, reused, or explicitly accepted as blocked.
Every 3 completed components, or when context has become large, re-run:
node <skill-root>/scripts/plan_component_batches.mjs <design-system-package-root> --write --queue
Then re-read the queue before continuing. This keeps dependency order, source URLs, and completion records synchronized across long sessions.
Integrate tokens before components:
If the product repo has no token system, ask whether to establish one before implementing components.
Create or update foundations stories/docs for the token groups touched by this pass:
typographic-* specs existUse the project's existing docs style. If none exists, create the smallest useful Storybook docs page that displays token names, rendered examples, and usage notes.
Foundation guides may use the product's Storybook docs folder, normally stories/ or src/stories/. Keep these docs separate from component folders because they describe token systems rather than a single reusable component. Do not implement typographic-* specs only as foundation docs; if the extractor created a component spec, create or update the shared component and its co-located story.
For each selected component spec:
STORYBOOK_SOURCE_TRACE.md.STORYBOOK_COMPONENT_QUEUE.md whose dependencies are already done, reused, or explicitly blocked with an accepted decision.STORYBOOK_SOURCE_TRACE.md for the component.<ComponentName>.tsx, <ComponentName>.css, and <ComponentName>.stories.tsx.For typographic components, implement named text slots instead of accepting one undifferentiated children blob unless the existing component API requires that pattern. Preserve the extracted hierarchy through tokens: slot type roles, color, line-height, gap, alignment, max width, wrapping, truncation, and responsive rules. Stories should include realistic short and long copy, localization-length stress cases, and any numeric/price formatting shown in the spec.
If the extracted spec lacks a necessary state, mark it blocked or implement only the documented states. Do not invent undocumented visual variants as normative design-system behavior.
For a batch pass, keep implementation scoped to the selected batch. If a new primitive or API decision would change later batches, update the queue and implementation map before continuing.
Use this section only when the user asks for product pages, composed screens, or page-level Storybook entries.
src/pages/<PageName>/.<PageName>.tsx, <PageName>.css, and <PageName>.stories.tsx.components/<ComponentName>/ before using them in multiple pages.Do not place page stories in the root stories/ folder unless the existing product uses that folder exclusively for page docs and the implementation map records the exception.
Every new or changed shared component needs Storybook coverage:
Every component story should carry the best source URL the trace can resolve. Prefer the sync script before manual edits:
node <skill-root>/scripts/sync_story_source_parameters.mjs <design-system-package-root> --product-root <product-repo-root> --write
parameters: {
figmaSourceUrl: "https://www.figma.com/design/...?...node-id=...",
}
If the best source is a non-Figma URL, use:
parameters: {
design: { url: "https://..." },
}
Set this at the story meta level when all variants share the same source. Set it per story only when variants/states map to different Figma nodes or source URLs. The bundled review helper reads parameters.figmaSourceUrl, parameters.figma.url, and parameters.design.url automatically for the Open source action.
Prefer existing story conventions inside the co-located component or page folder. Use Autodocs or MDX only when the repo already uses them or the user asks for docs pages. Root stories/ or src/stories/ is reserved for foundation guides/docs, not new component stories.
Run the cheapest reliable checks available:
If Storybook is runnable, open the relevant stories and inspect rendered states before calling the pass done. When the selected component has Figma evidence, compare against a Figma MCP screenshot or exported frame when available. When the Figma export addon is installed, confirm the Storybook toolbar loads without console errors, the figmaExport toolbar can be toggled on, the review overlay appears, Open source is available for at least one component story with a resolved source URL, and Copy design can place SVG design output on the clipboard.
For large inventories, verify per batch and keep the full-library check for milestone boundaries. Do not wait until dozens of components are complete before running Storybook build or typecheck if those checks are available.
Update the implementation map and component queue with completed files, blocked items, token decisions, and verification results.
Report:
Do not treat guesses, unrecorded screenshots, or ad hoc visual impressions as source of truth in this skill. If a component or token is not documented in the extracted package, either defer it or ask to expand the extraction first.
Before implementing a component, resolve its extractor evidence IDs to original sources when those IDs exist. If the source trace shows Figma, image, frontend-folder, or rendered-route evidence, inspect at least the sources needed for the current component batch or record why they are unavailable. Do not implement a new component solely from an unlisted Figma node, image, or code folder; mark it needs-extraction instead.
Do not hardcode colors, spacing, radii, typography, shadows, or motion values in shared components when equivalent tokens exist. If a required token is missing, ask whether to add it at the correct layer before continuing.
Do not create a new shared component before checking the product's existing components and stories. If a candidate is close to an existing component, extend the existing one or ask whether to make it a variant.
Do not place new component stories in a detached root stories/ or src/stories/ folder. New shared components use components/<ComponentName>/<ComponentName>.stories.*; foundation docs are the only default exception.
Do not downgrade an extracted typographic-* component into a static typography foundation example. Build it as a shared component when the spec defines slots, composition rules, and component tokens. If the product already has an equivalent text component, mark the extractor component reused and add matching stories instead.
Do not start a composed component while STORYBOOK_COMPONENT_PLAN.md lists unfinished dependencies for it. Build, reuse, or explicitly block the dependency first, then update the queue and implementation map before moving to the composed component. Do not mark a component done until every listed dependency is done, reused, or recorded as an accepted blocked decision.
Do not move from one component to the next until the current component has a queue status, dependency-plan status, implementation-map entry, story source URL decision, and verification-log entry. For long runs, treat each component as a checkpoint boundary: finish or block the current component cleanly before reading the next spec.
Do not attempt to implement a large inventory in one pass. When implementing more than one component, create or update the component queue from STORYBOOK_COMPONENT_PLAN.md, choose a bounded dependency-adjacent batch, and leave the remaining work queued.
Do not silently skip addon setup for compatible React Storybook 10 projects. Install and configure it before component implementation unless the user opts out. If the project is incompatible, record the reason and continue with Storybook implementation only after the blocked addon status is explicit.
Use the bundled addon installer instead of GitHub dependency specs. If @storybook/icons is missing and package-manager install cannot reach the registry, record the addon as blocked with that dependency reason.
Keep project-specific addon settings in .storybook/figma-export.config.ts. Do not patch the bundled addon with product Figma file URLs, node overrides, token prefixes, theme globals, local image imports, or story sorting rules.
Do not mark a shared component implementation complete without a story, example, or documented catalog entry covering its main states.
Do not mark a component or page complete until its story is co-located in that component/page folder, unless the implementation map records an explicit product-convention exception.
Do not mark a component story complete until the best resolved source URL from STORYBOOK_SOURCE_TRACE.md is written to story parameters, or until the implementation map records that no URL source exists. Prefer parameters.figmaSourceUrl for Figma; use parameters.design.url for other web sources. Local screenshots and frontend folders are implementation evidence, but they are not Open source URLs unless the product serves them through a stable URL.
Do not rewrite product screens to use the new library until the relevant shared components are implemented and documented, unless the user explicitly requests route adoption as the current pass.
scripts/trace_sources.mjs and scripts/plan_component_batches.mjs: write source trace, component plan, and queue files.scripts/sync_story_source_parameters.mjs: reports or writes story source URL parameters from STORYBOOK_SOURCE_TRACE.md.scripts/generate_figma_export_config.mjs: infers product-specific addon settings and writes .storybook/figma-export.config.ts.scripts/generate_component_spec_modules.mjs: writes .storybook/figma-component-specs.ts for Open source fallback.scripts/install_figma_export_addon.mjs: copies the bundled Figma export addon into a product repo and installs it as a local file: dependency.scripts/inspect_storybook_project.mjs and scripts/validate_figma_export_setup.mjs: inspect target Storybook compatibility and validate addon wiring.references/agent-installation.md: target paths and verification checklist for Claude Code, Codex, and Cursor installation.references/figma-export-review-setup.md: troubleshooting and required wiring for the review overlay and Open source action.assets/storybook-component-queue-template.md, assets/storybook-implementation-map-template.md, and assets/figma-export-addon/: templates and vendored addon package.development
Extract a reusable design-system specification from UI screenshots/images, Figma URLs or exports, Figma Variables, existing app/project folders, or prototype code. Use when Codex must produce evidence-backed design principles, design elements, token architecture, component inventory, component token specs, anti-AI style constraints, static HTML documentation for developers, cross-agent handoff guidance for Claude Code/Cursor/Codex, and a checkpoint before any product implementation.
development
Create, apply, audit, and understand Variables in Figma using Google Material Design's three-tier token inheritance (Ref → Sys → Comp). Use when: creating Variables for components or screens, applying existing Variables to nodes, auditing token naming and structure for compliance, or having AI read existing Variables to reverse-engineer design components. Triggers: create Variables, apply Variables, Figma variables, M3 token, design token, token inheritance, token audit, audit variables, design component from variables, three-tier token.
tools
Turn screenshots or Figma exports into token-backed Storybook components and composed product screens.
tools
Turn screenshots or Figma exports into token-backed Storybook components and composed product screens.