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.
What changed
- 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.
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.
Installation
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.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.localBALLMAC_LICENSE_KEY=your-licence-keyAdd 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
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.
Header, title and actions
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.
Highlighted code and lines
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.
Diff
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.
Floating actions
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.
Show more
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 stepThe 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.
Tool output in a Trace
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.
API reference
<CodeBody>
| Prop | Type | Default |
|---|---|---|
code | string | — |
children | React.ReactNode | — |
lineNumbers* | boolean | — |
highlight* | number[] | — |
wrap* | boolean | — |
label* | string | — |
codeRef* | React.RefObject<HTMLDivElement | null> | — |
className | string | — |
<CodeBlockPanel>
| Prop | Type | Default |
|---|---|---|
codeSource as plain text. Rendered unhighlighted in monospace; required for `highlight`. | string | — |
childrenPre-highlighted markup (e.g. Shiki's output as JSX) used instead of `code`. Pass `code` too so copy gets clean text. | React.ReactNode | — |
filenameShown in the header, e.g. "app/page.tsx". | string | — |
languageLanguage label shown in the header, e.g. "tsx". | string | — |
lineNumbersShow line numbers. | boolean | false |
highlight1-based line numbers to highlight (plain `code` only). | number[] | [] |
wrapWrap long lines instead of scrolling horizontally (initial value when the toggle is shown). | boolean | — |
wrapToggleShow a button that toggles line wrapping. | boolean | false |
copyableShow the copy button. | boolean | true |
bodyClassNameClasses for the scrolling body, e.g. a max height. | string | — |
<CodeBlockShell>
| Prop | Type | Default |
|---|---|---|
variantThe 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>
| Prop | Type | Default |
|---|---|---|
wrapWrap long lines instead of scrolling. | boolean | false |
lineNumbersNumber each line. A string child is split into lines. | boolean | false |
startLineThe number of the first line, when `lineNumbers` is set. | number | 1 |
<CodeBlockLine>
| Prop | Type | Default |
|---|---|---|
variantThe state of the line. `added` and `removed` add a `+` or `−` marker as well as a tint. | keyof typeof lineVariants | "default" |
<CodeBlockTabs>
| Prop | Type | Default |
|---|---|---|
files*One tab per file. | CodeBlockFile[] | — |
defaultValueFilename of the tab open at first. | string | — |
valueControlled open tab (a filename). | string | — |
onValueChangeCalled with the filename of the newly selected tab. | (filename: string) => void | — |
lineNumbersShow line numbers. | boolean | false |
wrapWrap long lines instead of scrolling horizontally. | boolean | false |
copyableShow the copy button (copies the open file). | boolean | true |
bodyClassNameClasses for each scrolling body. | string | — |
Also accepts the standard attributes of its root element.
Accessibility
| Key | Action |
|---|---|
| Tab | Focuses 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
Every applicable check passes
Measured in Chromium 153.0.8010.12 on October 19, 2026, on version 1.1.0, across 8 examples.
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.
Pairs well with
Install Tabs
Package-manager tabs for a CLI command (pnpm, npm, yarn, bun) with a copy button. Remembers the reader's choice and keeps every instance on the page in sync.
Terminal
A terminal window with command, output, success, error and comment lines, optional per-command copy buttons and a sequenced typing animation that respects reduced motion.
AI Message
A chat message with user, assistant and system roles: right-aligned user bubbles, full-width assistant prose, an avatar slot, hover-revealed actions and a hydration-safe timestamp.
API Key Field
Displays a secret such as an API key, masked by default (sk-live-••••••••a1b2), with a reveal toggle, a copy button that copies the full key, and an optional regenerate action.