Code block
ProSource code for documentation, highlighted at build time, with a copy button and optional line numbers. Not an M3 component (@windmorph/react-pro).
import { CodeBlock } from '@windmorph/react-pro';Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.
Props
CodeBlock 11 props
Raw source — copied by the copy button and used as a fallback when
htmlis absent.Build-time Shiki markup rendered inside
<pre><code>. Trusted (build-generated); when omitted,coderenders as plain text.Language label, exposed on the root as
data-lang.Optional title shown in the header, e.g. a file name. It also names the code region.
Numbers each line (Shiki's
.linespans) in the start margin.Shows a copy button in the header, which copies
code.Ref to the root element. Its other props (
id,aria-*,data-*) go to it too.
Text
The words it shows and announces, merged over the English defaults. A
LabelsProvidersets them for the whole app.
Classes for the root; they win over the defaults via
cn().Classes for each part.
The bordered container (the same element as
className).The header row holding the title and the copy button.
The title in the header.
The scrolling
<pre>region.The
<code>inside it.The copy button: the core's
IconButton.
Inline styles for the root.
Also accepts the root element's HTML attributes (id, data-*, event handlers).
Spec status
Not part of Material Design 3: a Windmorph Pro component, built on M3's colour roles, type scale, shapes and motion. Its variants and configurations each link to a live example.
| Item | Status | Details |
|---|---|---|
Highlighted at build time (html), with a title | Built | Use case · Highlighted |
Line numbers (lineNumbers) | Built | Configuration · Line numbers |
Plain text, without a title, and without the copy button (copyable) | Built | Configuration · Plain |
Highlighted at build time (
Builthtml), with a titleUse case · Highlighted
Line numbers (
BuiltlineNumbers)Configuration · Line numbers
Plain text, without a title, and without the copy button (
Builtcopyable)Configuration · Plain
M3 Expressive specs
- Shape
rounded-corner-medium
Highlighting
htmlis trusted markup from your own build, rendered as it is inside<pre><code>: never pass text people typed. Without it,codeshows as plain text.- It expects Shiki's CSS-variables theme (
createCssVariablesTheme), whose token spans read--shiki-token-*variables. The block sets them to M3 colour roles (keywordsprimary, stringstertiary, commentson-surface-variant…), so one highlight follows every theme, mode and contrast level. Set a variable on the block (withclassName) to change a colour. lineNumberscounts the highlighter's.linespans, so it needshtml.
Styling
classNameandstylego on the bordered root;classNamesstyles the header, title,pre,codeand copy button.- It has no tokens of its own: it is
surface-containerwith anoutline-variantborder and medium corners, and its root carriesdata-tokens="wm-code-block". The copy button is the core's standardIconButton, kept at density 0 in its 48px header. labelsholds every word it shows or announces:copy,copiedandregion, the code's name when there is no title.