CodeBlock

Read-only code with copy, for docs and setup only.

$ npx shadcn@latest add https://mahrdesign.faizintifada.com/r/code-block.json

File

Grey tray (--muted, 3 px, radius 16) → 32 px header with the file name and an icon-only copy → white card (radius 13, --edge ring), mono 13/20. Copy: transitions.dev 09 Icon swap to a tick (250 ms), shown on the click, back after 1.4 s; "Copy failed" if the clipboard refuses.

save-bar.tsx
import { Button } from "@/components/ui/button"export function SaveBar({ saving }: { saving: boolean }) {  return (    <Button variant="primary" loading={saving} loadingText="Menyimpan…">      Simpan    </Button>  )}

Line numbers + highlighted lines

Long lines wrap by default; the number stays at the top of its line. Numbers in --placeholder, sticky on sideways scroll (wrap={false}), not selectable, hidden from screen readers. highlightLines: --primary-subtle fill with a 2 px primary edge on the left.

payroll-dates.ts
const payday = lastWorkingDay(2026, 11) // Kamis, 24 Desconst cutoff = addWorkingDays(payday, -4) // Jumat, 18 Desexport function payrollDates() {  return { payday, cutoff }}

Shell command

language="bash": the header shows the language when there is no file name.

bash
bunx --bun shadcn@latest add https://mahrdesign.faizintifada.com/r/code-block.json

Max height

maxHeight={240}: a long file scrolls inside the card; the card is then a focusable region (Tab, then arrow keys).

employees.json
{  "employees": [    { "id": "MC-001", "department": "Engineering", "leaveLeft": 12 },    { "id": "MC-002", "department": "Engineering", "leaveLeft": 11 },    { "id": "MC-003", "department": "Engineering", "leaveLeft": 10 },    { "id": "MC-004", "department": "Engineering", "leaveLeft": 9 },    { "id": "MC-005", "department": "Engineering", "leaveLeft": 8 },    { "id": "MC-006", "department": "Engineering", "leaveLeft": 7 },    { "id": "MC-007", "department": "Engineering", "leaveLeft": 12 },    { "id": "MC-008", "department": "Engineering", "leaveLeft": 11 },    { "id": "MC-009", "department": "Engineering", "leaveLeft": 10 },    { "id": "MC-010", "department": "Engineering", "leaveLeft": 9 },    { "id": "MC-011", "department": "Engineering", "leaveLeft": 8 },    { "id": "MC-012", "department": "Engineering", "leaveLeft": 7 },    { "id": "MC-013", "department": "Engineering", "leaveLeft": 12 },    { "id": "MC-014", "department": "Engineering", "leaveLeft": 11 }  ]}

Plain block (no header)

No file name, no language and copyable={false}: only the tray and the card.

Is the user's next step to read code?├─ Yes → CodeBlock└─ No  → plain text, a Callout or a Table

When to use

  • Read-only code or a shell command in docs, setup notes and this gallery.
  • A decision tree or another fixed-width text block (copyable={false}, no header).

When not to use

  • Anything an HR user reads in the app (slip, leave, profile) → never code; use Card, Table or a Callout.
  • Code the user edits → a code editor, not this.
  • One short token in a sentence (e.g. --primary) → inline <code> in the text.

Do and don't

DoName the fileA file name in the header tells the engineer where the code goes and gives the colours their language.
Don'tCode in HR screensMaHR users are not technical. CodeBlock is for docs and setup only, never inside the app.

Installation

Add CodeBlock with the shadcn CLI (your project needs a components.json and the MaHR theme: https://mahrdesign.faizintifada.com/r/theme.json), or copy the files by hand.

terminal
bunx --bun shadcn@latest add https://mahrdesign.faizintifada.com/r/code-block.json

API

CodeBlock

import { CodeBlock } from "@/components/ui/code-block"
PropTypeDefaultDescription
codestring–Required. A trailing newline is dropped.
filename · languagestring · string–tsx, ts, jsx, js, json, bash, css, html are coloured; other values are plain text. The language comes from the file extension when not set.
showLineNumbersbooleanfalseSticky numbers, not selectable.
highlightLinesnumber[]–1-based line numbers.
maxHeightnumber | string–e.g. 480 or "40vh"; the code scrolls inside after it.
wrapbooleantrueLong lines wrap inside the card. false = one line each, scroll sideways (sticky line numbers).
copyablebooleantruefalse + no label = no header.
classNamestring–On the root <figure>.

CodeLines · CodeFrame (advanced)

import { CodeLines } from "@/components/ui/code-block" import { CodeFrame } from "@/components/ui/code-block-parts"
PropTypeDefaultDescription
CodeLinesasync Server Component–Only the coloured lines (same props as CodeBlock minus the frame). Pass them into a client component.
CodeFrameClient Component–label · copyText · maxHeight · children: the tray, header and card around lines you swap on the client (gallery Installation).