Code Block
Styled code block with header, line numbers, tabs, and copy.
A styled code block with window-chrome dots, a header showing the language badge or a filename, optional line numbers, lightweight syntax highlighting, and a copy-to-clipboard button. Pass tabs to render multiple switchable code panes instead of a single block.
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.
CodeBlockfromyunui/contentis 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
1import { CodeBlock } from "@yuhuanowo/yunui/patterns";Basic
CodeBlock
1import { Button } from "@yuhuanowo/yunui";2 3export function App() {4return <Button variant="primary">Click me</Button>;5}With a filename
Set filename to show a file label instead of the language badge, and showLineNumbers={false} to hide the gutter.
Filename
const greeting = "Hello, YunUI";Tabs
Provide a tabs array to switch between related snippets in one block.
Tabs
1 Props
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | — | |
| code* | string | — | The code to display (ignored when `tabs` are provided). |
| copyable | boolean | true | Show the copy-to-clipboard button. |
| filename | string | — | Filename shown in the header instead of the language badge. |
| language | string | text | Language label, also used by the lightweight highlighter. |
| showLineNumbers | boolean | true | Show line numbers in the gutter. |
| tabs | Tab[] | — | Render multiple switchable code tabs instead of a single `code` block. |