Code block

Shows source text with optional line numbers, wrapping, and copy feedback.

JavaScript
const total = 42;
TypeScript
const range = 386;
const unit = "km";

Use it for

  • Installation commands, code samples, and technical documents.

Not for

  • Comparing revisions; use DiffViewer.

Three ways in. They share one source, so the pixels match whichever you pick.

1. Import the package

npm install @noorddev/vlak-react

// once, next to your app's root
import "@noorddev/vlak-react/css";

import { CodeBlock } from "@noorddev/vlak-react";

Precompiled React and one stylesheet. No compiler to configure. Per-component imports work too: @noorddev/vlak-react/components/code-block.

2. Vendor the source

npx @noorddev/vlak-cli add code-block

The StyleX leaf lands in components/vlak/ with its dependencies, for your own compiler to own. See StyleX.

3. Through shadcn

npx shadcn add https://vlak.dev/r/code-block.json

The same registry item, installed by shadcn's CLI.

CSS only

<link rel="stylesheet" href="node_modules/@noorddev/vlak/css/vlak.css" />

No React. Link vlak.css and use the markup and classes below.

import { CodeBlock } from "@noorddev/vlak-react";

<CodeBlock language="TypeScript" code={"const range = 386;\nconst unit = \"km\";"} lineNumbers />

CodeBlock

Plain source with optional numbering and honest asynchronous copy feedback.

PropTypeDefaultDescription
coderequiredstring
languagestring"Text"
lineNumbersbooleanfalse
wrapbooleanfalse
copyablebooleantrue
onCopyCode(code: string) => void | Promise<void>

Also accepts HTMLAttributes<HTMLElement>.

KeysDoes
Tab, Enter, SpaceTab reaches the copy action and scrollable source; Enter or Space copies.
<figure class="rs-code-block"><figcaption class="rs-code-block-header">TypeScript</figcaption><pre class="rs-code-block-pre" tabindex="0" aria-label="TypeScript source"><code>const range = 386;</code></pre></figure>
.rs-code-block.rs-code-block-header.rs-code-block-pre.rs-code-block-wrap.rs-code-block-line.rs-code-block-number.rs-code-block-status