CodeBlock
Read-only code display card with a one-click copy button, an accessible copy status, and horizontal scroll contained inside the block. Renders raw text — highlighting is layered in by a consumer or the StreamingMarkdown renderer.
type Source = { id: string; title: string; url?: string };
function cite(sources: Source[]): string {
return sources.map((s, i) => `[${i + 1}] ${s.title}`).join('\n');
} 01 Examples
Multi-line code
import { CodeBlock } from '@urbicon-ui/blocks';
export function greet(name: string): string {
return `Hello, ${name} — this line is long enough to scroll inside the block.`;
} Track copies with onCopy
curl -fsSL https://ui.urbicon.de/install.sh | sh Copied 0 times.
Extra header actions
SELECT id, title FROM sources WHERE cited = true; 02 Accessibility
Copy button label
The copy button carries an aria-label that swaps
from copyLabel ("Copy code") to copiedLabel ("Copied") for two seconds after a successful
copy, so its accessible name always matches what the user sees. A denied or failed clipboard
write leaves the label untouched — the UI never falsely confirms a copy that did not happen.
Status announcement
A visually hidden role="status" region announces "Copied"
to screen readers. A label change on the button the user just pressed is not a reliable announcement;
a dedicated live region is, so the region ships in the DOM up front and only its text content
changes.
Scrollable region
The code body is a focusable role="region" (tabindex="0") labelled by the language, so keyboard users can reach and scroll horizontally
overflowing code (WCAG 2.1.1). Focus rings use focus-visible: for keyboard-only visibility.
03 API Reference
No matching properties |