Code Block
Shows read-only code with a copy button, in plain text that keeps 7:1 contrast in light and dark.
- Status
- Not tracked
- Code
- In React
- Role
- Display
Usage
This demo is live, and the code below it is the same code, imports included. The component lives in src/ui of this repository and is not published to npm yet.
import { Button } from "@/ui"; export function PayButton() { return <Button size="lg">Pay Rp 412.500</Button>;}Pastes as editable layers. Shadows are not exported.
import { CodeBlock } from "@/ui";
const SAMPLE_CODE: string = `import { Button } from "@/ui";
export function PayButton() {
return <Button size="lg">Pay Rp 412.500</Button>;
}`;
export default function CodeBlockDemo() {
return <CodeBlock title="pay-button.tsx" language="TSX" showLineNumbers code={SAMPLE_CODE} />;
}Variants and states
Every specimen is the real component from src/ui, held in one state.
import { Button } from "@/ui";import { Button } from "@/ui"; export function PayButton() { return <Button size="lg">Pay Rp 412.500</Button>;}const message = "A long line keeps going past the edge of the panel, so it scrolls, or wraps when wrap is set.";const message = "A long line keeps going past the edge of the panel, so it scrolls, or wraps when wrap is set.";Pastes as editable layers. Shadows are not exported.
Props
- code
- string · default none
- Required. The code, as plain text.
- language
- string · default none
- Shown in the header, such as "TSX". Also names the scroll region.
- title
- string · default none
- A file name or title in the header.
- showLineNumbers
- boolean · default false
- Numbers each line. The numbers are aria-hidden and not selected with the code.
- wrap
- boolean · default false
- Wrap long lines instead of scrolling sideways.
- copyable
- boolean · default true
- Show the Copy button. It says Copied for two seconds.
- className
- string · default ""
- Extra classes on the figure.
Figma to code
Figma properties by their exact names from Naming, and the React prop that carries each one. The table covers the shared properties that bear on this component; the Figma file decides which of them its component exposes. None means there is no prop for it yet.
- 🖍 Label
- title, language
- The header text.
- 🎯 State
- None
- Copied is shown for two seconds after a copy.
Accessibility
What the code in src/ui does today, and what it leaves to you.
Keyboard
- Tab reaches the Copy button, then the code region when it scrolls. Arrow keys scroll the focused region.
Screen readers
- The Copy button's text changes to Copied in a polite live region, so the copy is announced.
- A scrolling region is named by title and language.
What you still need to do
- Keep the code short enough to read. Link to the full file for anything long.
- Plain text only: there are no syntax colors, so meaning must not depend on color.
When to use
Documentation and usage examples.
Do and don't
Do
- Include a copy button.
- Keep line length reasonable, wrap when needed.
Don't
- Use for non-code content.
- Omit the language label when it helps readers know what they are reading.
Related
Other untracked components.
- Button GroupA set of related buttons, visually grouped together as a single control.Not tracked
- Icon ButtonA compact button that uses only an icon to represent its action.Not tracked
- LinkNavigates the user to another page, section, or resource.Not tracked
- SelectLets users choose one option from a list in a dropdown.Not tracked
Status reflects the component tracker snapshot of 29 October 2026.