Skip to content

CodeBlock

CodeBlock

<CodeBlock
language="ts"
filename="App.tsx"
code={`import { Button } from '@helixui/core';
export function App() {
return <Button>Save</Button>;
}`}
/>

With your own highlighter

import { highlight as prism } from 'prism-react-renderer';
<CodeBlock language="rust" code={src} highlight={(code) => prism({ code, language: 'rust' }).html} />

Install: @helixui/core

import { CodeBlock } from '@helixui/core'

status: stable · since: 0.3.0

Tags: code, mono, snippet, copy

Anatomy

┌─ tsx ─────────────────────────── [📋] ┐
│ const x = 1; │
│ console.log(x); │
└────────────────────────────────────────┘

Layout

  • displayblock
  • widthfill
  • heightcontent
  • intrinsicSizefills width, scrolls horizontally on overflow
  • stackabletrue
  • fullBleedfalse

Visual

A surface with a small language label in the top-left, a copy button in the top-right, and monospace content (font.family.mono) on a subtle surface (surface.subtle). Tokenized highlighting for ts/js/py/json/bash; falls back to plain text otherwise.

Props

NameTypeDefaultDescription
codestringSource text. Required.
languagestringtsLanguage tag for highlighter and label.
filenamestringOptional filename — replaces the language label.
noCopybooleanfalseHide the copy button.
highlight(code, language?) => stringOverride the built-in highlighter. Returns HTML string.

Tokens used

color.bg.surface.inverse, color.text.inverse, color.border.default, radius.md, radius.sm, space.2, space.3, space.4, font.family.sans, font.family.mono, font.size.xs, font.size.sm, font.weight.medium

Accessibility

Notes

  • Copy button announces ‘Copied’ via its aria-label after a successful copy.
  • Built-in highlighter is regex-based (small) — for richer highlighting pass highlight (e.g. wrap Prism / Shiki).

Composes with

ComponentRelationNote
CodeEditoralternativeCodeBlock is read-only display; CodeEditor is editable.
CardparentOften inside a Card or doc body.
ChatMessagesibling

Prompt examples

These are the AI prompt → JSX mappings used by the helixui prompt DSL and integrations like Cursor / Claude Code.

show a tsx snippet

“render a code block with copy button”

<CodeBlock language="tsx">{`const x = 1;`}</CodeBlock>