Skip to content
caliper ui pro docs

Code block

Syntax-highlighted code with a language label and a copy button.

Pro
welcome-banner.tsx
tsx
export function WelcomeBanner({ name }: { name: string }) {  return <p>Welcome back, {name}.</p>;}

When to use

  • Showing a snippet, command or config the reader may copy.
  • You need optional line numbers.

When not to use

  • The content is a diff; use the file diff.
  • It is inline code inside a sentence.

Installation

terminal
pnpm dlx shadcn@latest add @caliper/code-block

Adds its 4 files to components/ui/, each with its own stylesheet, and installs their packages. Pro installs with your access token, set up once per project. See Pro access. The first part also adds Caliper UI’s tokens; import them once as in Installation.

API reference

CodeBlock

12 props
PropTypeDefaultDescription
codestring—
languageCodeLanguage"text"
titlestring—A filename or short caption shown in the header.
variantsreadonly CodeVariant[]—Alternatives of the same snippet, such as package managers. Replaces `code`.
lineNumbersbooleanfalse
highlightreadonly number[][]1-based line numbers to emphasize.
collapsedLinesnumber—Show only this many lines until the reader expands.
wrapbooleanfalse
streamingbooleanfalseThe code is still arriving: shows a caret, follows the newest line and holds Copy until it is whole.
maxHeightstring—Any CSS height. Taller code scrolls inside the block.
labelstring—
classNamestring—

highlightCode

0 props

No props of its own; it accepts the native props of its root element.

copyText

0 props

No props of its own; it accepts the native props of its root element.

Keyboard

→
Moves to the next item or value.
←
Moves to the previous item or value.
Home
Jumps to the first item or the minimum.
End
Jumps to the last item or the maximum.

Accessibility

It exposes tablist, tab and status semantics, with aria-busy, aria-label, aria-selected, aria-hidden and aria-expanded kept in step with state. Changes that matter are announced through a live region.

Notes for AI

Give your coding assistant this page as Markdown instead of screenshots: the props, keyboard and examples in one file.

/docs/components/code-block.md

The index of every part is at /llms.txt.

More in Agent work