Skip to main content
  1. Docs
  2. Components
  3. Data display

Code block

Code to read and copy: a command, a snippet, a JSON event or XML metadata, coloured, with one Copy button.

Import
@qeetrix/react/experimental
Status
ExperimentalSince 0.0.6
Renders
<pre>Server-rendered
Tested
WCAG 2.2 AAaxe on every pull request

01

When to use

Use it for
  • A command to run: bun add @qeetrix/react.
  • A snippet, a webhook event, SAML metadata.
Not for

02

Anatomy

  1. 1code-block-header<div>The title or the language, and Copy: for more than one line.
  2. 2copy<button>"Copy code": the code exactly, never the line numbers.
  3. 3region<section>The code: a named region that takes focus, so long lines scroll by keyboard.
  4. 4code<pre>Monospace, coloured by the code tokens; ligatures off.

03

Do and don't

The code as it's copied
DoExactly what runs: no prompt, no output.
Don'tA $ prompt and the output: Copy takes them too.
Name the language
Dolanguage: it's coloured, and the header says what it is.
Don'tLeft as text: no colours, and no name.

04

Content

  • The code exactly as it should run or be pasted.
  • A title for a file or an event: qeet-id.config.ts, user.signed_in.
  • Short: the lines that matter, not a whole file.
Next — Code blockAPI