Skip to content

Code block

Present code with legible hierarchy and copy access.

ContentDeveloper
npx shadcn@latest add @silicon-ui/code-block

Installation

With the shadcn CLI

npx shadcn@latest add @silicon-ui/code-block

Manually

  1. Install the dependencies

    npm install lucide-react motion
  2. Copy these files into your project

    • components/silicon-ui/code-block/code-block.tsx
    • components/silicon-ui/code-block/code-block.module.css

    Shared with other components. Skip any you already have.

    • components/silicon-ui/copy-button/copy-button.tsx
    • components/silicon-ui/copy-button/copy-button.module.css
    • components/silicon-ui/lib/use-copy-feedback.ts
  3. Add the foundation, once per app, for the design and motion tokens

    npx shadcn@latest add @silicon-ui/silicon-foundation

Usage

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

API reference

PropTypeDefault
code*

Source shown in the block and copied by the action.

string—
filename

File name displayed in the header.

string—
language

Used for the header label and lightweight syntax highlighting.

string"tsx"
maxLines

Collapse longer sources to this many lines, with a toggle that expands the rest in place.

number—
header

The header (experimental): `full` (default) has the file's icon, its name, the language and Copy code; `path` is just the file's path, quiet, for a block whose actions live elsewhere (a docs page's bar).

"full" | "path""full"
fade

Fills its container's height and fades the source out at the foot, with no scrolling and no toggle (experimental). For a fixed-size view of a file that a Full screen elsewhere shows whole; give the container a height.

booleanfalse

Dependencies

npm
lucide-reactmotion
Registry
silicon-motion-tokenscopy-button