Code block
Read-only source, commands, and diffs with shared code tokens, line-level state, copy behavior, and optional disclosure.
export function decide(input: Request) { if (input.risk === "high") return "review"; return "allow";}<CodeSnippet code={source} language="typescript" title="Policy" filename="policy.ts" lineNumbers actions={2}/>Installation
import { CodeSnippet } from "@catalog-developer/components";Usage
Use CodeSnippet for the common case: one source string and an optional title, file label, line numbers, and actions.
export function decide(input: Request) { if (input.risk === "high") return "review"; return "allow";}<CodeSnippet code={source} language="typescript" filename="escalation.ts" lineNumbers/>Header and actions
Headers are optional. Without one, normal actions stay inside the source surface; floatingActions makes them compact and hover-revealed instead.
export function decide(input: Request) {
if (input.risk === "high") return "review";
return "allow";
}export function decide(input: Request) {
if (input.risk === "high") return "review";
return "allow";
}<CodeSnippet code={source} language="typescript" header={false} actions={2}/> <CodeSnippet code={source} language="typescript" header={false} actions={2} floatingActions/>Lines and marks
Line marks use source-line numbers. Removed lines are visually retained in a diff but excluded from the copy value.
export function decide(input: Request) { if (input.risk === "high") return "review"; return "allow";}<CodeSnippet code={source} language="typescript" lineNumbers startLine={24} highlightLines={[25]} addedLines={[26]} removedLines={[24]}/>Terminal and disclosure
Terminal mode recognizes a leading prompt. Show more is a disclosure: it renders a short preview first, then the full source after activation.
$ pnpm lintsrc/policy.ts ✓export function decide(input: Request) { if (input.risk === "high") return "review"; return "allow";}
export function auditDecision(input: Request) { return input.risk === "high" ? "review" : "allow";}
export function formatDecision(decision: string) { return { decision, recorded: true };}<CodeSnippet code={"$ pnpm lint\nsrc/policy.ts ✓"} language="shell" terminal/> <CodeSnippet code={longSource} language="typescript" showMore lineNumbers />Composition
Compose a custom surface when the standard snippet layout is not enough. The parts use the same code tokens and line behavior, so custom chrome does not create a second code style.
export function decide(input: Request) { if (input.risk === "high") return "review"; return "allow";}<CodeBlock> <CodeBlockHeader> <CodeBlockTitle>Policy</CodeBlockTitle> <CodeBlockFilename>policy.ts</CodeBlockFilename> <CodeBlockActions> <CodeBlockWrapButton /> <CodeBlockCopyButton value={source} language="typescript" /> </CodeBlockActions> </CodeBlockHeader> <CodeBlockContent language="typescript" lineNumbers> {source} </CodeBlockContent></CodeBlock>API Reference
CodeSnippet
| Prop | Type | Default | Description |
|---|---|---|---|
code | string | — | The source displayed by the ready-made snippet and copied by its copy action. |
language | string | "text" | Sets the language hint. TypeScript, JavaScript, JSON, YAML, and shell variants receive built-in semantic highlighting. |
title | string | — | Text at the start of the metadata header. Defining it creates the header. |
filename | string | — | A file label after the title. Defining it creates the header; with no title it aligns directly to the header padding. |
header | boolean | — | Set false to suppress a metadata header. Without this prop, a header appears only when title or filename is defined. |
actions | 0 | 1 | 2 | 3 | 1 | Copy only, copy plus wrap, or copy plus wrap and full-screen. |
floatingActions | boolean | false | When the header is off, switches its persistent in-surface controls to a compact hover-revealed treatment. |
size | "default" | "sm" | "default" | Changes the source density. |
variant | "default" | "destructive" | "default" | Uses the destructive code surface treatment for an unsafe or failing result. |
wrap | boolean | false | Allows long source lines to wrap. The interactive wrap action owns this state when it is present. |
lineNumbers | boolean | false | Shows a line-number gutter. |
startLine | number | 1 | The number shown for the first source line. |
highlightLines | number[] | — | Neutral emphasis for exact source-line numbers. |
addedLines | number[] | — | Success treatment for exact source-line numbers. |
removedLines | number[] | — | Error treatment for exact source-line numbers; these lines are omitted when copied. |
terminal | boolean | false | Treats leading $ lines as commands and the lines between them as terminal output. |
showMore | boolean | false | Shows a five-line preview and a disclosure that renders the rest of the supplied source. |
maxHeight | number | — | Maximum source viewport height in pixels. The source scrolls inside that cap. |
CodeBlockContent
| Prop | Type | Default | Description |
|---|---|---|---|
language | string | — | The highlighting and terminal-language hint. |
wrap | boolean | false | Uses wrapped, break-anywhere source lines. |
lineNumbers | boolean | false | Displays the line-number gutter. |
startLine | number | 1 | The first line number. |
highlightLines | number[] | — | Neutral highlighted source lines. |
addedLines | number[] | — | Added source lines. |
removedLines | number[] | — | Removed source lines. |
terminal | boolean | false | Styles transcript output and shell prompts. |
maxHeight | number | — | A pixel height cap for the scrollable source area. |