CodeSnippet

React code block with language tabs, line numbers, a copy button, Show More collapsing, and an inline variant. Code stays left to right in Arabic pages.

CodeSnippet takes a languages array; more than one entry shows tabs. Use maxLines for a Show More toggle, and CodeSnippetInline for one-line commands. Code always renders left to right.

When to use

Use CodeSnippet in developer documentation, API portals, and integration guides. Pass several languages to show tabs, use maxLines for long samples, and CodeSnippetInline for single commands or values inside a sentence.

Examples

Multiple languages

Single language, no line numbers

Collapsible with Show More

Inline command

Props

Props declared by CodeSnippet. Native attributes of the underlying element pass through.

<CodeSnippet>

PropTypeDefaultDescription
languagesrequiredCodeSnippetLanguage[]One entry per language. A single entry hides the tab bar (SDGA single-tab).
valuestringControlled active language.
defaultValuestringUncontrolled initial active language (defaults to the first).
onValueChange(value: string) => void
lineNumbersbooleantrueRender the line-number gutter.
maxLinesnumberCollapse to this many lines with a Show More toggle when exceeded.
renderCode(ctx: { code: string; language: string; }) => ReactNodeEscape hatch: render highlighted code yourself; the active code still drives copy + line count.
onCopy(text: string) => void
copyLabelstring'Copy code'Accessible name for the copy button.
copiedLabelstring'Copied'Live-region text announced after a successful copy.

<CodeSnippetInline>

PropTypeDefaultDescription
childrenrequiredstringThe command text - copied verbatim.
prefixreact.ReactNodeLeading label (e.g. npm) - rendered in gold.
onCopy(text: string) => void
copyLabelstring'Copy code'Accessible name for the copy button.
copiedLabelstring'Copied'Live-region text announced after a successful copy.

Accessibility

The copy button has an accessible name and announces success through a live region. The Show More toggle exposes aria-expanded.

Code is rendered inside <pre> and <code> with a forced left-to-right direction, so it reads correctly inside Arabic content. Tabs are keyboard operable.