Atom · stable · v1.0.0 · owner: Site system lead · contract 19 of 20 points (open: figma)
Do and don't
Do: A real command
Rendered by code-block.tsOpen example: Code block · Do: A real command Use the full-page example to follow page links.
Do: A real record
Rendered by code-block.tsOpen example: Code block · Do: A real record Use the full-page example to follow page links.
Don't: Pseudo-code presented as real
Rendered by code-block.tsOpen example: Code block · Don't: Pseudo-code presented as real Use the full-page example to follow page links.
Don't: Prose in a code block
Rendered by code-block.tsOpen example: Code block · Don't: Prose in a code block Use the full-page example to follow page links.
Rules
| Rule | Why | Check |
|---|---|---|
| Code on the site is real output, or its caption says it is sample. | The site's credibility rests on showing real artefacts. | Review: Owner review of each new code block |
| A block that scrolls is focusable. | Keyboard users cannot scroll what they cannot reach. | Automated: axe scrollable-region-focusable (tests/site/pages.spec.ts) |
API
| Prop | Type | Required | Default | What it does |
|---|---|---|---|---|
code | string | Yes | The exact code. | |
lang | string | No | yaml, json, ts or text, for the class name. |
Contract details
The full contract: identity, anatomy, variants, states, tokens, layout, motion, accessibility, content, tests
Identity
| Aspect | Value |
|---|---|
| Id | code-block |
| Layer | Atoms |
| Category | typography |
| Owner | Site system lead |
| Status | stable |
| Version | 1.0.0 |
| Source | apps/showcase/site/system/atoms/code-block.ts (private repository; the contract and the render function are this one module) |
| Version | Date | Change |
|---|---|---|
| 1.0.0 | 2026-10-26 | Real records and commands in Martian Mono on the terminal ground. |
Use when
- A command the reader can run, or a record from loom/. Why: Real artefacts prove the product better than descriptions.
- A before-and-after code change. Why: The change is visible line by line.
Do not use when
- For prose or emphasis. Why: Monospace slows reading.
- For made-up code presented as real. Why: Code on the site is real output or is captioned as sample.
Anatomy
| Part | What it is |
|---|---|
| root | pre with a code child, language class language-<lang>. |
Made of: tokens:type, tokens:colour.
Used in: finding, academy-lesson, agent-check, before-after, design-md-excerpt, replay, score-us, token-chain.
Variants
| Variant | When | Why |
|---|---|---|
| terminal | Commands and records. | The dark terminal ground marks machine text. |
States
| State | Rendered or not applicable |
|---|---|
| default | default |
| hover | Not applicable: A code block is not interactive, so it has no hover state. |
| focus-visible | Scrollable blocks are focusable (tabindex=0) so keyboard users can scroll them. |
| active | Not applicable: A code block cannot be pressed. |
| disabled | Not applicable: A code block has nothing to disable. |
| loading | Not applicable: A code block is rendered at build time and is complete when the page loads. |
| empty | Not applicable: A code block is not rendered without content; the builder skips it. |
| error | Not applicable: A code block shows no data that can fail. |
| current | Not applicable: A code block has no current item. |
| visited | Not applicable: A code block is not a link. |
| expanded | Not applicable: A code block does not open or close. |
Tokens
| Part | Token |
|---|---|
| root.background | --term-bg |
| root.color | --term-fg |
| root.font | --font-mono, --fs-small, line height 1.6 |
| root.padding | --space-7 |
| root.radius | --radius |
Layout
| Aspect | Value |
|---|---|
| breakpoints | Required review at 390, 768, 1024 and 1440 px; execution is not implied by this declaration; wraps under 900 px, scrolls sideways above. |
| wrapping | pre-wrap with anywhere breaks on phones; pre on wide screens. |
| textExpansion | Code is not translated; Japanese pages caption it. |
Spacing and rhythm
| Aspect | Value |
|---|---|
| internal | --space-7. |
| external | --space-6 above and below in prose. |
| rhythm | Inside prose or a panel. |
Motion
| Aspect | Value |
|---|---|
| None | Static. |
Runtime and reuse
Render-only element; mount any registered child enhancements separately. Preserve required Site CSS, fonts, responsive and locale rules from nativeElement.
Accessibility passport
| Aspect | Value |
|---|---|
| role | code (pre) |
| name | Labelled by its caption when in a figure |
| keyboard | Focusable when it scrolls. |
| focus | In reading order. |
| screenReader | Read as text. |
| contrast | --term-fg on --term-bg 13.2:1. |
| target | Not a target. |
Content
| Slot | Length | Voice |
|---|---|---|
| code | 30 lines | Exact, unedited output |
Good: “npm run audit -- --project harbor”
Bad: “// pseudo-code that looks real”
Japanese: Code stays in English; Japanese pages say 「チェック結果は英語で表示されます」 nearby.
Icons and illustrations
None: this element uses no icon or illustration of its own.
Decisions and exceptions
Usage
16 uses across the built pages (measured by npm run site:system).
Shared styles
Base styles the code font; the .prose context supplies the pre surface, padding, wrapping and focusable scroll region.
apps/showcase/site/system/styles/core/base.cssapps/showcase/site/system/styles/site/text.css
Remaining review: Twelve existing positive specimens pass light/dark 320/390/1440 surface, focusability and overflow checks; keyboard scrolling and manual AT review remain open.
Tests
| Aspect | Value |
|---|---|
| unit | tests/unit/site-system.test.ts: renders every do and don't example through the registry and checks the classes it owns |
| visual | Not yet: there are no screenshot baselines; the Library page is checked for sideways scroll at 1440 px by tests/site/system.spec.ts |
| a11y | tests/site/system.spec.ts: axe (0 serious or critical) on the element's Library page in light and dark |
| parity | scripts/site/system/check.ts: Library examples are rendered by the same render function the site imports |
Figma
not-yet: The Loom Site Figma library is the last stage of the plan; this element is not mapped yet.