Ballmac UI home

Code BlockPRO

A code panel with filename and language header, line numbers, highlighted lines, a wrap toggle, copy feedback and file tabs. No highlighter bundled; pass Shiki output as children.

7/7 checksv1.1.0Updated Oct 19, 2026Ships with a test
What changed
  1. 1.1.0 Oct 19, 2026Adds the compound API of shadcn's Code Block: header, title, actions, copy button, content, line and footer parts, size and variant, diff and highlighted lines, start line and a useHighlightedCode hook. The ready-made panel and CodeBlockTabs are unchanged.

Update without losing your edits

components/save-button.tsxtsx
import { Button } from "@/components/ballmac/button" export function SaveButton({ saving }: { saving: boolean }) {  return <Button loading={saving}>Save changes</Button>}

Installation

  1. Get a Pro licence key.

    The source is part of Ballmac UI Pro.

    Log in with your licence key to read and copy it here, or install it through the shadcn CLI or the MCP server. You own the code once it is in your project.

    $49 once regular price $99for this and every other Pro item. Tax included.Money back if it does not work.

  2. Once per project: add the Pro registry and your licence key.

    components.json
    {
      "registries": {
        "@ballmac": "https://ui.ballmac.com/r/{name}.json",
        "@ballmac-pro": {
          "url": "https://ui.ballmac.com/r/pro/{name}.json",
          "headers": { "Authorization": "Bearer ${BALLMAC_LICENSE_KEY}" }
        }
      }
    }
    .env.local
    BALLMAC_LICENSE_KEY=your-licence-key
  3. Add it.

    $ pnpm dlx shadcn@latest add @ballmac-pro/code-block

Usage

import { CodeBlock, CodeBlockActions, CodeBlockContent, CodeBlockCopyButton, CodeBlockFooter, CodeBlockHeader, CodeBlockLine, CodeBlockTabs, CodeBlockTitle, useHighlightedCode } from "@/components/ballmac/code-block"

The full example is in the Code tab above.

Examples

File tabs

tsx
import { Hero } from "@/components/hero" export default function Page() {  return <Hero />}

Header, title and actions

Terminal
$ pnpm build
 ✓ Compiled in 4.2s
 ✓ Generated 48 static pages
Done in 11.8s

Highlighted code and lines

app/api/items/route.ts
export async function GET(request: Request) {  const { searchParams } = new URL(request.url)  const id = searchParams.get("id")  if (!id) return Response.json({ error: "id is required" }, { status: 400 })  return Response.json({ id })}

Diff

lib/cart.ts
export function total(items: Item[]) {  return items.reduce((sum, i) => sum + i.price, 0)  return items.reduce((sum, i) => sum + i.price * i.qty, 0)}

Floating actions

npx ballmac add code-block

Show more

build.log
line 1: output from the build stepline 2: output from the build stepline 3: output from the build stepline 4: output from the build stepline 5: output from the build stepline 6: output from the build stepline 7: output from the build stepline 8: output from the build stepline 9: output from the build stepline 10: output from the build stepline 11: output from the build stepline 12: output from the build stepline 13: output from the build stepline 14: output from the build stepline 15: output from the build stepline 16: output from the build stepline 17: output from the build stepline 18: output from the build stepline 19: output from the build stepline 20: output from the build stepline 21: output from the build stepline 22: output from the build stepline 23: output from the build stepline 24: output from the build stepline 25: output from the build stepline 26: output from the build stepline 27: output from the build stepline 28: output from the build stepline 29: output from the build stepline 30: output from the build step

Tool output in a Trace

$ pnpm test
 FAIL  src/cart.test.ts
 Expected: 40
 Received: 20

API reference

<CodeBody>

PropTypeDefault
codestring—
childrenReact.ReactNode—
lineNumbers*boolean—
highlight*number[]—
wrap*boolean—
label*string—
codeRef*React.RefObject<HTMLDivElement | null>—
classNamestring—

<CodeBlockPanel>

PropTypeDefault
code

Source as plain text. Rendered unhighlighted in monospace; required for `highlight`.

string—
children

Pre-highlighted markup (e.g. Shiki's output as JSX) used instead of `code`. Pass `code` too so copy gets clean text.

React.ReactNode—
filename

Shown in the header, e.g. "app/page.tsx".

string—
language

Language label shown in the header, e.g. "tsx".

string—
lineNumbers

Show line numbers.

booleanfalse
highlight

1-based line numbers to highlight (plain `code` only).

number[][]
wrap

Wrap long lines instead of scrolling horizontally (initial value when the toggle is shown).

boolean—
wrapToggle

Show a button that toggles line wrapping.

booleanfalse
copyable

Show the copy button.

booleantrue
bodyClassName

Classes for the scrolling body, e.g. a max height.

string—

<CodeBlockShell>

PropTypeDefault
variant

The tone of the block. `destructive` is for errors and failed output.

keyof typeof shellVariants"default"
size

`sm` has tighter padding and smaller text, for tool output inside a Trace.

"default" | "sm""default"

<CodeBlockContent>

PropTypeDefault
wrap

Wrap long lines instead of scrolling.

booleanfalse
lineNumbers

Number each line. A string child is split into lines.

booleanfalse
startLine

The number of the first line, when `lineNumbers` is set.

number1

<CodeBlockLine>

PropTypeDefault
variant

The state of the line. `added` and `removed` add a `+` or `−` marker as well as a tint.

keyof typeof lineVariants"default"

<CodeBlockTabs>

PropTypeDefault
files*

One tab per file.

CodeBlockFile[]—
defaultValue

Filename of the tab open at first.

string—
value

Controlled open tab (a filename).

string—
onValueChange

Called with the filename of the newly selected tab.

(filename: string) => void—
lineNumbers

Show line numbers.

booleanfalse
wrap

Wrap long lines instead of scrolling horizontally.

booleanfalse
copyable

Show the copy button (copies the open file).

booleantrue
bodyClassName

Classes for each scrolling body.

string—

Also accepts the standard attributes of its root element.

Accessibility

KeyAction
TabFocuses the scrollable code region (arrow keys scroll long lines), then wrap and copy buttons
← / →In CodeBlockTabs, moves between file tabs
—Copying announces 'Copied to clipboard' through a polite live region

Quality scorecard

7/7

Every applicable check passes

Measured in Chromium 153.0.8010.12 on October 19, 2026, on version 1.1.0, across 8 examples.

How we measure
  • Passed: Accessibility scan

    No serious or critical issues in light and dark, on a phone and a desktop (axe-core 4.13.0, WCAG 2.1 AA and best-practice rules).

  • Passed: Small screens

    No sideways scrolling at 360, 390 or 1280 px wide.

  • Passed: Reduced motion

    No endless animation to begin with.

  • Passed: Right to left

    Mirrors correctly in Arabic, Hebrew, Persian and Urdu layouts (0% of elements off the mirror, limit 15%).

  • Passed: Clean console

    No console errors or React hydration errors while loading.

  • Passed: Keyboard

    18 tab stops, each showing a visible change when it takes focus. 3 documented keys.

  • Not applicable: Loading, empty and error

    Does not show data or take submissions.

  • Passed: Automated tests

    Covered by code-block.test.tsx.

  • For information: Footprint

    5.6 KB of source (gzip) in 1 file. Installs lucide-react, radix-ui.

Automated checks find a subset of problems and do not replace testing with a screen reader and a keyboard in your own app. What they miss.

Use with AI

Two ways to use it. Ready-made: <CodeBlock code filename language lineNumbers highlight={[2,3]} /> renders plain monospace text. Compound (the same API as shadcn's Code Block, so chat kits and agent output drop in): <CodeBlock size variant><CodeBlockHeader><CodeBlockTitle/><CodeBlockActions><CodeBlockCopyButton value/></CodeBlockActions></CodeBlockHeader><CodeBlockContent lineNumbers wrap startLine><CodeBlockLine variant="added|removed|highlighted"/></CodeBlockContent><CodeBlockFooter/></CodeBlock>, with useHighlightedCode(code, language) giving one node per line. For syntax colors, highlight on the server (e.g. Shiki) and pass the result as children plus the raw code for copying. <CodeBlockTabs files={[…]}> shows several files. With the shadcn MCP server set up (guide), ask your agent:

Add the Ballmac UI Code Block (@ballmac-pro/code-block) to this project with the shadcn MCP, then use it where it fits.

Use it for

  • Code samples in docs, READMEs rendered on the web and blog posts
  • Showing a changed file with specific lines highlighted
  • Several related files (component, usage, config) in one panel with tabs

Not for

  • One-line install commands for several package managers (use install-tabs)
  • Terminal sessions with prompts and output (use terminal)
  • Editable code (use a code editor)

Registry JSON (needs your licence key): https://ui.ballmac.com/r/pro/code-block.json

Credits

Covered by the Ballmac UI Pro license.