Code Snippet displays formatted code blocks in single-line and multi-line layouts with optional tab navigation.
Loading demo: code-snippet-real-world
npx sdaia-ui@latest add code-snippet
import { CodeSnippet } from '@/components/ui/CodeSnippet';<CodeSnippet type="single-line" code="..." />A compact code snippet for displaying a single line of code.
Loading demo: code-snippet-single-line
Multi-line code snippet with tab navigation for switching between files or examples.
Loading demo: code-snippet-multi-line-tabs
Props for the CodeSnippet component.
Prop | Type | Default | Required |
|---|---|---|---|
variant | 'multi-line-with-tabs' | 'multi-line-without-tabs' | 'single-line' | - | required |
showHeader | boolean | true for multi-line variants; no effect for single-line. | optional |
showLineNumbers | boolean | true for multi-line variants; no effect for single-line. | optional |
codeBodyMinHeight | string | - | optional |
copyText | string | - | optional |
onCopy | () => void | Promise<void> | - | optional |
showMoreButton | boolean | true | optional |
showMoreLabel | string | "Show More" | optional |
onShowMore | () => void | - | optional |
showCopyButton | boolean | true | optional |
labels | Partial<CodeSnippetLabels> | English strings | optional |
Multi-line body with language tabs (`Tabs` type `underline`, size `md`).
Prop | Type | Default | Required |
|---|---|---|---|
variant | 'multi-line-with-tabs' | - | required |
tabItems | TabItem[] | - | required |
tabPanels | Record<string, string> | - | required |
tabValue | string | - | optional |
defaultTabValue | string | - | optional |
onTabValueChange | (value: string) => void | - | optional |
showHeader | boolean | true for multi-line variants; no effect for single-line. | optional |
showLineNumbers | boolean | true for multi-line variants; no effect for single-line. | optional |
codeBodyMinHeight | string | - | optional |
copyText | string | - | optional |
onCopy | () => void | Promise<void> | - | optional |
showMoreButton | boolean | true | optional |
showMoreLabel | string | "Show More" | optional |
onShowMore | () => void | - | optional |
showCopyButton | boolean | true | optional |
Multi-line body with optional file-style header (icon + title).
Prop | Type | Default | Required |
|---|---|---|---|
variant | 'multi-line-without-tabs' | - | required |
code | string | - | optional |
codeContent | ReactNode | - | optional |
lineCount | number | derived from `code` | optional |
fileTitle | string | "" | optional |
headerIcon | ReactNode | - | optional |
showHeader | boolean | true for multi-line variants; no effect for single-line. | optional |
showLineNumbers | boolean | true for multi-line variants; no effect for single-line. | optional |
codeBodyMinHeight | string | - | optional |
copyText | string | - | optional |
onCopy | () => void | Promise<void> | - | optional |
showMoreButton | boolean | true | optional |
showMoreLabel | string | "Show More" | optional |
onShowMore | () => void | - | optional |
showCopyButton | boolean | true | optional |
One-line install / CLI style row.
Prop | Type | Default | Required |
|---|---|---|---|
variant | 'single-line' | - | required |
commandPrefix | ReactNode | - | required |
command | ReactNode | - | required |
showHeader | boolean | true for multi-line variants; no effect for single-line. | optional |
showLineNumbers | boolean | true for multi-line variants; no effect for single-line. | optional |
codeBodyMinHeight | string | - | optional |
copyText | string | - | optional |
onCopy | () => void | Promise<void> | - | optional |
showMoreButton | boolean | true | optional |
showMoreLabel | string | "Show More" | optional |
onShowMore | () => void | - | optional |
showCopyButton | boolean | true | optional |
How this component behaves at the three system breakpoints. Spacing and type tokens switch automatically at 768px and 1280px.
| Screen | Behavior |
|---|---|
| Desktop (1280px and up) | Fills the width of its container. Long code lines wrap; the code itself always stays left to right. Tabs scroll sideways if they don't fit. |
| Tablet (768–1279px) | Same layout as desktop, with the tablet token values. |
| Phone (under 768px) | Same, with the mobile token values. Below 768px the single-line command row wraps so the copy button moves under long commands. Long file names are truncated. |