tsimport {XDSCodeBlock} from '@xds/core/CodeBlock'
| Guidance | Practices |
|---|---|
| Do | Set the language prop to match the code content so syntax highlighting is accurate. Use "plaintext" when the language is unknown. |
| Do | Add a title when the code represents a file — it gives readers context and appears in the header bar alongside the copy button. |
| Do | Use XDSCode for short inline references like function names or CLI flags, and XDSCodeBlock for standalone multi-line snippets. |
| Don't | Enable line numbers on short snippets (under 5 lines) where they add clutter without helping navigation. |
| Don't | Nest a code block inside a scrollable container — use the maxHeight prop instead, which handles overflow natively. |
| Prop | Type | Description |
|---|---|---|
childrenrequired | ReactNode | Code content. |
xstyle | StyleXStyles | StyleX styles for layout customization. Must be a stylex.create() value. |
className | string | CSS class name for the root element. Prefer xstyle for styling. |
style | CSSProperties | Inline styles. Prefer xstyle for StyleX-optimized styling. |
data-testid | string | Test selector for automated testing frameworks. |
| Prop | Type | Description |
|---|---|---|
coderequired | string | The code string to display. |
language | string (default: 'plaintext') | Language for syntax highlighting. Use "plaintext" to disable. |
title | string | Filename or label shown in the header bar. |
hasLanguageLabel | boolean (default: true) | Show the language name in the header bar. Hidden when language is "plaintext". |
hasLineNumbers | boolean (default: false) | Show a line number gutter. |
highlightLines | number[] | 1-indexed line numbers to highlight. |
hasCopyButton | boolean (default: true) | Show a copy-to-clipboard button. |
onCopy | () => void | Callback after the code is copied. |
isWrapped | boolean (default: false) | Wrap long lines instead of enabling horizontal scroll. |
maxHeight | number | string | Max height before the block scrolls vertically. |
size | 'sm' | 'md' (default: 'md') | Text size variant. |
tokenizer | (code: string, language: string) => Array<{type: string; start: number; end: number}> | Custom tokenizer override for unsupported languages. |
isCollapsible | boolean (default: false) | Allow collapsing the code body into just the header bar. Starts expanded; the header becomes clickable to toggle. Only shows the toggle when the code exceeds collapsibleThreshold lines. |
collapsibleThreshold | number (default: 10) | Minimum number of lines before the collapse toggle appears. Below this threshold the code block renders normally even when isCollapsible is true. |
xstyle | StyleXStyles | StyleX styles for layout customization. Must be a stylex.create() value. |
className | string | CSS class name for the root element. Prefer xstyle for styling. |
style | CSSProperties | Inline styles. Prefer xstyle for StyleX-optimized styling. |
data-testid | string | Test selector for automated testing frameworks. |