Skip to content

Code Window ​

A presentational window chrome for code blocks and AI/MCP conversation flows.

ts
import '@vielzeug/refine/tokens.css';
import '@vielzeug/refine/code-window';

Code Variant ​

The default variant. The header shows a lang badge and an optional filename.

Full width

Omit filename to show only the language badge:

Full width

Chat Variant ​

Set variant="chat" for conversation flows. The header shows three traffic-light dots and a title label (default: "MCP tool call").

Full width

Header End Slot ​

Use slot="header-end" to append content to the trailing edge of the header: useful for copy buttons, badges, or status indicators.

Full width

Tightening body padding

Override --code-window-body-padding for a more compact look:

html
<ore-code-window lang="sh" style="--code-window-body-padding: 0.75rem 1rem">
  <pre style="margin:0;font-family:var(--font-mono);font-size:0.875rem"><code>pnpm add @vielzeug/rune</code></pre>
</ore-code-window>

API Reference ​

Attributes ​

AttributeTypeDefaultDescription
variant'code' | 'chat''code'Switches the header chrome between code and chat mode
langstring'ts'Language badge text (variant="code" only)
filenamestringN/AFilename shown next to the badge (variant="code" only)
titlestring'MCP tool call'Label beside the traffic-light dots (variant="chat" only)

Slots ​

SlotDescription
(default)Main body content: code blocks, conversation turns, or any markup
header-endContent pinned to the trailing edge of the header bar

CSS Parts ​

PartDescription
windowThe root window element
headerThe header bar
langThe language badge (variant="code")
filenameThe filename label (variant="code")
dotsThe traffic-light dot container (variant="chat")
titleThe title label (variant="chat")
bodyThe body container wrapping the default slot

CSS Custom Properties ​

PropertyDefaultDescription
--code-window-bg--color-canvasWindow background color
--code-window-header-bg--color-contrast-100Header background color
--code-window-border-color--color-contrast-300Border color
--code-window-radius--rounded-lgBorder radius
--code-window-shadow--shadow-smBox shadow
--code-window-body-padding--size-5 --size-6Body slot padding

Accessibility ​

ore-code-window is a presentational container with no interactive role. The traffic-light dots in variant="chat" carry aria-hidden="true" and have no semantic meaning. Use semantic <pre><code> markup for code content in the default slot. For conversation flows, ensure each speaker label is readable by screen readers: use visually hidden text or aria-label rather than relying solely on color or position.