Add docs and demos
@codeui/solid v0.3.0
Write a component page and its Solid demos.
The docs site lives in apps/docs and uses Fumadocs. Pages are MDX files under apps/docs/content/docs/(kit)/. Live examples are Solid components in packages/docs-demos. The build renders each demo on the page, prints its source under it, and puts the same source in the page's Markdown route for agents.
Start from the page template
pnpm docs:scaffold
node tools/docs/scaffold.mjs --print components/badgepnpm docs:scaffold writes the sidebar meta.json files and a draft stub for every planned page that has no file yet. It never overwrites a page. The planned pages live in tools/docs/ia.mjs. --print <slug> prints one stub without writing it.
A component page has these sections, in this order:
- When to use
- When to choose another component
- Live demo
- Anatomy
- Variants
- States
- Ready API
- Styled parts API
- Styles export
- Accessibility
- SSR notes
- Theming hooks
- Composition examples
- Related
Each section holds a TODO comment that says what goes in it. Fill the section, then delete the comment. When the page has no TODO left, delete status: draft from the front matter. pnpm docs:coverage fails on a page that has no status: draft but still holds a TODO comment. Remove a section only when the component has nothing for it, such as States on a presentational component.
Write a demo
import { Button, createToaster, Toaster } from "@codeui/solid";
export default function ToastBasic() {
const notifications = createToaster();
return (
<>
<Button
variant="primary"
onClick={() =>
notifications.show({ tone: "success", description: "Snippet exported as PNG." })
}
>
Export
</Button>
<Toaster toaster={notifications} closeLabel="Dismiss" />
</>
);
}- Create
packages/docs-demos/src/demos/<page>/<name>.tsxwith a default export. - Render it on the page with a
SolidDemoelement whosenameis<page>/<name>. The Toast page usesname="toast/basic"for the demo above.
There is no registry. The client and server bundles find demos with import.meta.glob. The build fails when the file is missing or when one page uses the same name twice. Hydration needs one name per page.
- Write one demo per variant axis and one per distinct state. Add composition demos that show the component in a real screen.
- Use CodeImage content, such as snippet names, export formats, and editor settings. Do not use "foo" and "bar".
- Import ready components from
@codeui/solidand parts as a namespace from@codeui/solid/<name>. Copy what an app would write. - Follow the same rules as kit code. Read values from
--cui-*tokens. Give every control an accessible name. - A demo can import a plain
.cssfile next to it. The page does not print imported CSS, so paste it under the demo in acsscode block with atitle. - Add
source="hidden"toSolidDemoonly for a demo whose code teaches nothing, such as a token swatch grid. - Never write a literal
SolidDemoorPropsTabletag in a code block or in inline code. The build expands only real elements, and the Markdown route check fails on a tag left in the text.
Every code example on a page must be a demo file that type-checks, or an exact copy of one. That rule keeps examples from going stale. Check your demos with:
pnpm --filter @codeui/docs-demos exec tsc --noEmit -p .Write a props table
import type { BadgeProps } from "@codeui/solid";
import type { RootProps, IconProps, LabelProps } from "@codeui/solid/badge/parts";
import type { PropNotes } from "./notes";
export type Badge = Pick<
BadgeProps,
"tone" | "size" | "variant" | "icon" | "classes" | "class"
>;
export type BadgeInherited = Pick<BadgeProps, "textValue">;
export type BadgeRoot = Pick<RootProps, "tone" | "size" | "variant" | "class">;
export const notes = {
Badge: {
tone: { default: '"neutral"', description: "Semantic status color." },
size: { default: '"sm"', description: "Visual size." },
// …
},
} satisfies PropNotes;apps/docs/scripts/generate-props.mjs reads every exported type alias in packages/docs-demos/src/props/*.ts and writes apps/docs/.generated/props.json. A PropsTable element renders the alias named in its name attribute, such as name="Badge", as a Fumadocs type table. The page's .md route gets the same rows as a Markdown table.
The generator keeps each shown type short:
-
A union of literals is spelled out when it has at most 6 members and 60 characters, such as
"sm" | "md" | "lg". -
Any other type shows the shortest of the type as the kit source wrote it, the union, and the resolved type. A polymorphic
asshowsValidComponent, and an option key showskeyof Option. -
A kit alias name, such as
GaporSelectClasses, links to its declaration. The full type opens under the row. -
The build fails when a shown type is longer than 80 characters. Set
typein the prop's note to a shorter form. The table keeps the full type under the row. -
Import kit symbols with
import typeonly. The generator loads these files in Node, and a runtime import of@codeui/solidcrashes it. -
Export one
Pick<…>projection per ready export and one per styled part. Keep only the props the kit adds or changes. -
Add a
<Name>Inheritedprojection for the Kobalte props that change behavior, such asopenoronChange. Link the Kobalte page for the rest. -
Put the default and a one-line description of each prop in
notes, keyed by projection name. The description from the JSDoc comment is used when the note has none. -
Put a
SolidDemoorPropsTableelement on its own line. Inside a paragraph it breaks hydration, and the build fails.
The generator needs a kit build. Run pnpm build:kit, then pnpm --filter @codeui/docs props.
Fill the reference sections
- Anatomy. A table with the columns Export, Renders,
classeskey,data-cui, and Role. Copy eachdata-cuivalue from the<name>Partsmap inpackages/kit/src/parts/<name>.tsx. Never derive one from the export name, because some do not match, such asselectfor theSelectroot. - Accessibility. A keyboard table with the columns Key and Action. Then the roles and ARIA attributes the component renders, and where focus goes on open and on close.
- Theming hooks. The
--cui-*properties the component reads. Find them in its.css.tsfile, and check each name against Tokens. - SSR notes. What renders on the server. Portalled content, for example, renders only on the client.
Follow the voice
The pages follow the Inkstone docs in apps/docs/content/docs/design/.
- Write short declarative sentences in plain English. Address the reader as "you".
- Put the code first and the explanation after it.
- Each section answers one question.
- Use no marketing words and no long dashes. Do not join two clauses with a colon in the middle of a sentence. A colon before a list is fine.
Check the page
The build fails on a missing demo, a repeated demo name, a demo or props table inside a paragraph, a props table with no projection, or a prop type longer than 80 characters. Run these checks before you open the pull request:
| Check | Command | Fails when |
|---|---|---|
| Demo types | pnpm --filter @codeui/docs-demos exec tsc --noEmit -p . | A demo does not compile. |
| Demo references | node tools/docs/lint-demos.mjs | A SolidDemo points at a missing file, or a name repeats on a page. |
| Internal links | node tools/docs/lint-links.mjs | A /docs/… link has no page. |
| Export coverage | pnpm docs:coverage | A public export has no anchor on a page. --strict also fails on drafts. |
| Markdown routes | pnpm docs:check-llms <url> | A page's .md route is missing, or still holds a SolidDemo or PropsTable tag. |
| Rendered pages | node tools/docs/crawl.mjs <url> | A page logs a console error, a demo renders nothing, a block demo is shrink-wrapped, or a page scrolls sideways at 390 px. |
pnpm docs:lint runs both lints, and the Docs workflow runs it on every pull request.
The crawl loads every prerendered page in dark and light at 1440 and 390 px. Build with NITRO_PRESET=cloudflare-pages, serve with pnpm --filter @codeui/docs exec wrangler pages dev dist, and install Playwright once with npm ci --prefix tools/baseline.
docs:coverage reads the kit's emitted declarations, so run pnpm build:kit first. docs:check-llms needs a running site. Build it with pnpm --filter @codeui/docs build, start it with PORT=6150 node apps/docs/.output/server/index.mjs, and pass http://localhost:6150.
When a page documents a new export, map the export to its anchor in apps/docs/export-manifest.json. node tools/docs/coverage.mjs --add proposes the entries.