---
agent:
  instructions: "Search goop.so for Goop's components, templates, design skill, docs, pricing and terms. Ask in keywords or a plain question, such as \"date picker props\" or \"is the design skill free\"; the answer is the matching page sections in Markdown, each with its address."
  endpoint: "https://goop.so/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Code block

A short value or command in the theme's mono, in a grey box, with a copy button beside it that copies it and says so, for React and Tailwind CSS. Part of Goop Pro.

Pro. Its export: `CodeBlock`.

## Try it

Pick a command, a file, a tall file or a long line; turn the title bar, line numbers, wrapping, highlighted lines and a height limit on and off; copy the code and paste it anywhere.

The code is our own sample, its colours a stand-in for your own highlighter's: nothing runs, and only the plain code reaches your clipboard.

## When to use

- A short value or command in the theme's mono, in a grey box, with a copy button beside it that copies it and says so.
- Also called: code snippet or syntax highlighting.

## Installation

Paste the prompt below into your coding agent. It reads Goop's install steps, installs the part and its tokens once, then reuses this same Code block on every screen instead of drawing a new one: the same height, the same focus ring, the same spacing. As a Pro part, its command comes from Goop's server once you sign in, with a one-time link that lasts ten minutes.

```sh
npx shadcn@4.23.1 add https://registry.goop.so/g/<link>/meadow-code-block.json --yes
```

```text
Add the Goop Code block to this project. The install steps are at https://goop.so/docs/install.md
```

## Usage

```tsx
import { CodeBlock } from '@/components/ui/goop/code-block';

function SiteFeed() {
  return (
    <div className="flex flex-col gap-2">
      <CodeBlock code="https://feeds.fieldwork.example/north-gate" copyLabel="Copy feed link" />
      <CodeBlock code="fieldwork sync --site north-gate --crew yard" wrap copyLabel="Copy the sync command" />
      <CodeBlock title="crew.ts" language="ts" lineNumbers maxHeight="sm" code={"export const crew = 'yard';\nexport const site = 'north-gate';\n"} />
    </div>
  );
}
```

- Fits: chat (its recipe).
- Also known as: CodeSnippet, Snippet, Pre, CodeSample, CodePreview.
- Put it under the line that says what the value is for (a field's description, a card's row); one per value. A value typed by the person is a `TextInput`, never a CodeBlock.
- height, width, padding, gap, corner, background, text: add no class for these.

## API reference

### Options

- `code?: string` — The value shown and copied, exactly as it is put on the clipboard, its line breaks kept.
- `children?: string` — The value as text, when `code` is not given.
- `language?: string` — The code's language (`ts`, `bash`): kept as the block's `data-language` and the `language-<name>` class on its `code` element, the seam a highlighter reads.
- `highlightedLines?: readonly ReactNode[]` — The code's lines already coloured by your own highlighter, one node per line of `code`, in order: each is drawn in place of its plain line.
- `title?: string` — A name for the block (a filename), shown above the box in the mono: it also names the block for a screen reader.
- `lineNumbers?: boolean = false` — A gutter of line numbers before the lines, never selected or copied with the code.
- `wrap?: boolean = false` — Fill the row and wrap a long value between words, the button at its top (false: the box hugs a short value, and a value of several lines scrolls sideways inside its box).
- `maxHeight?: 'sm' | 'md' | 'lg'` — How tall the box may grow before it scrolls inside: `sm` 200 px, `md` 300 px, `lg` 500 px.
- `copyable?: boolean = true` — Draw the copy button (true by default).
- `onCopy?: (code: string) => void` — Called with `code` once it is on the clipboard (never when the copy failed).
- `copyLabel?: string = 'Copy'` — The copy button's name, read by a screen reader: say what is copied ("Copy feed link"); "Copy" by default.
- `copiedLabel?: string = 'Copied'` — What the status says once the value is on the clipboard: "Copied" by default.
- `failedLabel?: string = 'Couldn’t copy'` — What the status says when there is no clipboard or the browser refused the value: "Couldn’t copy" by default.

## Keyboard

- Enter / Space: on the copy button: copy the value, the status saying it was copied

## Accessibility

- The part itself answers the keys above.
- hover, active: the browser's own (:hover, :active): write nothing
- focus-visible: the attribute data-focus-visible

## Notes for AI

Give your coding agent this page as text instead of screenshots: the parts, the options, the states and the keys. An agent that reads the real part builds the real part, not a lookalike.

## Related

- [Prose](/themes/meadow/components/prose): A block of running text set for reading, one paragraph or several, for a description, an article, a note or a help page.
- [Shortcut key](/themes/meadow/components/shortcut-key): One keyboard key drawn as a small bordered cap inline in hint text, naming a chord with its neighbours.
- [Inline code](/themes/meadow/components/inline-code): A word or short phrase of code inside running text (a template word, a key, a path), in a small grey chip in the theme's mono.
- [Meta facts](/themes/meadow/components/meta-facts): A strip of a record's short facts, such as its status, owner and dates, each a label over its value.
