Skip to content

CodeBlock

Config snippets and terminal commands, highlighted on the server, with a wrap toggle and a copy button.

DataIsland

Examples

Config file

The filename is the header label; the language shows next to it.

.mcp.jsonjson
{
  "mcpServers": {
    "switchboard": {
      "type": "http",
      "url": "https://sb.example.dev/mcp/u_7f3k2"
    }
  }
}
Example
<CodeBlock filename=".mcp.json" language="json" code={config} copyLabel="Copy config" />

Terminal command

Without a filename the header falls back to the language label, "Terminal" for shell. Turn on Wrap for long lines.

Terminal
claude mcp add --transport http switchboard https://sb.example.dev/mcp/u_7f3k2
Example
<CodeBlock
  language="shell"
  code="claude mcp add --transport http switchboard https://sb.example.dev/mcp/u_7f3k2"
  copyLabel="Copy command"
/>

TOML, wrapped

~/.codex/config.tomltoml
[mcp_servers.switchboard]
url = "https://sb.example.dev/mcp/u_7f3k2"
bearer_token_env_var = "SWITCHBOARD_TOKEN"
Example
<CodeBlock filename="~/.codex/config.toml" language="toml" code={config} wrap />

Bare

No header strip: no label, wrap toggle or copy button.

search_tools(query: string) -> Tool[]
Example
<CodeBlock bare language="text" code="search_tools(query: string) -> Tool[]" />

Usage

Usage
import { CodeBlock } from '@switchboard/ui'

<CodeBlock filename=".mcp.json" language="json" code={JSON.stringify(config, null, 2)} />

Props

Every component also takes mix, for css() and mixins applied after its own style.

CodeBlock

CodeBlock props
PropTypeDefaultDescription
code*string–The source text. Also what the copy button copies.
language'json' | 'shell' | 'toml' | 'text''text'Server-side highlighter to use. text is not highlighted.
filenamestring–Header label. Falls back to the language name (JSON, Terminal, TOML, Text).
copyLabelstring'Copy'Accessible name and tooltip of the copy button.
wrapboolean–Start with long lines wrapped instead of scrolling.
bareboolean–Hide the header strip.

Also accepts every <figure> attribute.

Accessibility

  • Renders a <figure> with the label as its <figcaption>; the <pre> is focusable (tabindex="0") and named by the label so it can be scrolled with the keyboard.
  • The wrap toggle is a real checkbox named "Wrap long lines" and works without JavaScript.
  • The copy button announces "Copied to clipboard" through a polite live region.

Guidance

Do

  • Name the file the snippet belongs in, so people know where to paste it.
  • Use the full, real value (the trunk URL, not a placeholder) when you have it.

Don’t

  • Put a secret token in a code block; use a secret input.
  • Use a CodeBlock for a single identifier inside a sentence; use InlineCode.