Axon 911 Frontend DocsAxon 911 Frontend Docs
Axon 911 Frontend Docs
    Loading navigation…
U
User
Switch to light mode
  1. Components
  2. Code Block
  3. Usage

Code Block

Usage

CodeBlock shows source code: the language as a label, a copy control, and syntax highlighting. It is the block a model's fenced code becomes inside Response, and it works on its own for any code sample.
code is data and language is an id, so both are plain strings. label names the block, and the three copy labels name the copy control in its three states. Pass showCopy={false} and leave the copy labels out to drop the control.
When to use
  • A code sample, a command, a configuration file or a diff in a chat reply or a help page.
  • Fenced code from Markdown, through Response.
When not to use
  • A single token or identifier inside a sentence: use Text with as="code".
  • A value the reader should copy and nothing else, such as an incident ID: use CopyButton.
  • Editable code: CodeBlock is read-only.
Languages
bash, css, diff, go, html, java, javascript, json, jsonc, jsx, markdown, python, rust, sql, toml, tsx, typescript, xml and yaml, plus the common aliases (ts, js, sh, shell, zsh, yml, md, py, rs, golang, htm, svg, patch). The case does not matter, and a language- prefix is accepted. A language outside the list, or no language, leaves the code plain. The label still shows the language as written. Code past 100,000 characters stays plain too, because tokenizing runs on the main thread.
Plain first, then highlighted
The first render, including the server render, is the code as plain text. The highlighter and the grammar for the language load on first use, and the code is repainted in place when they arrive. The text never changes, so the layout does not move and the code is readable and copyable the whole time. While the highlight is being made the block carries the loading state (data-loading), which stories and tests wait on. When the code grows (a streaming reply), the block keeps the earlier highlight, appends the new text plain, and re-highlights. It never falls back to plain and back.
Colors
Tones are painted from Chroma foreground tokens, so one markup serves light and dark and nothing is computed per theme. There are no syntax tokens in Chroma yet, so keywords and links share --color-fg-link, strings and added lines use the success foreground, constants the warning foreground, functions the informative foreground, deleted lines the destructive foreground, and comments and punctuation the subtle foreground. Under forced colors every tone is the system text color.
Layout
The code never wraps. A line wider than the block scrolls along the inline axis in a focusable region named by label. Code reads left to right whatever the page direction: the code region is a left-to-right run, so lines stay in order and flush left under RTL. The header follows the page direction.
Previous
Checkbox Cards / Accessibility
Next
Code Block / API and Development
On this page
When to use
When not to use
Languages
Plain first, then highlighted
Colors
Layout