Xzero UI
Pro library

Code block

Present code with legible hierarchy and copy access.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui/code-block
Live · keyboard ready

When to use

When not to use

Installation

Register both Xzero UI namespaces in your project's components.json:

{
  "registries": {
    "@xzero-ui": "https://mcp.xzero.co.uk/r/{name}.json",
    "@xzero-ui-pro": "https://mcp.xzero.co.uk/r/pro/{name}.json"
  }
}
npx shadcn@4.23.0 add @xzero-ui/code-block

Install xzero-foundation once, and import @/components/xzero/foundation.css in your app root. No Xzero token is used by this snapshot. For sample portraits, photos, fonts, or logos, download https://mcp.xzero.co.uk/install-assets.mjs and run node xzero-install-assets.mjs <receiving-project>.

Usage

import { CodeBlock } from "@/components/xzero/code-block/code-block";

const snippet = `export function hello() {
  return "world";
}`;

export function Example() {
  return <CodeBlock code={snippet} filename="hello.ts" language="ts" maxLines={12} />;
}

API reference

CodeBlock

A source viewer with filename header, light syntax highlighting, copy button, and optional collapse.

PropTypeDefaultDescription
code (required)string–Source shown and copied.
filenamestring–File name in the header. Defaults to "Source code".
languagestring"tsx"Header label and highlighter mode.
maxLinesnumber–Collapses longer sources to this many lines with a Show all toggle.

Keyboard interactions

KeysAction
TabFocuses the copy button, the scrollable source, and the expand toggle.
Enter / SpaceCopies the code or toggles the expanded state.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Also in tables

Guidance for AI tools

Code block: Present code with legible hierarchy and copy access. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://ui.xzero.co.uk/llms.txt

Browse all components