Code Block
A code viewer with a filename bar, copy button, and collapse for long files.
button.tsx
Examples
The bar
Pass label for a filename, or lang for a language. A filename shows as
written; a bare language is uppercased, so the two never read alike.
BASH
globals.css
Omit both and the bar does not render at all.
import { PreviewCode } from "@/components/preview"
<PreviewCode standalone label="button.tsx">
{/* a fenced code block, or highlighted output */}
</PreviewCode>When to use what
labelnames the file. Falls back tolangwhen omitted, so the bar always says what you are looking at.standalonerounds all four corners. Leave it off when the block is fused to a preview above it.lineNumbersadds the gutter. Off by default — numbers are noise unless you are pointing at a specific line.- Blocks taller than 150px collapse behind an Expand code button. Shorter ones render whole, with no button.
Install commands
InstallTabs renders one command per package manager in the same shell, with
the tab row in place of the filename bar. Commands are highlighted server-side,
so they match every other block.
bun add @fern-ui/color-picker<InstallTabs pkg="@fern-ui/color-picker" />Rendering a source file
ComponentSource reads a file from a package and pipes it through the same
viewer, so a copy-paste component can show exactly what you would copy.
<ComponentSource pkg="color-picker" file="color-picker.tsx" />Installation
Copy these into your project. PreviewCode is the viewer; ComponentSource
reads a file and pipes it through it; InstallTabs renders the command row.
preview.tsx
component-source.tsx
install-tabs-client.tsx
Props
PreviewCode
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | – | The code. A fenced block in MDX, or highlighted output. |
label | string | – | Filename shown in the bar. Falls back to lang. |
lang | string | – | Language shown when there is no filename. |
standalone | boolean | false | Round all four corners, for a block with no preview above it. |
lineNumbers | boolean | false | Show the line-number gutter. |
InstallTabs
| Prop | Type | Default | Description |
|---|---|---|---|
pkg | string | – | Package name. Expands to bun add, npm install, pnpm add and yarn add. |
ComponentSource
| Prop | Type | Default | Description |
|---|---|---|---|
pkg | string | – | Package directory under packages/. |
file | string | – | File to read from that package's src/. |