OfferLifetime Pro for $99

Code Block

Code in a chat answer or a doc: coloured, numbered, copyable, with marked lines, several files as tabs, and a block that collapses after a set number of lines. It streams in without flashing plain text first.

AI ChatFree356 lines · one file

The decision inside it

A highlighter that cannot throw

The colouring is a small tokenizer in the file, not a parser or a dependency. It reads half a line as happily as a whole one, so a block that is still streaming is coloured on every render instead of flashing plain and then re-highlighting.

When to use it

Use Code Block for code in a chat answer, a doc or a settings page: highlighted, numbered, copyable, with marked lines and several files as tabs. Set maxLines so a long answer folds, and streaming while a model is still writing it. For a proposed change to existing files, use Code Diff View.

Installation

How you get it

Paste this into Claude Code, Cursor, Codex or any coding agent. It installs the file and uses it as it is, instead of writing a new one.

Use Layro's Code Block for this.
Install it: npx shadcn@latest add @layro/code-block
(the @layro registry is set up in components.json, with LAYRO_KEY in .env.local)
Import it from @/components/ui/code-block.
Do not rewrite or restyle it. Pass my data through its props
and keep its built-in states.

For the full brief with every prop and the mistakes assistants usually make, use Copy prompt above. Free components install through the @layro registry with your CLI token: see the Namespaced tab.

Usage

components/answer-code.tsx
import { CodeBlock } from "@/components/ui/code-block";

export function AnswerCode({ code, done }: { code: string; done: boolean }) {
  return (
    <CodeBlock
      filename="app/api/signing/route.ts"
      language="ts"
      code={code}
      streaming={!done}
      maxLines={24}
      highlightLines={[9, 10]}
      onCopy={() => console.info("copied")}
    />
  );
}

API reference

“Copy prompt” above puts a full brief on your clipboard — install command, dependencies, props, and the mistakes an assistant usually makes with this component.

Props

Read from the component’s own TypeScript interface when the site is built, so this table cannot drift from the file you install.

PropTypeNotes
codestringThe code. Ignored when `tabs` is set.
languagestringThe language, for colouring and the label: "ts", "tsx", "js", "bash", "json", "py", "css", "html".
filenamestringShown in the header in place of the language.
showLineNumbersbooleanNumbers down the left. Default true.
highlightLinesnumber[]One-based line numbers to mark, e.g. the lines an answer changed.
maxLinesnumberCollapse after this many lines, with "Show N more lines". Default 0, never.
wrapbooleanBreak long lines instead of scrolling sideways. Default false.
tabs{ label: string; code: string; language?: string }[]Several files or package managers, one tab each.
streamingbooleanThe code is still arriving: draws a caret at the end and keeps the block expanded.
onCopy(code: string) => voidCalled with the code after it is copied.
actionsReact.ReactNodeExtra buttons in the header, before Copy: "Insert", "Run".
lookLookLayered rests the code in a tray with the header in its margin. Flat is one card. Default layered.

Dependencies

npm packages

clsxlucide-reacttailwind-merge

Layro foundations, installed alongside it

layro-theme

States

All of them are drawn by the component. None is left for you to design.

  • File
  • Marked lines
  • Collapsed
  • Tabs
  • Streaming
  • Copied

Accessibility

  • Keyboard reachable throughout, in visual order
  • Focus trapped in overlays, Escape closes them
  • Focus returns to whatever opened it
  • Live regions announce what changed, not that something did
  • Honours prefers-reduced-motion

Responsive behavior

  • Sizes to its container, not the viewport
  • Usable from 320px up
  • Pointer-based interaction, so trackpad and touch both work
  • No hover-only affordances

Lifetime access

Every component, and everything we ship next.

  • All 232 components, source included
  • Every template, and everything released after you buy
  • shadcn CLI or download — React 18/19, Tailwind v4
  • One payment. No subscription.