YuhuanStudioYunUIDocs
Patterns

CodeBlock

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.

Import

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

Basic

CodeBlock

tsx
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

app.tsx
const greeting = "Hello, YunUI";

Tabs

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

Tabs

1 

Props

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

On this page