On this page

InstallationUsageHeader and actionsLines and marksTerminal and disclosureCompositionAPI ReferenceCodeSnippetCodeBlockContent

Code block

Read-only source, commands, and diffs with shared code tokens, line-level state, copy behavior, and optional disclosure.

Policy
policy.ts
1export function decide(input: Request) {2  if (input.risk === "high") return "review";3  return "allow";4}
1<CodeSnippet2  code={source}3  language="typescript"4  title="Policy"5  filename="policy.ts"6  lineNumbers7  actions={2}8/>

Installation

text
import { CodeSnippet } from "@dome-systems/ds-dashboard/components";

Usage

Use CodeSnippet for the common case: one source string and an optional title, file label, line numbers, and actions.

typescript
escalation.ts
1export function decide(input: Request) {2  if (input.risk === "high") return "review";3  return "allow";4}
1<CodeSnippet2  code={source}3  language="typescript"4  filename="escalation.ts"5  lineNumbers6/>

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";
}
1<CodeSnippet2  code={source}3  language="typescript"4  header={false}5  actions={2}6/>7
8<CodeSnippet9  code={source}10  language="typescript"11  header={false}12  actions={2}13  floatingActions14/>

Lines and marks

Line marks use source-line numbers. Removed lines are visually retained in a diff but excluded from the copy value.

Policy update
policy.ts
24export function decide(input: Request) {25  if (input.risk === "high") return "review";26  return "allow";27}
1<CodeSnippet2  code={source}3  language="typescript"4  lineNumbers5  startLine={24}6  highlightLines={[25]}7  addedLines={[26]}8  removedLines={[24]}9/>

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.

Terminal
$ pnpm lintsrc/policy.ts  ✓
typescript
policy.ts
1export function decide(input: Request) {2  if (input.risk === "high") return "review";3  return "allow";4}5
6export function auditDecision(input: Request) {7  return input.risk === "high" ? "review" : "allow";8}9
10export function formatDecision(decision: string) {11  return { decision, recorded: true };12}
1<CodeSnippet2  code={"$ pnpm lint\nsrc/policy.ts  ✓"}3  language="shell"4  terminal5/>6
7<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.

Policy
policy.ts
1export function decide(input: Request) {2  if (input.risk === "high") return "review";3  return "allow";4}
1<CodeBlock>2  <CodeBlockHeader>3    <CodeBlockTitle>Policy</CodeBlockTitle>4    <CodeBlockFilename>policy.ts</CodeBlockFilename>5    <CodeBlockActions>6      <CodeBlockWrapButton />7      <CodeBlockCopyButton value={source} language="typescript" />8    </CodeBlockActions>9  </CodeBlockHeader>10  <CodeBlockContent language="typescript" lineNumbers>11    {source}12  </CodeBlockContent>13</CodeBlock>

API Reference

CodeSnippet

PropTypeDefaultDescription
codestring—The source displayed by the ready-made snippet and copied by its copy action.
languagestring"text"Sets the language hint. TypeScript, JavaScript, JSON, YAML, and shell variants receive built-in semantic highlighting.
titlestring—Text at the start of the metadata header. Defining it creates the header.
filenamestring—A file label after the title. Defining it creates the header; with no title it aligns directly to the header padding.
headerboolean—Set false to suppress a metadata header. Without this prop, a header appears only when title or filename is defined.
actions0 | 1 | 2 | 31Copy only, copy plus wrap, or copy plus wrap and full-screen.
floatingActionsbooleanfalseWhen 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.
wrapbooleanfalseAllows long source lines to wrap. The interactive wrap action owns this state when it is present.
lineNumbersbooleanfalseShows a line-number gutter.
startLinenumber1The number shown for the first source line.
highlightLinesnumber[]—Neutral emphasis for exact source-line numbers.
addedLinesnumber[]—Success treatment for exact source-line numbers.
removedLinesnumber[]—Error treatment for exact source-line numbers; these lines are omitted when copied.
terminalbooleanfalseTreats leading $ lines as commands and the lines between them as terminal output.
showMorebooleanfalseShows a five-line preview and a disclosure that renders the rest of the supplied source.
maxHeightnumber—Maximum source viewport height in pixels. The source scrolls inside that cap.

CodeBlockContent

PropTypeDefaultDescription
languagestring—The highlighting and terminal-language hint.
wrapbooleanfalseUses wrapped, break-anywhere source lines.
lineNumbersbooleanfalseDisplays the line-number gutter.
startLinenumber1The first line number.
highlightLinesnumber[]—Neutral highlighted source lines.
addedLinesnumber[]—Added source lines.
removedLinesnumber[]—Removed source lines.
terminalbooleanfalseStyles transcript output and shell prompts.
maxHeightnumber—A pixel height cap for the scrollable source area.