Skip to content
THE COMPONENT LIBRARY
Skip to content

Component reference

CodeBlock

A release note with a copyable code sample.

Preview

Live preview

Changes apply to this preview only.

Migration notes

How a documentation page can frame a code sample.

v1.4
migration.tsts
// Before
theme="light"

// After
theme={{ mode: "light" }}

Width adapts to the available space

More examples

Different configurations and compositions using the real Pimolu API. Each preview runs independently and follows the site appearance.

Documentation sample

File name, language label, line numbers, highlighted lines and copy feedback.

Open preview

Languages

Every supported language shares the same surface; only the token rules differ.

Open preview

Long lines, height and wrapping

Without wrap, the code area scrolls horizontally. maxHeight caps the vertical scroll; wrap breaks long lines instead.

Open preview

Usage

Display the exact working source and choose wrapping or scrolling for long lines.

API reference

Generated from the public TypeScript declarations. Native HTML attributes are inherited where the component extends them; this reference includes Pimolu props and selected common native attributes.

PimoluCodeBlockProps

Type source
PimoluCodeBlockProps public API
NameTypeDefaultDescription
codeRequiredstring—Raw source. It is always rendered as text, never as HTML.
language"text" | "html" | "ts" | "tsx" | "js" | "jsx" | "css" | "json" | "bash" | undefined"ts"Language used for the label and the tokenizer. Defaults to "ts".
filenamestring | undefined—Optional file name shown next to the language label.
showLineNumbersboolean | undefinedfalsePrefix each line with its 1-based number. Defaults to false.
copyableboolean | undefinedtrueRender the copy button. Defaults to true.
copyLabelstring | undefined"Copy"Copy button label while idle. Defaults to "Copy".
copiedLabelstring | undefined"Copied"Copy button label and live message after a successful copy.
highlightLinesreadonly number[] | undefined—1-based line numbers to emphasise.
maxHeightstring | number | undefined—Cap the scrollable code area. Numbers are read as pixels.
wrapboolean | undefinedfalseWrap long lines instead of scrolling horizontally. Defaults to false.
onChangeChangeEventHandler<HTMLDivElement, Element> | undefined—Standard React/HTML attribute.
defaultValuestring | number | readonly string[] | undefined—Standard React/HTML attribute.
classNamestring | undefined—Standard React/HTML attribute.
styleCSSProperties | undefined—Standard React/HTML attribute.
aria-labelstring | undefined—Defines a string value that labels the current element.
onClickMouseEventHandler<HTMLDivElement> | undefined—Standard React/HTML attribute.
codeRequired

string

No default extracted.

Raw source. It is always rendered as text, never as HTML.

language

"text" | "html" | "ts" | "tsx" | "js" | "jsx" | "css" | "json" | "bash" | undefined

Default: "ts"

Language used for the label and the tokenizer. Defaults to "ts".

filename

string | undefined

No default extracted.

Optional file name shown next to the language label.

showLineNumbers

boolean | undefined

Default: false

Prefix each line with its 1-based number. Defaults to false.

copyable

boolean | undefined

Default: true

Render the copy button. Defaults to true.

copyLabel

string | undefined

Default: "Copy"

Copy button label while idle. Defaults to "Copy".

copiedLabel

string | undefined

Default: "Copied"

Copy button label and live message after a successful copy.

highlightLines

readonly number[] | undefined

No default extracted.

1-based line numbers to emphasise.

maxHeight

string | number | undefined

No default extracted.

Cap the scrollable code area. Numbers are read as pixels.

wrap

boolean | undefined

Default: false

Wrap long lines instead of scrolling horizontally. Defaults to false.

onChange

ChangeEventHandler<HTMLDivElement, Element> | undefined

No default extracted.

Standard React/HTML attribute.

defaultValue

string | number | readonly string[] | undefined

No default extracted.

Standard React/HTML attribute.

className

string | undefined

No default extracted.

Standard React/HTML attribute.

style

CSSProperties | undefined

No default extracted.

Standard React/HTML attribute.

aria-label

string | undefined

No default extracted.

Defines a string value that labels the current element.

onClick

MouseEventHandler<HTMLDivElement> | undefined

No default extracted.

Standard React/HTML attribute.

Accessibility

  • Keep code readable at zoom and confirm that copy feedback is announced without moving focus.
Read the accessibility guide →