Draft. Ported from the shadcn-vue Code Block (registry style reka-nova, read 12 November 2026). Not yet approved; the API may still change.
A code block shows code, a payload or a log as it is, in a monospaced font, so people can read and copy it. It can have a title, actions, line numbers, highlighted lines and diff lines.
When to use
- Payloads and responses: a webhook body, an API error.
- Snippets people paste: a command, a config file.
- Changes: a mapping before and after, as added and removed lines.
When not to use
- For one ID, key or URL. Show it as text in
font.code.defaultwith a copy button beside it. - For code people edit. Use an editor.
- For a short message. Write it as a sentence; an error people must act on belongs in an alert.
Parts
| Part | What it does |
|---|---|
CodeBlock |
The frame. variant: default or destructive; size: default or sm |
CodeBlockHeader, CodeBlockTitle |
A line above the code with a file name or a short title |
CodeBlockActions |
Buttons. In the header they sit at the end; straight in CodeBlock they float in the corner |
CodeBlockCopyButton |
Copies value. Its name is a tooltip; after a click a check shows for 2 s |
CodeBlockContent |
The scrolling code. lineNumbers, startLine, wrap |
CodeBlockLine |
One line. variant: default, added, removed, highlighted |
CodeBlockToken |
One highlighted token from useHighlightedCode |
CodeBlockFooter |
A line below the code, such as the run and time |
Content
- Show code exactly as it is. Don’t cut lines; use
wrapwhen the block is narrow. - Give the copy button a name that says what it copies: “Copy payload”.
- In a diff, the signs and colours both mark a line; keep the signs.
Tokens
The block uses the editor roles, so it follows the light and dark theme.
| Part | Tokens |
|---|---|
| Frame | editor.background, editor.border, radius.card; destructive color.border.danger |
| Code | font.code.default, editor.text; padding space.150 (space.100 when sm) |
| Highlighting | editor.syntax.comment, .string, .number, .keyword, .type, .delimiter |
| Line numbers | editor.lineNumber |
| Lines | highlighted editor.lineHighlight; added editor.diff.inserted.*; removed editor.diff.removed.* |
| Header, footer | color.text.subtle; title font.label.default, color.text |
| Focus | border.width.focused, color.border.focus, state.focus.offset, as Button |
Related
- Icon button: the copy button is one, named by its tooltip.