Skip to content
Components

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 />
        </CodeActions>
      </CodeHeader>
    • <CodeContent />
    </Code>

Code without a header

A headerless surface overlays its own copy button. Pass copy={false} and place CodeFloatingCopy or CodeCopy yourself.

  • <Code>
    • <CodeContent />
    </Code>

Custom copy placement

Pass copy={false} when you need the overlay elsewhere, with a different value, or with your own tone.

  • <Code>
    • <CodeFloatingCopy />
    • <CodeContent />
    </Code>

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 />
        </CodeActions>
      </CodeHeader>
    • <CodeEditable />
    </Code>

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 />
          </TabsList>
        • <CodeActions />
        </CodeHeader>
      • <TabsPanel>
        • <CodeContent />
        </TabsPanel>
      </Code>
    </Tabs>

Custom token rendering

CodeTokenLine renders highlighted tokens inside your own code surface.

  • <pre>
    • <code>
      • <CodeTokenLine />
      </code>
    </pre>

Installation

The Control UI source installs this primitive from src/registry/sources/control-ui/ui/code.tsx.

Registry command
See registry manifest

Dependencies

Shiki tokenizersrc/registry/lib/code-tokens.tsSupport
Code + diff tokenssrc/registry/sources/control-ui/code.cssSupport
Use copy to clipboardsrc/registry/hooks/use-copy-to-clipboard.tsHook
ButtonbuttonPrimitiveLive statuslive-statusPrimitiveScroll areascroll-areaPrimitiveTooltiptooltipPrimitive

Raw code

Primary installed source

src/registry/sources/control-ui/ui/code.tsx

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