YuhuanStudioYunUIDocs
Patterns

Code Block

Styled code block with header, line numbers, tabs, and copy.

A compact 14px code block with a filename/language header, optional line numbers, lightweight syntax highlighting, and full-source copy. Pass tabs for switchable examples. Blocks longer than 16 lines initially show 8 lines, with an accessible expand/collapse control; copy always uses the full active tab. Line numbers are off by default.

Which CodeBlock? This one is dependency-free — it highlights with a small built-in tokenizer, so it costs nothing to render a snippet in a marketing page or a docs card. CodeBlock from yunui/content is the Shiki-backed one: VS Code-grade highlighting, line highlighting and an edit action, at the cost of loading a grammar. Use that for real code, this for illustration.

Import

tsx1 line
import { CodeBlock } from "@yuhuanowo/yunui/patterns";

Basic

CodeBlock

tsx5 lines
import { Button } from "@yuhuanowo/yunui";

export function App() {
return <Button variant="primary">Click me</Button>;
}

With a filename

Set filename to show a file label instead of the language badge, and showLineNumbers={false} to hide the gutter.

Filename

app.tsxtext1 line
const greeting = "Hello, YunUI";

Tabs

Provide a tabs array to switch between related snippets in one block.

Tabs

1 line
npm install @yuhuanowo/yunui

Props

PropTypeDefaultDescription
classNamestring—
code*string—The code to display (ignored when `tabs` are provided).
copyablebooleantrueShow the copy-to-clipboard button.
filenamestring—Filename shown in the header instead of the language badge.
languagestringtextLanguage label, also used by the lightweight highlighter.
showLineNumbersbooleanfalseShow line numbers in the gutter.
tabsTab[]—Render multiple switchable code tabs instead of a single `code` block.

On this page