Code block
In reviewLive · web
Full chrome: filename · language · copy (tab to it, hit Enter)
import { CodeBlock } from '@dizyx/nockerl-react';
export function Viewer() {
return <CodeBlock filename="backoff.ts"
language="typescript" showLineNumbers lines={lines} />;
}
// nextDelay caps the exponential backoff at 30s and adds jitter so a fleet never stampedes
No header · line numbers · a quiet, recessed well
{
"engine": "cloud-agent",
"maxBudgetUsd": 5,
"streaming": true
}
Wrap toggle: long line scrolls (off) or reflows (on)
import { CodeBlock } from '@dizyx/nockerl-react';
export function Viewer() {
return <CodeBlock filename="backoff.ts"
language="typescript" showLineNumbers lines={lines} />;
}
// nextDelay caps the exponential backoff at 30s and adds jitter so a fleet never stampedes
Unified diff: added / removed (warm status + a +/- glyph, never color alone)
fun nextDelay(attempt: Int): Long =
minOf(15_000, 1_000 shl attempt)
minOf(30_000, 1_000 shl attempt)
.plus(Random.nextLong(250))
Copy writes to the clipboard and confirms Copied for ~2s · the code region is a focusable, scrollable target. The island is live.
// Web: React, consuming @dizyx/nockerl-tokens. (Web is the laggard platform. Spec + live demo,// not yet exported from @dizyx/nockerl-react; promotion is tracked.)
export function FileViewer({ source }: { source: string }) { return ( <CodeBlock filename="backoff.ts" language="typescript" code={source} showLineNumbers highlightLines={[4]} onCopy={() => track('code.copy')} /> );}
// Unified-diff mode: added/removed lines get a warm wash + a +/- gutter.<CodeBlock filename="backoff.kt" language="kotlin" diff oldCode={before} code={after} />;// Android: Jetpack Compose (canonical). The dedicated viewer body lives in// com.nockerl.app.files.ui; the diff variant in com.nockerl.app.chat.ui.import com.nockerl.app.files.ui.FileViewerContentimport com.nockerl.app.files.ui.LanguageBadgeimport com.nockerl.app.chat.domain.computeDiff
// Header chrome (filename + language pill) is supplied by the surrounding sheet:LanguageBadge(language = "TypeScript")
// The recessed, 2D-scrollable monospace well (line-number gutter; lines never wrap):FileViewerContent( content = state.viewerContent, // FileContent(content, language, isBinary, error) isLoading = state.isViewerLoading, modifier = Modifier.fillMaxSize(),)
// Unified diff for an Edit/Write (red/green lines, +/- gutter, copy of the new content):val diffLines = computeDiff(old = before, new = after) // List<DiffLine>// macOS: SwiftUI, from the NockerlDesign SwiftPM package. `NockerlCodeBlock` is a// RECESSED monospace well (code sinks into the page, law §2): an optional filename// header that also hosts the copy button, an optional line-number gutter, and// horizontal scrolling. Lines NEVER wrap unless `wrap` is set. Replaces Voice's raw// `.monospaced` Text. The `code` argument is the first positional.import NockerlDesign
NockerlCodeBlock( source, // the source text, rendered verbatim filename: "backoff.swift", // header title + copy button; omit → no header showLineNumbers: true)
// No filename → the well renders without a header (copy still appears where the// platform has a pasteboard).NockerlCodeBlock(snippet)
// Soft-wrap long lines instead of scrolling horizontally.NockerlCodeBlock(longLine, wrap: true)
// Syntax highlighting, highlight-lines, and the unified-diff mode are documented// web/Android-first follow-ups, not in NockerlDesign yet.Parameters
Section titled “Parameters”| Prop | Type | Default | Description |
|---|---|---|---|
code * | string | The source to display. Rendered in the font.family.mono well. | |
filename | string | Shown in the header bar. Omit → the block renders with no header. | |
language | 'typescript' | 'kotlin' | 'swift' | 'json' | 'shell' | Drives the cyan-soft language pill + the file-type tint dot. | |
showLineNumbers | boolean | false | Right-aligned, muted line-number gutter (sticky under horizontal scroll). |
highlightLines | number[] | [] | Lines to emphasize: a faint cyan wash + a left cyan rail (a shape, not a glow). This inset rail is the one sanctioned Law 6 carve-out (adjudication B18): editorial emphasis inside a code surface only, always paired with a wash, never status, never selection, and never outside code. |
wrap | boolean | false | Soft-wrap long lines. Off → lines scroll horizontally (the app default). |
diff | boolean | false | Unified-diff mode: a +/- gutter with warm added/removed washes. |
oldCode | string | The pre-change source, diffed against code when diff is set. | |
onCopy | () => void | Fires after a successful copy. The button confirms Copied for ~2s. |
| Parameter | Type | Default | Description |
|---|---|---|---|
content * | FileContent? | FileContent(content, language, isBinary, error). Drives the well + its empty / binary / error states. | |
isLoading * | Boolean | Shows a centered progress indicator while the file is fetched. | |
modifier | Modifier | Modifier | Applied to the content root. Pass Modifier.fillMaxSize() for a full viewer. |
language | String | LanguageBadge(language), the cyan-soft pill beside the filename in the sheet top bar. | |
diffLines | List<DiffLine> | DiffView input from computeDiff(old, new); each DiffLine(type, text, lineNumber) is ADDED / REMOVED / UNCHANGED. | |
newContent | String | The resulting content the DiffView copy button writes to the clipboard. |
NockerlCodeBlock is the recessed well: a filename header (which also hosts the copy
button), an optional line-number gutter, and horizontal scroll. It renders the
platform .monospaced design (the Swift token build emits no mono type role yet;
see drift). The code argument is the first positional.
| Parameter | Type | Default | Description |
|---|---|---|---|
code * | String | First positional arg: the source text, rendered verbatim in the mono well. | |
filename | String? | nil | Header title (e.g. "backoff.swift"). The header also hosts the copy button; omit → no header (copy still shows where the platform has a pasteboard). |
showLineNumbers | Bool | false | Render the muted, right-aligned line-number gutter. |
wrap | Bool | false | Soft-wrap long lines instead of scrolling horizontally (horizontal scroll is the default idiom). |