CodeBlock
Read-only code with copy, for docs and setup only.
$ npx shadcn@latest add https://mahrdesign.faizintifada.com/r/code-block.jsonFile
Line numbers + highlighted lines
Shell command
Max height
Plain block (no header)
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
Name the fileA file name in the header tells the engineer where the code goes and gives the colours their language.
Code 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.
API
CodeBlock
import { CodeBlock } from "@/components/ui/code-block"| Prop | Type | Default | Description |
|---|---|---|---|
code | string | – | Required. A trailing newline is dropped. |
filename · language | string · 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. |
showLineNumbers | boolean | false | Sticky numbers, not selectable. |
highlightLines | number[] | – | 1-based line numbers. |
maxHeight | number | string | – | e.g. 480 or "40vh"; the code scrolls inside after it. |
wrap | boolean | true | Long lines wrap inside the card. false = one line each, scroll sideways (sticky line numbers). |
copyable | boolean | true | false + no label = no header. |
className | string | – | On the root <figure>. |
CodeLines · CodeFrame (advanced)
import { CodeLines } from "@/components/ui/code-block"
import { CodeFrame } from "@/components/ui/code-block-parts"| Prop | Type | Default | Description |
|---|---|---|---|
CodeLines | async Server Component | – | Only the coloured lines (same props as CodeBlock minus the frame). Pass them into a client component. |
CodeFrame | Client Component | – | label · copyText · maxHeight · children: the tray, header and card around lines you swap on the client (gallery Installation). |