CodeBlock
Default Liquid Glass code viewer with SF Mono typography, sticky line numbers, diff highlighting, Xcode-themed syntax highlighting, and one-click copy.
Fully compatible with the standard shadcn/ui JSX API (CodeBlock / CodeBlockHeader / CodeBlockTitle / CodeBlockActions / CodeBlockWrapButton / CodeBlockCopyButton / CodeBlockContent / CodeBlockLine / CodeBlockFooter):
- Default Liquid Glass: Uses the
mediumLiquid Glass backdrop reacting to the global glass tint; passglass={false}for a 100% opaque code surface, and automatically switches to Over-Glass inside glass Cards or Dialogs. - Responsive typography: 14px radius and 13px monospace on mobile ↔ 10px radius and 12px monospace on desktop, with
size="sm"stepping down one size. - Sticky line numbers & diff rows:
lineNumbersenables line numbering (startLinesets the offset) pinned to the left during horizontal scrolling;CodeBlockLinesupportsadded,removed, andhighlightedtints with a leading accent bar. - Xcode syntax highlighting: Pass
language(e.g."tsx","bash","swift") toCodeBlockContentfor shiki highlighting styled after Xcode's default light/dark themes. Loaded lazily in the browser with pure-JS regex (no WASM) and zero layout shift. - Wrap & copy buttons: Place
CodeBlockWrapButtonandCodeBlockCopyButtoninsideCodeBlockActions(always visible inCodeBlockHeader, or floating top-right on hover/focus on desktop and persistent on touch devices).
Installation (Shadcn Registry)
npx shadcn@latest add @apple-liquid/code-blockDiff Lines, Terminal & Errors
Usage
import { FileCodeIcon } from 'lucide-react';
import {
CodeBlock,
CodeBlockActions,
CodeBlockContent,
CodeBlockCopyButton,
CodeBlockHeader,
CodeBlockTitle,
CodeBlockWrapButton,
} from '@/components/ui/code-block';
const code = `npx shadcn@latest add @apple-liquid/button`;
export function Example() {
return (
<CodeBlock>
<CodeBlockHeader>
<CodeBlockTitle>
<FileCodeIcon />
Terminal
</CodeBlockTitle>
<CodeBlockActions>
<CodeBlockWrapButton />
<CodeBlockCopyButton value={code} />
</CodeBlockActions>
</CodeBlockHeader>
<CodeBlockContent language="bash">{code}</CodeBlockContent>
</CodeBlock>
);
}Props API
CodeBlock
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'default' | 'destructive' | 'default' | destructive adds red border and text for error logs |
size | 'default' | 'sm' | 'default' | Typography and padding density |
wrap | boolean | — | Controlled word-wrap state synced with CodeBlockWrapButton |
defaultWrap | boolean | false | Initial uncontrolled word-wrap state |
onWrapChange | (wrap: boolean) => void | — | Fired when CodeBlockWrapButton toggles wrapping |
glass | boolean | true | Liquid Glass material reacting to glass tint; false renders a 100% opaque surface. Auto-switches to Over-Glass on glass surfaces |
surface | 'default' | 'over-glass' | Auto-detected | Manually override the hosting surface context |
CodeBlockContent
| Prop | Type | Default | Description |
|---|---|---|---|
lineNumbers | boolean | false | Show sticky line numbers (auto-splits string children by line) |
startLine | number | 1 | Starting line number |
wrap | boolean | false | Soft-wrap long lines instead of horizontal scrolling |
language | BundledLanguage | string | — | Shiki syntax highlighting with Xcode palette; unknown languages stay plain text |
CodeBlockLine
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'default' | 'added' | 'removed' | 'highlighted' | 'default' | Added, removed, or highlighted diff line style |
Syntax highlighting applies to string children only; manually composed CodeBlockLine rows remain plain text. Installing this component also adds shiki.
CodeBlockWrapButton toggles wrapping on its parent CodeBlock, and CodeBlockCopyButton copies the provided value; both forward remaining props to Button (defaulting to variant="ghost", size="icon-xs").
Language & Text
CodeBlock accepts locale and messages, which apply to all of its parts and the overlays it opens and win over the global <LiquidGlassProvider locale messages>. To override the text globally, put it under messages.codeBlock on the provider. See Liquid Glass → Global settings.
| Prop | Type | Description |
|---|---|---|
locale | LiquidGlassLocaleInput | UI language of this component (any BCP 47 tag; unsupported ones fall back to English) |
messages | Partial<CodeBlockMessages> | Text overrides, merged over the built-in text and the global messages.codeBlock |
| Key | Built-in text (English) |
|---|---|
copy | Copy |
copied | Copied |
enableWrap | Enable word wrap |
disableWrap | Disable word wrap |
Checkbox
Responsive Apple Liquid Glass checkbox with unified rounded-square semantics across platforms (square for multi-select, circle for radio), larger mobile touch targets, macOS 27 desktop precision, indeterminate state, orthogonal glass, and spring check animation.
Collapsible
Unstyled disclosure container with built-in Apple 27 height easing and Reduced Motion support, ideal for sidebar folders and expandable detail panels.