ComponentsData display

Code block & tabs

Highlighted code with a file name, line numbers, marked lines and a copy button that works where the clipboard is blocked. CodeTabs shows one snippet in several languages, and the language picked in any of them switches every other block on the page (and is remembered per browser if you want). A small built-in highlighter colours with tokens only; Shiki or Prism output plugs in through an adapter or pre-highlighted HTML.

WAI-ARIA Tabs (CodeTabs) components/code-block.tsxtheme · material · accent · density · font
send-event.ts
import { createClient } from "@example/sdk";​const client = createClient({ apiKey: process.env.EXAMPLE_KEY });​// Send the first event and wait for the receipt.const receipt = await client.events.send({ type: "order.paid", amount: 4200 });console.log(receipt.id);
Lines 5–6 send the event; the receipt id is logged.

Installation

$ pnpm add @vamos-ui/react

The whole kit as one package — get updates by bumping the version. Add the styles to globals.css: @import "@vamos-ui/react/styles.css";

Usage

import { CodeBlock, CodeTabs, useCodeLanguage } from "@vamos-ui/react";

<CodeBlock title="send.ts" language="ts" code={source} lineNumbers highlightLines="3-4" />
<CodeTabs persist samples={[
  { language: "ts", label: "TypeScript", title: "send.ts", code: ts },
  { language: "python", label: "Python", title: "send.py", code: py },
]} />

// Anything else that follows the same choice (install line, SDK table):
const [language] = useCodeLanguage("default", { persist: true });

// Shiki (server): pass the HTML; each line stays its own row.
<CodeBlock code={source} html={await shiki.codeToHtml(source, { lang: "ts", theme })} lineNumbers />

The code area is a focusable, named group so keyboard users can scroll long lines; line numbers are aria-hidden and not selectable.

Colours come from tokens (accent-ink, success-ink, warning-ink, info-ink, fg-subtle), so the code follows theme, accent and dark mode.

The built-in highlighter is deliberately small (comments, strings, numbers, keywords, calls). For full grammars use Shiki on the server and pass html.

Examples

Language tabs that sync

Two CodeTabs and an install line share group "docs-sdk"; persist remembers the choice. The block you click stays still while others change height.

npm install @example/sdk
const receipt = await client.events.send({ type: "order.paid" });
if (!client.webhooks.verify(body, signature)) throw new Error("bad signature");

Dark window, wrapping, plain text

scheme="dark" on a light page; wrap for long JSON; highlight={false} for terminal output.

Terminal
$ example deploy --env productionUploading 14 files (2.1 MB)Build finished in 38 sLive at https://preview.example.com
{ "id": "evt_01", "type": "order.paid", "data": { "amount": 4200, "currency": "EUR", "note": "Long values wrap onto the next line instead of scrolling the block sideways." } }

Your own highlighter

A highlight function returns one node per line (or an HTML string); line numbers keep working.

config.diff
 retries: 3-timeout: 10s+timeout: 30s+region: eu-central

API

CodeBlock

PropTypeDefault
code
Source text; the copy button copies it as-is.
string—
language
Highlighter language and accessible name ("ts code").
string—
title
File name or title in the header bar (also the code area's name).
ReactNode—
caption
Text under the block (figcaption).
ReactNode—
lineNumbers
Show numbers; a number is the first one.
boolean | number—
highlightLines
Marked lines: "2,5-7" or [2, [5, 7]].
string | (number | [number, number])[]—
highlight
Highlighter adapter (one node per line, or HTML). false: plain text. Default: the built-in highlighter.
(code, language) => ReactNode[] | string | false—
html
Pre-highlighted HTML (Shiki codeToHtml…); a wrapping <pre><code> is removed. Trusted markup only.
string—
wrap
Wrap long lines instead of scrolling sideways.
boolean—
maxHeight
Cap the height; scrolls inside.
number | string—
copy
Copy button (polite "Copied" announcement, textarea fallback).
booleantrue
scheme
A dark code window on any page.
"inherit" | "dark""inherit"
actions
Extra header controls before the copy button.
ReactNode—
labels
Dictionary namespace "codeBlock": copy, copied, copyFailed, codeIn, code, languages.
Partial<CodeBlockLabels>—

CodeTabs

PropTypeDefault
samples
One tab per language.
{ language, label?, code, title?, html?, highlightLines? }[]—
group
Every CodeTabs and useCodeLanguage with the same group shows the same language; false: independent.
string | false"default"
persist
Remember the choice in localStorage (true: vui-code-language:<group>, string: your key).
boolean | string—
value / defaultValue / onValueChange
Controlled language, the starting one (default: first sample) and the change callback.
string—
keepPosition
Keep the clicked block still while blocks above it change height.
booleantrue
…
lineNumbers, highlightLines, highlight, wrap, maxHeight, copy, scheme, title, caption, labels.
CodeBlock display props—

Helpers

PropTypeDefault
useCodeLanguage(group?, { persist? })
Read or set the shared language from anything else on the page.
[language | undefined, set]—
highlightCode(code, language)
The built-in tokenizer: lines of { kind, text }.
CodeToken[][]—
copyText(text)
Clipboard with a textarea fallback.
Promise<boolean>—