Theme
Install with your agentnpx shadcn@4.23.1 add https://registry.goop.so/g/<link>/trail-code-block.json --yes

Code block

Pro

A block of code or a command with a copy button, for React and Tailwind CSS. Part of Goop Pro.

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 block of code or a command with a copy button.
  • Also called: code snippet or syntax highlighting.

When not to use

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.

Terminal
npx shadcn@4.23.1 add https://registry.goop.so/g/<link>/trail-code-block.json --yes
PROMPT
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 Snippets() {
  const code = "export const ledger = {\n  currency: 'EUR',\n};\n";
  // your highlighter's tokens for `code`, one list per line (made on your server; written out here)
  const tokens = [
    [{ content: 'export const', color: 'var(--code-keyword)' }, { content: ' ledger = {' }],
    [{ content: '  currency: ' }, { content: "'EUR'", color: 'var(--code-string)' }, { content: ',' }],
    [{ content: '};' }],
  ];
  return (
    <div className="flex flex-col gap-4">
      <CodeBlock code="ledger serve --port 4400" language="bash" />
      <CodeBlock
        title="ledger.config.ts"
        language="ts"
        lineNumbers
        code={code}
        highlightedLines={tokens.map((line) =>
          line.map((token, index) => (
            <span key={index} style={{ color: token.color }}>
              {token.content}
            </span>
          )),
        )}
      />
    </div>
  );
}
  • Fits: chat, settings (their recipes).
  • Also known as: CodeSnippet, Snippet, Pre, CodeSample, CodePreview.
  • Use a CodeBlock for any code or command a person reads or copies whole — an install line, a config file, an API call; a word of code inside a sentence is an InlineCode, and a single value to paste (a key, a link) is a read-only TextInput with a CopyButton at its end.
  • height, width, padding, gap, corner, border, background, text: add no class for these.

API reference

Options
OptionTypeWhat it does
code?stringThe code, exactly as it is copied: its spaces, tabs and line breaks kept.
children?stringThe code as text, when code is not given.
language?stringThe 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 (its tokens as spans with their colours): each is drawn in place of its plain line, with the numbers, the wrap, the fades and the copy button working as before.
title?stringA name for the block, shown in a bar on top (a filename): it also names the body for a screen reader.
lineNumbers?boolean = falseA gutter of line numbers, never selected or copied with the code.
wrap?boolean = falseLong lines wrap inside the block; left out, they scroll sideways inside it (never the page).
maxHeight?'sm' | 'md' | 'lg'How tall the block may grow before it scrolls inside: sm 200 px, md 300 px, lg 500 px.
copyable?boolean = trueThe copy button: it copies exactly code.
onCopy?(code: string) => voidCalled with the code once it is on the clipboard (never when the copy failed).
copyLabel?string = 'Copy code'The copy button's spoken name.
copiedLabel?stringThe word the copy button shows once the code is copied; Copied by default.
failedLabel?stringThe word the copy button shows when the copy failed; Couldn’t copy by default.

Keyboard

KeyWhat it does
TabReach the copy button and, while it scrolls, the body, in the block's order: under a title bar the button first; with no bar the body first, the button beside its first line after it
EnterOn the copy button: copy the code; the focus stays on the button
SpaceOn the copy button: copy the code; the focus stays on the button
ArrowLeft ArrowRight ArrowUp ArrowDownOn the scrolling body: scroll the code

Accessibility

  • The part itself answers the keys above.
  • focus-visible: the browser's own (:focus-visible): write nothing

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.

goop.so/themes/trail/components/code-block.md · the page as Markdown
Theme
Install with your agentnpx shadcn@4.23.1 add https://registry.goop.so/g/<link>/trail-code-block.json --yes

Where would you like to start?

Free · now

The Goop plugin

A design system for your AI coding agent, so screen ten matches screen one.

/plugin marketplace add goop-so/skillsthen /plugin install goop@goopCodex, Cursor, ChatGPT, the Claude app and more: Connect Goop
FreePro

The components

Every part live, with its props, its keys and what an agent sees. Whole page and app templates, working with sample data.