Code block
Present code with legible hierarchy and copy access.
npx shadcn@latest add @silicon-ui/code-blockInstallation
With the shadcn CLI
npx shadcn@latest add @silicon-ui/code-blockManually
Install the dependencies
npm install lucide-react motionCopy 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
Add the foundation, once per app, for the design and motion tokens
npx shadcn@latest add @silicon-ui/silicon-foundation
Usage
API reference
| Prop | Type | Default |
|---|---|---|
code*Source shown in the block and copied by the action. | string | — |
filenameFile name displayed in the header. | string | — |
languageUsed for the header label and lightweight syntax highlighting. | string | "tsx" |
maxLinesCollapse longer sources to this many lines, with a toggle that expands the rest in place. | number | — |
headerThe 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" |
fadeFills 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. | boolean | false |