CodeBlock
<CodeBlock>TailwindCSS ModulesPremium, self-contained code display with built-in syntax highlighting, line numbers, copy, and documentation-friendly controls — no Prism, Shiki, or Highlight.js required.
InstallationColoxo CLI
npx coloxo add code-block --style coloxo-cssES Module ImportPlayground / npm package
import { CodeBlock } from '@coloxo/ui';Design Tokens:
--cx-code-bg--cx-code-keyword--cx-code-string--cx-radius-lg: 12px
1. Variant Matrix
Presentation variants for documentation, terminals, and compact surfaces.
| Variant | Preview |
|---|---|
| default | user.ts TypeScript |
| minimal | user.ts TypeScript |
| compact | user.ts TypeScript |
| borderless | user.ts TypeScript |
| elevated | user.ts TypeScript |
| terminal | TypeScript |
2. Features
Line numbers, highlighting, focus, wrapping, and collapse — without exposing tokenizer internals.
Line numbers + highlight
user.service.ts
TypeScript
const user = await getUser("acct_1a2b3c4d5e6f7g8h9i0j_with_a_very_long_identifier");if (user) { console.log(user.profile); return user;}Focus lines
NestJSuser.service.ts
TypeScript
const user = await getUser("acct_1a2b3c4d5e6f7g8h9i0j_with_a_very_long_identifier");if (user) { console.log(user.profile); return user;}Languages
package.json
JSON
{ "name": "@coloxo/ui", "version": "1.0.0", "private": false}Bash
pnpm add @coloxo/uinpx coloxo add code-blockbutton.module.css
CSS
.button { color: var(--cx-brand-600); border-radius: 8px;}Expandable
TypeScript
const user = await getUser("acct_1a2b3c4d5e6f7g8h9i0j_with_a_very_long_identifier");if (user) { console.log(user.profile); return user;}export default user;3. Interactive Props Configurator
Line numbers
Copy button
Filename
Highlight lines
Word wrap
Visual Render CanvasLANG: TYPESCRIPT | VARIANT: DEFAULT
example.ts
TypeScript
const user = await getUser("acct_1a2b3c4d5e6f7g8h9i0j_with_a_very_long_identifier");if (user) { console.log(user.profile); return user;}tsx
<CodeBlock code={`const user = await getUser("acct_1a2b3c4d5e6f7g8h9i0j_with_a_very_long_identifier");…`} language="typescript" filename="example.ts" showLineNumbers highlightLines={[3, 4]}/>4. Dark theme
Token-driven syntax colors follow [data-cx-theme].
user.ts
TypeScript
const user = await getUser("acct_1a2b3c4d5e6f7g8h9i0j_with_a_very_long_identifier");if (user) { console.log(user.profile); return user;}Accessibility
Copy control
Native button with aria-label and polite live region when the clipboard updates.
Selectable source
Line numbers are not selectable or copied — only the original source string is.
Focus
Header actions and expandable controls show Coloxo focus-visible rings.
Props
| Name | Type | Default | Description |
|---|---|---|---|
| code | string | — | Raw source. Exact string copied to clipboard. |
| language | CodeLanguage | plaintext | Syntax grammar id (typescript, json, bash, …). |
| languageLabel | string | — | Override display name (e.g. NestJS). |
| label | string | — | Optional header caption (stack/framework). |
| filename | string | — | Optional filename in the header. |
| variant | "default" | "minimal" | "compact" | "borderless" | "elevated" | "terminal" | default | Presentation chrome. |
| theme | "light" | "dark" | "system" | system | Forced or system theme. |
| showLineNumbers | boolean | false | Auto-number lines including blanks. |
| startLine | number | 1 | First displayed line number. |
| highlightLines | number[] | — | Subtle row highlights. |
| focusLines | number[] | — | Mute all lines except these. |
| showCopyButton | boolean | true | Header copy control. |
| wordWrap | boolean | false | Wrap long lines instead of scrolling. |
| maxHeight | number | string | — | Scrollable viewport height. |
| maxLines | number | — | Visible lines before collapse. |
| expandable | boolean | — | Show more / Show less when maxLines is set. |