For AI agents: the complete documentation index is available at https://wallarm.github.io/design-system/llms.txt, the full documentation bundle is available at https://wallarm.github.io/design-system/llms-full.txt, and this page is available as Markdown at https://wallarm.github.io/design-system/components/code-snippet.md.

CodeSnippet

A block of code to be read and copied, never edited — reach for InlineCodeSnippet when the code belongs inside a sentence, and a real editor when the value is meant to change. Everything beyond the code is composed: a CodeSnippetHeader carrying a title or tabs, CodeSnippetActions for copy, wrap and fullscreen, CodeSnippetLineNumbers, and per-line colour, prefixes and folds — and highlighting happens only inside a CodeSnippetAdapterProvider. The snippet sits inside a display: contents wrapper that keeps it mounted across fullscreen, so space snippets with their own className (for example mt-16) or a gap on the parent — not space-*, divide-* or child selectors on the parent.

Source · Storybook

Usage

import { CodeSnippetCode, CodeSnippetContent, CodeSnippetRoot } from '@wallarm-org/design-system/CodeSnippet';

Examples

CodeSnippet

With line numbers

CodeSnippetLineNumbers is a sibling of the code inside CodeSnippetContent, so the gutter is something you compose in rather than a prop you switch on.

Sizes

The three sizes. sm is the default at 12px; md and lg step the code to 14 and 16px for a block meant to be read from further away.

Line annotations

lines, keyed by line number, tints a line and hangs a prefix off it — here a tooltipped icon on each of the three headers worth calling out.

Line colors

The seven line colours are semantic, so choose by what the line means — danger for the attack, info for the aside — not by which tint reads best.

Line ranges

ranges narrows the emphasis to character offsets inside the line — start inclusive, end exclusive — and once a line has them only the range is coloured, though the line's own background stays.

Text styles

textStyle overrides the weight or slant a colour would have chosen, with className and style left for the cases the three named styles do not cover.

Line with prefix

A + and - prefix over success and danger lines gives you a diff without a diff component.

Line wrapping

wrapLines against the same code unwrapped, in three pairs — what to check is that prefixes, colour sticks and fold toggles stay on the first visual row of a wrapped line.

With both scrolls

Given a fixed height inside a narrow column, the block scrolls in both directions rather than pushing its container around.

Custom starting line

startingLineNumber renumbers the gutter, for a fragment lifted out of a longer file.

JSON with shiki

Shiki, supplied through CodeSnippetAdapterProvider, uses VS Code-style grammars. The adapter lazily initializes its supported languages and github-light theme with the Oniguruma WASM engine on the first highlight call.

Typescript with prism

TypeScript highlighted with Prism. Its loader emits only the Prism adapter's dependencies; unused Shiki and highlight.js loaders are discarded by the consumer.

Bash with prism

A multi-line curl under Prism, where the continuation backslashes and the quoted JSON body are the parts a highlighter usually gets wrong.

HTML with highlight js

HTML highlighted with highlight.js. The adapter loads the library lazily and exposes the languages listed by its getSupportedLanguages() method.

HTTP request with prism

language='http' is a grammar in its own right — method, path and version on the first line, then header names told apart from their values.

HTTP response with shiki

The response side, where the JSON body after the headers is highlighted as JSON rather than as more header text.

With header

CodeSnippetHeader with a CodeSnippetTitle names the file the code came from, as a bar above the block rather than a caption on it.

With tabs and actions

Tabs in the header swap the code the block is given, which is how one command per package manager is built; the actions sit at the far end of the same bar.

With floating actions

With no header to hold them, CodeSnippetActions floats over the top-right of the code — the shape for a block whose only affordance is copy.

Show more

maxLines clips the block and adds the control itself — but only when it would hide at least three lines, so the middle snippet stays open; the third passes props to the real button by rendering CodeSnippetShowMoreButton in place of the automatic one.

HTTP request with folding

getHttpFolds reads an HTTP message and returns its fold regions, so the reader opens the headers or the body rather than scrolling past both.

HTTP response with folding

The same helper on a response, where the body is usually the half worth folding away.

With folding expanded

Folds over coloured lines: a collapsed fold takes its colours and prefixes with it, and hands them back on expand.

With folding and show more

Folds, maxLines and startingLineNumber together — fold line numbers are absolute, so getHttpFolds has to be given the same offset the gutter uses.

Fullscreen inside drawer

Fullscreen opened from a modal Drawer stacks above it as a nested layer: its buttons stay clickable, and Escape or a backdrop click leaves fullscreen while the drawer stays open.

InlineCodeSnippet

Default

One snippet in three sentence sizes: size='inherit', the default, scales the type and the padding with whatever it sits in, and hovering offers the copy.

Sizes

The three fixed sizes, each beside the text size it pairs with — set one when the snippet must hold its size regardless of its surroundings.

Non copyable

copyable={false} takes the tooltip and the pointer cursor away with the copy, for a snippet that is only being named rather than reused.

Various content

Commands, JSON, SQL and a quoted message all render in one colour — inline code gets the mono treatment and nothing else.

Props

CodeSnippetActions

PropTypeDefaultDescription
defaultCheckedboolean | undefined
defaultValuestring | number | readonly string[] | undefined
autoFocusboolean | undefined
idstring | undefined
tabIndexnumber | undefined
titlestring | undefined
relstring | undefined
onChangeChangeEventHandler<T, Element> | undefined

CodeSnippetAdapterProvider

PropTypeDefaultDescription
adapter *AdapterInput<TLanguage>Syntax adapter or a loader function that returns a Promise of the adapter. Using a loader function enables code splitting - the adapter bundle will only be loaded when the component mounts.

CodeSnippetCode

PropTypeDefaultDescription
defaultCheckedboolean | undefined
defaultValuestring | number | readonly string[] | undefined
autoFocusboolean | undefined
idstring | undefined
tabIndexnumber | undefined
titlestring | undefined
relstring | undefined
onChangeChangeEventHandler<T, Element> | undefined

CodeSnippetContent

PropTypeDefaultDescription
defaultCheckedboolean | undefined
defaultValuestring | number | readonly string[] | undefined
autoFocusboolean | undefined
idstring | undefined
tabIndexnumber | undefined
titlestring | undefined
relstring | undefined
onChangeChangeEventHandler<T, Element> | undefined
nativeScrollboolean | undefinedfalseUse native browser scroll instead of ScrollArea.

CodeSnippetCopyButton

PropTypeDefaultDescription
titlestring | undefined
defaultCheckedboolean | undefined
defaultValuestring | number | readonly string[] | undefined
autoFocusboolean | undefined
idstring | undefined
tabIndexnumber | undefined
relstring | undefined
colorstring | undefined
onChangeChangeEventHandler<T, Element> | undefined
type"button" | "submit" | "reset" | undefined
disabledboolean | undefined
namestring | undefined
valuestring | number | readonly string[] | undefined
asChildboolean | undefined
size{ small: string; medium: string; large: string; 'inline-edit': string; }
data-testidstring | undefined
variant{ primary: string; outline: string; ghost: string; secondary: string; }
loading{ true: string; }
asC | undefined
fullWidth{ true: string; false: string; }

CodeSnippetFullscreenButton

PropTypeDefaultDescription
titlestring | undefined
defaultCheckedboolean | undefined
defaultValuestring | number | readonly string[] | undefined
autoFocusboolean | undefined
idstring | undefined
tabIndexnumber | undefined
relstring | undefined
colorstring | undefined
onChangeChangeEventHandler<T, Element> | undefined
type"button" | "submit" | "reset" | undefined
disabledboolean | undefined
namestring | undefined
valuestring | number | readonly string[] | undefined
asChildboolean | undefined
size{ small: string; medium: string; large: string; 'inline-edit': string; }
data-testidstring | undefined
variant{ primary: string; outline: string; ghost: string; secondary: string; }
loading{ true: string; }
asC | undefined
fullWidth{ true: string; false: string; }

CodeSnippetHeader

PropTypeDefaultDescription
defaultCheckedboolean | undefined
defaultValuestring | number | readonly string[] | undefined
autoFocusboolean | undefined
idstring | undefined
tabIndexnumber | undefined
titlestring | undefined
relstring | undefined
onChangeChangeEventHandler<T, Element> | undefined

CodeSnippetLineNumbers

PropTypeDefaultDescription
defaultCheckedboolean | undefined
defaultValuestring | number | readonly string[] | undefined
autoFocusboolean | undefined
idstring | undefined
tabIndexnumber | undefined
titlestring | undefined
relstring | undefined
onChangeChangeEventHandler<T, Element> | undefined

CodeSnippetRoot

PropTypeDefaultDescription
titlestring | undefined
defaultCheckedboolean | undefined
defaultValuestring | number | readonly string[] | undefined
autoFocusboolean | undefined
idstring | undefined
tabIndexnumber | undefined
relstring | undefined
onCopyClipboardEventHandler<T> | undefined
onChangeChangeEventHandler<T, Element> | undefined
size{ sm: string; md: string; lg: string; }sm
data-testidstring | undefined
code *stringThe code string to display
languageTLanguage | undefinedtext' as TLanguageProgramming language for syntax highlighting
linesRecord<number, LineConfig> | undefinedEMPTY_LINESPer-line configuration (color, prefix) keyed by line number
startingLineNumbernumber | undefined1Starting line number (default: 1)
wrapLinesboolean | undefinedEnable line wrapping
maxLinesnumber | undefined0Max lines before collapsing. Root auto-renders the default show-more button unless a direct CodeSnippetShowMoreButton child is provided for button-level props.
foldsFoldRegion[] | undefinedFoldable regions that can be collapsed/expanded

CodeSnippetShowMoreButton

PropTypeDefaultDescription
titlestring | undefined
defaultCheckedboolean | undefined
defaultValuestring | number | readonly string[] | undefined
autoFocusboolean | undefined
idstring | undefined
tabIndexnumber | undefined
relstring | undefined
colorstring | undefined
onChangeChangeEventHandler<T, Element> | undefined
type"button" | "submit" | "reset" | undefined
disabledboolean | undefined
namestring | undefined
valuestring | number | readonly string[] | undefined
asChildboolean | undefined
size{ small: string; medium: string; large: string; 'inline-edit': string; }
data-testidstring | undefined
variant{ primary: string; outline: string; ghost: string; secondary: string; }
loading{ true: string; }
asC | undefined
fullWidth{ true: string; false: string; }

CodeSnippetTab

PropTypeDefaultDescription
value *string
asChildboolean | undefined
onFocus((e: FocusEvent<HTMLButtonElement, Element>) => void) | undefined
titlestring | undefined
defaultCheckedboolean | undefined
defaultValuestring | number | readonly string[] | undefined
autoFocusboolean | undefined
idstring | undefined
tabIndexnumber | undefined
relstring | undefined
onChangeChangeEventHandler<T, Element> | undefined
type"button" | "submit" | "reset" | undefined
disabledboolean | undefined
namestring | undefined
data-testidstring | undefined

CodeSnippetTabs

PropTypeDefaultDescription
valuestring | undefined
defaultValuestring | undefined
onValueChange((value: string) => void) | undefined

CodeSnippetTitle

PropTypeDefaultDescription
defaultCheckedboolean | undefined
defaultValuestring | number | readonly string[] | undefined
autoFocusboolean | undefined
idstring | undefined
tabIndexnumber | undefined
titlestring | undefined
relstring | undefined
onChangeChangeEventHandler<T, Element> | undefined

CodeSnippetWrapButton

PropTypeDefaultDescription
titlestring | undefined
defaultCheckedboolean | undefined
defaultValuestring | number | readonly string[] | undefined
autoFocusboolean | undefined
idstring | undefined
tabIndexnumber | undefined
relstring | undefined
colorstring | undefined
onChangeChangeEventHandler<T, Element> | undefined
onToggle((active: boolean, event: MouseEvent<HTMLButtonElement, MouseEvent>) => void) | undefined
type"button" | "submit" | "reset" | undefined
disabledboolean | undefined
namestring | undefined
valuestring | number | readonly string[] | undefined
asChildboolean | undefined
size{ small: string; medium: string; large: string; 'inline-edit': string; }
data-testidstring | undefined
variant{ outline: string; ghost: string; }
loading{ true: string; }
asC | undefined
fullWidth{ true: string; false: string; }
active{ true: string; false: string; }

InlineCodeSnippet

PropTypeDefaultDescription
code *stringThe code content to display
size"inherit" | "sm" | "md" | "lg" | undefinedinheritSize variant
asChildboolean | undefinedfalseRender as the React element passed via children instead of the default <code>. The code prop becomes the cloned element's content.
copyableboolean | undefinedtrueEnable click to copy functionality (default: true)
titlestring | undefined
defaultCheckedboolean | undefined
defaultValuestring | number | readonly string[] | undefined
autoFocusboolean | undefined
idstring | undefined
tabIndexnumber | undefined
relstring | undefined
onChangeChangeEventHandler<T, Element> | undefined