Skip to main content
Version: Next

AICodeBlock

AICodeBlock renders code in an AI assistant-style interface with syntax highlighting, streaming-aware rendering, copy actions, line numbers, and collapsible code blocks.

TypeScript
import { useState, useEffect } from "react";
interface Message {
id: string;
role: "user" | "assistant";
content: string;
}
export function useChat() {
const [messages, setMessages] = useState<Message[]>([]);
const [loading, setLoading] = useState(false);

Installation

ignix add component ai-code-block

Usage

import { AICodeBlock } from '@mindfiredigital/ignix-ui';

function ChatMessage({ codeSnippet }: { codeSnippet: string }) {
return (
<AICodeBlock
code={codeSnippet}
language="typescript"
streaming={false}
showLineNumbers={false}
collapsible
maxLines={20}
onCopy={(text) => console.log('Copied!')}
/>
);
}

Streaming Mode

When the AI is generating a code response in real time, pass streaming={true}. The component will animate the code being rendered character-by-character and shows a blinking cursor at the insertion point.

<AICodeBlock
code={partialCode} // grows as tokens arrive
language="python"
streaming={true}
streamSpeed={12} // characters per animation tick
/>

Props

PropTypeDefaultDescription
codestring""Raw source code to render
languagestring"typescript"Language for tokenization (typescript, javascript, python, html, css, bash, json, …)
streamingbooleanfalseAnimates code rendering character-by-character with blinking cursor
streamSpeednumber8Characters per 16ms tick during streaming
showLineNumbersbooleanfalseRender line number gutter
lineNumberTogglebooleantrueShow the line-number toggle button in the header
collapsiblebooleantrueFold blocks taller than maxLines with gradient mask
maxLinesnumber18Maximum visible lines before collapsing
onCopy(code: string) => voidCallback when user clicks Copy
classNamestringAdditional class names on the root element
variant'default' | 'dark' | 'glass' | 'minimal'"default"Visual theme variant preset

Supported Languages

IdentifierDisplay Label
typescript, tsxTypeScript / TSX
javascript, jsxJavaScript / JSX
pythonPython
html, xmlHTML / XML
css, scss, lessCSS / SCSS
bash, sh, shell, zshBash / Shell
jsonJSON
Any unlisted keyUsed as-is in the label