AI/Code Block

CodeBlock

Syntax-highlighted code display with language detection, line numbers, filename label, and copy-to-clipboard. Designed for rendering LLM-generated code in AI chat interfaces.

import { CodeBlock } from "@animui/ui"

Preview

page.tsx
TSX
1import { Button } from "@animui/ui";
2
3export default function Page() {
4 return <Button variant="default">Click me</Button>;
5}

Props

PropTypeDefaultDescription
codestringThe code string to display.
languagestring"tsx"Language identifier for syntax highlighting (tsx, ts, js, python, bash, etc.).
showLineNumbersbooleantrueShows line numbers in a left gutter.
filenamestringFilename displayed in the top bar of the code block.
copyablebooleantrueShows a copy-to-clipboard button.
theme"dark" | "light""dark"Color scheme of the code block.
highlightLinesnumber[][]Array of line numbers to highlight.
classNamestringAdditional classes on the outer wrapper.

In AI chat contexts

When rendering markdown from an LLM response, pass CodeBlock to your markdown renderer's code component override. It automatically detects the language from the fenced code block syntax.

import { CodeBlock } from "@animui/ui";
import Markdown from "react-markdown";

<Markdown
  components={{
    code({ node, inline, className, children, ...props }) {
      const match = /language-(\w+)/.exec(className || "");
      return !inline && match ? (
        <CodeBlock
          language={match[1]}
          code={String(children).replace(/\n$/, "")}
          showLineNumbers
        />
      ) : (
        <code className={className} {...props}>{children}</code>
      );
    },
  }}
>
  {markdownContent}
</Markdown>
© 2026 Steal Shadow. MIT License.Report an issue