CodeBlock
Data Display

CodeBlock

Syntax-highlighted code display with optional line numbers, highlighting, and copy.

Props

CodeLanguage is a string union: "ts" | "js" | "tsx" | "jsx" | "json" | "bash" | "sql" | "css" | "yaml" | "text".

CodeBlockProps props
PropTypeDefaultDescription
codestring—The source code string to display.
languageCodeLanguage"text"Language for syntax highlighting.
titleReactNode—File name or label in the header bar.
showLineNumbersboolean—Shows line numbers in the gutter.
copyablebooleantrueShows a copy button.
highlightLinesnumber[]—1-based line numbers to tint.
maxLinesnumber—Collapses to this many lines with a toggle.
wrapboolean—Soft-wrap instead of scrolling horizontally.
startLinenumber1Starting line number for excerpts.

Examples

TypeScript
With title and line numbers
Wrapped
Max lines
Highlighted lines
ImportTSX
import { CodeBlock } from "@solarius/onset";
import type { CodeLanguage } from "@solarius/onset";