Code
Shared code surface: Shiki-highlighted lines, gutter, clean copy, editable content, and virtualization for large files.
Examples
Headerless copy
Use an icon copy action when the filename row would add noise.
Editable files
CodeEditable makes the surface writable; wrap Code in Tabs and put TabsList in the header to switch files.
Composition
Code with header
- <Code>
- <CodeHeader>
- <CodeTitle />
- <CodeActions>
- <CodeCopy />
- <CodeContent />
- <CodeHeader>
Code without a header
A headerless surface overlays its own copy button. Pass copy={false} and place CodeFloatingCopy or CodeCopy yourself.
- <Code>
- <CodeContent />
Custom copy placement
Pass copy={false} when you need the overlay elsewhere, with a different value, or with your own tone.
- <Code>
- <CodeFloatingCopy />
- <CodeContent />
Editable code
CodeEditable swaps the read-only content for a textarea. It never overlays a copy button over text you are typing, so give it a header.
- <Code>
- <CodeHeader>
- <CodeTitle />
- <CodeActions>
- <CodeCopy />
- <CodeEditable />
- <CodeHeader>
One panel, several files
Wrap Code in Tabs and put TabsList in the header; the panel keeps one frame and Code needs no file API.
- <Tabs>
- <Code>
- <CodeHeader>
- <TabsList>
- <TabsTab />
- <CodeActions />
- <TabsList>
- <TabsPanel>
- <CodeContent />
- <CodeHeader>
- <Code>
Custom token rendering
CodeTokenLine renders highlighted tokens inside your own code surface.
- <pre>
- <code>
- <CodeTokenLine />
- <code>
Installation
The Control UI source installs this primitive from src/registry/sources/control-ui/ui/code.tsx.
Dependencies
src/registry/lib/code-tokens.tsSupportsrc/registry/sources/control-ui/code.cssSupportsrc/registry/hooks/use-copy-to-clipboard.tsHookbuttonPrimitiveLive statuslive-statusPrimitiveScroll areascroll-areaPrimitiveTooltiptooltipPrimitiveRaw code
Primary installed source
Knobs
Typed custom properties the recipe paints with. Set one on the root — style, a utility class, or a skin — and every slot inherits it.
--cui-code-* · 9 knobsHow the cascade resolves--cui-code-radius<length-percentage>min(var(--radius-panel), calc(var(--control-h-xs) / 2 + var(--cui-code-border-width) + var(--_code-corner-inset)))--cui-code-background<color>var(--background)--cui-code-border-color<color>var(--control-rim)--cui-code-border-width<length>var(--control-rim-width)--cui-code-shadow*var(--shadow-sm)--cui-code-title-foreground<color>var(--muted-foreground)--cui-code-text-foreground<color>var(--code-foreground)--cui-code-line-highlight-background<color>oklch(from var(--primary) l c h / 0.08)--cui-code-header-background<color>transparent