Skip to main content
Urbicon UI

CodePanel

Collapsible code block with syntax highlighting, line numbers and copy-to-clipboard. The shared primitive behind CodeExample and PlaygroundConfigurator.

Playground

<script lang="ts">
  import { Button } from '@urbicon-ui/blocks';

  let count = $state(0);
</script>

<Button onclick={() => count++}>
  Clicked {count} times
</Button>
Language
Line numbers
Size
<CodePanel />

01 Examples

Line numbers below the threshold

auto leaves the gutter off for short snippets — a single line gains nothing from a number in front of it.
bun add @urbicon-ui/blocks
<div class="w-full">
  <CodePanel code={ONE_LINER} language="bash" label="Install" />
</div>

Forced on

Pass lineNumbers explicitly to override the threshold in either direction.
bun add @urbicon-ui/blocks
<div class="w-full">
  <CodePanel code={ONE_LINER} language="bash" label="Install" lineNumbers={true} />
</div>

Collapsed by default

Without expanded/onToggle the panel owns its state; the toolbar toggle opens it.
<script lang="ts">
  import { Button } from '@urbicon-ui/blocks';

  let count = $state(0);
</script>

<Button onclick={() => count++}>
  Clicked {count} times
</Button>
<div class="w-full">
  <CodePanel code={SAMPLE} language="svelte" label="Counter button" />
</div>

02 Usage Notes

03 Accessibility

Built-in ARIA

The code region is a role="textbox" with aria-readonly and a name composed from label, so a screen reader announces which example it is reading. The toggle carries aria-expanded; the copy button announces its result through a polite status region rather than only changing its icon.

Keyboard

The code region is focusable (tabindex="0") so it can be scrolled without a pointer. Toggle and copy are ordinary buttons in the tab order, both with a visible focus ring.

While highlighting loads

Shiki is loaded lazily. The placeholder is an aria-live="polite" region, so the swap to highlighted code is announced instead of happening silently.

04 API Reference

Complete list of component properties and their configurations

11 props 1 required
Prop
Type
Default
Description

05 Types

Local type definitions used by this component.

4 types
Name
Kind
Category
Used by
Description

06 Installation

Import

import { CodePanel } from '@urbicon-ui/docs';