Skip to content

Code Window

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

ts
import '@vielzeug/refine/styles';
import '@vielzeug/refine/code-window';

Code Variant

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

PreviewCode
RTL
html
<ore-code-window lang="ts" filename="app.ts">
  <pre style="margin:0;font-family:var(--font-mono);font-size:0.8125rem;line-height:1.7">
    <code>import { createLogger } from '@vielzeug/rune';

const log = createLogger('app');
log.info('Server started', { port: 3000 });</code>
  </pre>
</ore-code-window>

Omit filename to show only the language badge:

PreviewCode
RTL
html
<ore-code-window lang="sh">
  <pre style="margin:0;font-family:var(--font-mono);font-size:0.875rem">
    <code>npx -y @vielzeug/codex</code>
  </pre>
</ore-code-window>

Chat Variant

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

PreviewCode
RTL
html
<ore-code-window variant="chat" title="MCP tool call">
  <div style="display:flex;flex-direction:column;gap:0.75rem">
    <div>
      <div style="font-size:0.6875rem;font-family:var(--font-mono);font-weight:600;letter-spacing:0.06em;text-transform:uppercase;color:var(--text-color-secondary);margin-bottom:4px">user</div>
      <span>How do I debounce a function in Arsenal?</span>
    </div>
    <div>
      <div style="font-size:0.6875rem;font-family:var(--font-mono);font-weight:600;letter-spacing:0.06em;text-transform:uppercase;color:oklch(58% 0.16 250deg);margin-bottom:4px">tool</div>
      <pre style="margin:0;font-family:var(--font-mono);font-size:0.8rem;background:var(--color-contrast-100);border:1px solid var(--color-contrast-300);border-radius:6px;padding:0.5rem 0.75rem">get-docs({ packageSlug: "arsenal", page: "api" })</pre>
    </div>
    <div>
      <div style="font-size:0.6875rem;font-family:var(--font-mono);font-weight:600;letter-spacing:0.06em;text-transform:uppercase;color:var(--color-primary);margin-bottom:4px">assistant</div>
      <span>Use <code>debounce(fn, wait)</code> — returns a debounced version that delays invoking <code>fn</code> until <code>wait</code> ms after the last call.</span>
    </div>
  </div>
</ore-code-window>

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.

PreviewCode
RTL
html
<ore-code-window lang="ts" filename="logger.ts">
  <ore-button slot="header-end" size="sm" variant="ghost">Copy</ore-button>
  <pre style="margin:0;font-family:var(--font-mono);font-size:0.8125rem;line-height:1.7">
    <code>const log = createLogger('app');</code>
  </pre>
</ore-code-window>

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)
filenamestringFilename 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.