Component Catalog Pipeline
How co-located UI stories and optional component docs become the styleguide catalog.
Story files are the catalog input
Component catalog entries start in packages/. Each story file is co-located with the component it documents and exports:
a default
StoryMetaobject with title, category, description, usage, and optional order;one or more named
Story<P>exports with a pure synchronousrenderfunction;optional
controlsmetadata and optional explicitsourcestrings for code panels.
The catalog renders stories during static build, so story rendering must not depend on browser globals, timers, network calls, or async data.
Codegen replaces runtime globbing
The catalog does not discover stories with import.meta.glob at runtime. zfb does not inline that call into shared client islands, so the @takazudo/zudo-sg engine's CLI uses code generation instead.
zudo-sg gen-registry — shipped by the engine (packages/styleguide) and driven by the host's zudo-sg.config.mjs (componentsRoots, registryOut, categoryOrder) — scans packages/ (any nesting depth) and regenerates explicit import registries:
src/for the root styleguide catalog.styleguide/ sg- registry. ts packages/for story contract and drift tests.demo- ui/ src/ stories/ _ _ tests_ _ / story- modules. ts
The first write does not require a hand-created seed: a missing or whitespace-only registryOut is bootstrapped as the complete generated file, including its parent directories. A non-empty file without the generated markers is rejected so hand-authored content is never overwritten. The --check form reports a missing or empty registry as drift without creating or modifying anything.
After adding, renaming, or deleting a story file, run:
pnpm gen:sg-registryCI and local quality gates run:
pnpm check:sg-registryThat check fails when the generated registries no longer match the story files on disk. Both pnpm scripts wrap the same zudo-sg CLI command (gen-registry / gen-registry --check); see Quality Gates.
Generated blocks
Do not hand-edit code between GENERATED:SG_REGISTRY_BEGIN and GENERATED:SG_REGISTRY_END. Regenerate it from the story files.
Optional component MDX
Quick reference content lives in story metadata. When a component needs more guidance, add an optional MDX file next to the component and story:
packages/demo-ui/src/cards/card/card.tsx
packages/demo-ui/src/cards/card/card.stories.tsx
packages/demo-ui/src/cards/card/card.mdxwithZudoSg() (zfb.config.ts) adds one componentDocs content collection per componentsRoots[] entry, rooted at that entry's dir (packages/ here), so zfb compiles those MDX files as part of the normal build. The engine's / detail route (packages/) looks up the matching MDX entry in the collection of the components root the story's registry key belongs to, from the same component path the story registry uses, so there is no separate registration step.
Authoring checklist
When adding a component, ship the component, story, tests, exports, and any optional MDX docs together. Then run the focused checks from Quality Gates: typecheck, unit tests, token lint, and story registry drift detection.