Components
CodeBlock
A syntax-highlighted code display with copy functionality, line numbers, and line highlighting.
Overview
CodeBlock renders formatted code with syntax highlighting, a copy-to-clipboard button, optional line numbers, and the ability to highlight specific lines.
Default with title
App.tsx
import { Button } from '@ds0/react'; export function App() { return ( <Button variant="primary" size="md"> Click me </Button> );}With line numbers & highlighted lines
Highlighted
1import { Button } from '@ds0/react';2 3export function App() {4 return (5 <Button variant="primary" size="md">6 Click me7 </Button>8 );9}Ghost variant
styles.css
.button { background: var(--color-primary); border-radius: 0.5rem; padding: 0.5rem 1rem;}Usage
<CodeBlock language="tsx" showLineNumbers highlightLines={[3, 4]}>
{`import { Button } from 'ds0';
<Button variant="primary">
Click me
</Button>`}
</CodeBlock>API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
language | string | 'text' | Syntax highlighting language |
showLineNumbers | boolean | false | Display line numbers |
highlightLines | number[] | [] | Lines to highlight |
copyable | boolean | true | Show copy button |
title | string | — | Optional title bar |
Related Components
| Component | When to Use Instead |
|---|---|
| Code | Inline code snippets |
| Terminal | Interactive terminal display |
| DiffViewer | Comparing code changes |