Skip to content

Data display

Code block

Code to read or copy, with a caption and a Copy button; it can draw a highlighter's tokens.

shell
pnpm add @elsikora/keystone-ui-kit

Installation

Terminal
pnpm add @elsikora/keystone-ui-kit

Usage

Import
import { CodeBlock } from "@elsikora/keystone-ui-kit";
docs/code-block/default.example.tsx
import { CodeBlock } from "@elsikora/keystone-ui-kit";
export default function CodeBlockDefaultExample() {  return <CodeBlock label="shell" code="pnpm add @elsikora/keystone-ui-kit" />;}

Examples

Default

shell
pnpm add @elsikora/keystone-ui-kit

Highlighted

Tones are drawn by the kit's theme; no colour crosses the API.

round.ts
// settle the roundconst win = stake * 2;

Without Copy

KEYSTONE_PORT=8080

API reference

CodeBlock

PropTypeDefaultDescription
codestring-The text: what is copied, and what is drawn without tokens.
labelstring-A caption: a file name, a shell.
copybooleantrueA Copy button in the caption row.
copyLabels{ copy: string; copied: string; failed: string }{ copy: "Copy", copied: "Copied", failed: "Copy failed" }The button's words, and what is said when the copy is done or refused.
tokensReadonlyArray<ReadonlyArray<{ content: string; tone?: TCodeTone }>>-Lines of tokens drawn in place of code.

Notes

  • The code scrolls sideways and takes the keyboard's focus; Copy says "Copied" to a screen reader.