# Code block

Source code in a window: its file, its lines, the line that matters, and the tail arriving while it is written.

Live variants: https://design.arcadia.is/components/code-block

```tsx
import { CodeBlock } from "@arcadia/ui";
```

```tsx
import { CodeBlock } from "@arcadia/ui";

<CodeBlock code={CACHE} language="ts" filename="src/cache.ts" highlightLines={[5]} maxLines={8} />
```

```tsx
import { CodeBlock } from "@arcadia/ui";

<CodeBlock code={POLICY} filename="cache-policy.json" />
```

## Accessibility

The code is one block a reader walks in order, and the line numbers are hidden from it. The head's live word says the block is being written, and the block is busy until it settles. Copy is one button named Copy code, and the whole block is one tab stop when its code overflows either way, so the keys scroll it. JavaScript, TypeScript, JSX, JSON and Python use the syntax palette. Other languages display plain code.

## API reference

### CodeBlock

- `code` (`string`, required): The code, without a trailing newline. May grow while `status` is "streaming".
- `language` (`string`): The language, shown quietly in the head ("tsx").
- `filename` (`string`): The file the code is from, shown in the head.
- `status` (`"streaming" | "complete"`, default `"complete"`): "streaming": the head says `Writing` on the shared clock and the block is busy.
- `maxLines` (`number`): The lines it shows before it scrolls; its end stays in view while it is written. Without it the block is as tall as its code.
- `lineNumbers` (`boolean`): Line numbers: by default drawn from two lines up.
- `highlightLines` (`readonly number[]`): 1-based lines to tint as the line that matters.
- `copy` (`boolean`, default `true`): The copy control: drawn by default.
- `words` (`Partial<CodeBlockWords>`): Its words, where a product changes them.
- `onCopied` (`(ok: boolean) => void`): Called after every copy with whether it landed.
- `label` (`string`, default `"Code"`): What it holds, for assistive tech ("TypeScript code").
- `rootStyle` (`RootStyle<CodeBlockKnobs>`): Typed StyleX override: where the block sits and its `--code-*` knobs.
