Code Block

@sushindustries/ui

A highlighted code slab in the CLI's colours, with a copy button that confirms in place.

Last updated Aug 17, 20266 min read
View as MarkdownEdit on GitHub

Code on this site is a terminal, whichever theme the page is in: a warm charcoal slab that does not invert, with a lit top edge and a contact shadow so it sits on the paper rather than tinting a region of it.

The syntax palette is the CLI's own xterm-256 hues, so a command pasted from the terminal into a fence keeps its colours.

Viewport width
Phone22remthe floor, the narrowest this promises to work at
tanstacktanstack add https://adamjurek.com/r/tanstack/code-block.jsonshadcnpnpm dlx shadcn@latest add https://adamjurek.com/r/shadcn/code-block.json

Why it is built this way

Highlighting is synchronous, so a page full of these renders during SSR and nothing re-highlights on hydration - only the copy button is live. Before this component existed the same highlighted markup was built in two places (MarkdownView for fences, the showcase block for demo source), and the copy button would have made it three. One component, one slab, one palette.

The colours are semantic tokens - --syn-keyword, --syn-string, --syn-command and friends - defined once in the stylesheet's :root. A shell fence gets the deeper ground and its command in the CLI's brand orange, because "type this" and "read this" are different asks and should read differently before the first word does.

What it does not do

It does not scroll its button. The copy chip sits on a code-shell wrapper outside the scrolling content, so a long line scrolls under it. It does not load grammars dynamically - the languages are the ones this site's content uses, registered by hand in highlighter.ts, and adding one is a one-line, noticeable change.

Install commands are not written here

Anything in packages/ui/registry.ts gets its TanStack and shadcn commands attached automatically, so there is nothing to keep in sync.

Install

tanstack add https://adamjurek.com/r/tanstack/code-block.json
shell
pnpm dlx shadcn@latest add https://adamjurek.com/r/shadcn/code-block.json
shell
pnpm add @sushindustries/ui @sushindustries/atoms
shell

What you get

Version0.1.0
Categorycontent · Rendering
Filescode-block.tsx, highlighter.ts
Dependencies@tanstack/highlight@0.0.10
Also installsiconIconThe glyph set, generated from a Markdown table where every drawing carries its reason. One component, typed names, no icon font.@sushindustries/ui · content, copy-buttonCopy ButtonA glass chip that writes to the clipboard and confirms in the button itself, then hands back.@sushindustries/ui · content
Tagscode, highlight, copy, ssr
UsesIconIconThe glyph set, generated from a Markdown table where every drawing carries its reason. One component, typed names, no icon font.@sushindustries/ui · contentCopy ButtonCopy ButtonA glass chip that writes to the clipboard and confirms in the button itself, then hands back.@sushindustries/ui · content
Used byMarkdown ViewMarkdown ViewRenders Markdown with callouts, CSS-only tabs, custom blocks and highlighted code.@sushindustries/ui · content