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.
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);Installation
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/sdkconst 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.
$ 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.
retries: 3-timeout: 10s+timeout: 30s+region: eu-centralAPI
CodeBlock
| Prop | Type | Default |
|---|---|---|
codeSource text; the copy button copies it as-is. | string | — |
languageHighlighter language and accessible name ("ts code"). | string | — |
titleFile name or title in the header bar (also the code area's name). | ReactNode | — |
captionText under the block (figcaption). | ReactNode | — |
lineNumbersShow numbers; a number is the first one. | boolean | number | — |
highlightLinesMarked lines: "2,5-7" or [2, [5, 7]]. | string | (number | [number, number])[] | — |
highlightHighlighter adapter (one node per line, or HTML). false: plain text. Default: the built-in highlighter. | (code, language) => ReactNode[] | string | false | — |
htmlPre-highlighted HTML (Shiki codeToHtml…); a wrapping <pre><code> is removed. Trusted markup only. | string | — |
wrapWrap long lines instead of scrolling sideways. | boolean | — |
maxHeightCap the height; scrolls inside. | number | string | — |
copyCopy button (polite "Copied" announcement, textarea fallback). | boolean | true |
schemeA dark code window on any page. | "inherit" | "dark" | "inherit" |
actionsExtra header controls before the copy button. | ReactNode | — |
labelsDictionary namespace "codeBlock": copy, copied, copyFailed, codeIn, code, languages. | Partial<CodeBlockLabels> | — |
CodeTabs
| Prop | Type | Default |
|---|---|---|
samplesOne tab per language. | { language, label?, code, title?, html?, highlightLines? }[] | — |
groupEvery CodeTabs and useCodeLanguage with the same group shows the same language; false: independent. | string | false | "default" |
persistRemember the choice in localStorage (true: vui-code-language:<group>, string: your key). | boolean | string | — |
value / defaultValue / onValueChangeControlled language, the starting one (default: first sample) and the change callback. | string | — |
keepPositionKeep the clicked block still while blocks above it change height. | boolean | true |
…lineNumbers, highlightLines, highlight, wrap, maxHeight, copy, scheme, title, caption, labels. | CodeBlock display props | — |
Helpers
| Prop | Type | Default |
|---|---|---|
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> | — |