CodeBlock

Display code with expand/collapse functionality

CodeBlock displays code with optional syntax highlighting, line numbers, and a "Show more" button for long code blocks that exceed the max height.

Preview

example.ts
function processData(data: DataPoint[]) {
  const normalized = data.map(point => ({
    x: point.x / maxX,
    y: point.y / maxY,
...

Import

import
import { CodeBlock } from '@ash-cloud/ash-ui';

Usage

CodeDisplay.tsx
import { CodeBlock } from '@ash-cloud/ash-ui';

function CodeDisplay() {
  const code = `function hello() {
  console.log("Hello, world!");
}`;

  return (
    <CodeBlock
      language="typescript"
      maxHeight={200}
      showLineNumbers
    >
      {code}
    </CodeBlock>
  );
}

Props

PropTypeDefaultDescription
childrenstringrequiredThe code to display
languagestringundefinedLanguage for syntax highlighting
maxHeightnumber300Max height before "Show more" appears
showLineNumbersbooleanfalseDisplay line numbers
classNamestringundefinedAdditional CSS classes

Features

Expand/Collapse

Long code blocks show a "Show more" button

Scrollable

Horizontal scrolling for long lines

Line Numbers

Optional line number display

Syntax Highlighting

Language-aware code coloring