Code Block
A block of code with a copy control, line numbers and highlighted lines, re-shaded from a single accent colour — ready for any highlighter.
- Data
- 1 file
- 1 npm package
- Accessibility notes
pnpm dlx @dowel-ui/cli add code-blocknpm packages installed: class-variance-authority.
import { CodeBlock } from "@/components/ui/code-block";Default
With Filename
Without Copy
Overflowing
Pre Highlighted
Accent
Line Numbers
Line Numbers On Markup
Without Header
Bare
<CodeBlock>
| Prop | Type | Default |
|---|---|---|
accentAny CSS colour. The surface, border, header, text, line numbers and highlights are all mixed from it and the theme, in light and dark mode. | string | — |
codeThe source code. Rendered when there are no children, and always what the copy button puts on the clipboard. Required when children are rendered markup, because reading text back out of highlighted DOM loses whitespace in ways that break pasted code. It also gives line numbers their count on the first paint. | string | — |
frame | boolean | true |
hideCopyHides the copy control. | boolean | — |
highlightLines1-based line numbers to mark with a soft wash of the accent. | number[] | — |
languageShown in the header and used as the language hint. | string | — |
showHeaderShows the header bar. By default it shows when there is a title, a language or a copy control. Without it, the copy control floats over the top corner. Always off when | boolean | — |
showLineNumbersA gutter of line numbers. They cannot be selected or copied, and are hidden from assistive technology. | boolean | false |
titleFilename or other caption for the header. | string | — |
Plus every attribute of <div>.
8/9
checks passed
- Tested — passes
- axe assertion — passes
- Keyboard tested — fails
- Storybook examples — passes
- Accessibility documented — passes
- Semantic tokens only — passes
- Motion from tokens — passes
- className merged — passes
- Visible focus — does not apply
- No fixed widths — passes