CodePreview

A live-rendered preview above a collapsible `Code` block showing the source behind it — the pattern this very docs site uses for every component example.

html
<UiCodePreview :code="..." />

Code

required

code is the source shown in the collapsible panel under the preview. The preview itself is the default slot — real, interactive content, not a screenshot of it — so the two are written separately and it is on you to keep them in step.

3
Example.vue
vue
<UiBadge text="3" color="error">
  <UiButton icon="bell" variant="soft" />
</UiBadge>

variant only styles the outer card wrapping both the preview and the code panel — it's unrelated to Code's own bare prop, which is always forced on internally so the inner code block never renders as a nested card.

Language

language is passed straight through to the inner Code, setting both the syntax highlighting and the tag shown in the corner of the panel.

Filename

filename puts a header bar on the code panel naming the file. Without one the panel opens straight into the code, which is right for a fragment that doesn't correspond to a file at all.

AL

Variant

variant styles the card wrapping both halves — the preview and the code panel together. It's unrelated to Code's own bare prop, which is always forced off inside here. Reach for subtle when the demo renders its own raised surface and an outlined card around it would read as a second border.

Tag
Tag

Copy

copy shows a button that copies the sample to the clipboard. It defaults to true here — the opposite of Code's own default — because a snippet sitting under a live preview is almost always something you want to take away.

Tag

The code panel is a Collapsible wrapping a Code, not a new implementation — language/filename/copy are passed straight through to that inner Code. defaultOpen controls whether it starts expanded; there's no open/update:open here, unlike Collapsible itself, since a single always-uncontrolled toggle button is the only use case this component targets.

copy defaults to true here (opposite of Code's own default of false) — a code sample sitting under a live preview is almost always something someone will want to copy, so this flips the more common case to the default without you having to opt in every time.

Default open

defaultOpen starts with the code panel expanded instead of collapsed, for a sample where the markup is the point rather than the render.

Tag
<UiTag color="primary">Tag</UiTag>

The preview above is real, interactive content — click the button

The default slot is the live preview, rendered as-is above the code panel — it's real, interactive content, not a screenshot. code is a separate, independent prop: a plain string, so it isn't extracted from the slot automatically. Keep the two in sync yourself, the same way Code's own code prop and default slot are independent.

`variant` — outline (default), subtle

outline (default)

Example

Tag
subtle

Example

Tag

API Reference

Generated from the component's source — props, slots and emits as the component actually declares them.

Props

Prop
Type
Default
Description
coderequired
string
The source code shown in the collapsible panel below the preview.
string
Language to syntax-highlight `code` as, passed straight through to `Code`.
string
Filename displayed in the code block's header bar, passed straight through to `Code`.
"outline" | "subtle"
'outline'
The visual style of the surrounding preview card.
boolean
true
Shows a button that copies the code to the clipboard, passed straight through to `Code`.
boolean
false
Whether the code panel starts open instead of collapsed.

Slots

Slot
default