Skip to content

Code block

Shows a block of code with a header, copy, and line numbers.

button.tsx
import { Button } from "@/components/vip-ui/button"; export function SaveButton() {  const save = () => saveChanges();  return <Button onPress={save}>Save changes</Button>;}
code-block-demo.tsx

Installation

The CLI adds the files, packages, theme variables, and Tailwind plugin that this component uses. Before you run it, set up your project.

Usage

snippet.tsx

Composition

  • CodeBlock

    Owns the code, the wrap state, and the expanded state.

    • CodeBlockHeaderOptional
      • CodeBlockTitleOptional
      • CodeBlockActionsOptional
        • CodeBlockWrapOptional
        • CodeBlockCopy
    • CodeBlockBody

      Pass highlighter output as children. Without children, it shows the code as plain text.

Highlighted lines

route.ts
import { NextResponse } from "next/server";import { listProjects } from "@/lib/projects"; export async function GET() {  const projects = await listProjects();  const active = projects.filter((project) => project.status === "active");   return NextResponse.json(active);}
code-block-highlight-demo.tsx

Collapsed

Set maxLines to collapse long code.

session.ts
code-block-collapsed-demo.tsx

Wrap

request.sh
curl --request POST "https://api.atlas.dev/v2/projects/atlas-2026/events?include=members,invites,activity&expand=owner,plan" --header "Authorization: Bearer $ATLAS_TOKEN" --data '{"name":"Invite sent","source":"dashboard"}'
code-block-wrap-demo.tsx

Syntax colors

Pass the output of your highlighter as the children of CodeBlockBody.

publish-button.tsx
import { useState } from "react";
import { Button } from "@/components/vip-ui/button";

export function PublishButton() {
  const [publishing, setPublishing] = useState(false);

  return (
    <Button
      isPending={publishing}
      onPress={() => {
        setPublishing(true);
        publish().finally(() => setPublishing(false));
      }}
    >
      Publish release
    </Button>
  );
}
code-block-syntax-demo.tsx

Streaming

Set isStreaming while the code arrives. Also install Response and Button.

Here is the route handler for project search.

route.ts
import { NextResponse } from "next/server";
code-block-streaming-demo.tsx

API reference

CodeBlock

code: stringRequired
The code text. The copy button writes it as given.
language: string
The language name. It shows in the default header when you do not render a title.
lineNumbers: boolean = true
Shows a gutter with line numbers. The numbers are not copied or selected. Ignored when you pass children.
highlight: number[]
Highlights these 1-based line numbers. Ignored when you pass children.
wrap: boolean
Wraps long lines, controlled.
defaultWrap: boolean = false
Wraps long lines at first, uncontrolled.
onWrapChange: (wrap: boolean) => void
Receives the new wrap state from the toggle.
maxLines: number
Collapses the body at this many lines and adds a Show more button.
isStreaming: boolean = false
Marks the frame busy and keeps the gutter wide while the code arrives.

CodeBlockBody

children: ReactNode
Highlighted output from your highlighter. Without it, the body shows the code as plain text.

CodeBlockHeader

Holds the title and actions. It shows the language name and the default actions when you pass no children.

children: ReactNode
Replaces the default title and action row with custom content.

CodeBlockTitle

Names the code in the header. A string also names the code region for assistive technology.

children: ReactNode
The title text, usually the file name.

CodeBlockActions

Holds the header actions. It renders the wrap toggle and the copy button by default.

children: ReactNode
Replaces the default wrap and copy actions.

CodeBlockWrap

Toggles line wrapping. It takes the ToggleButton props and is icon-only.

CodeBlockCopy

Copies the code from the frame. It takes the CopyButton props except value.