Code Block Dark Example

PreviousNext

Example implementation of code block-dark.

Docs
ai-elementsblock

Preview

Loading preview…
registry/default/examples/code-block-dark.tsx
"use client";

import { CodeBlock, CodeBlockCopyButton } from "@/components/ai-elements/code-block";

const code = `function MyComponent(props) {
  return (
    <div>
      <h1>Hello, {props.name}!</h1>
      <p>This is an example React component.</p>
    </div>
  );
}`;

const Example = () => (
  <div className="dark">
    <CodeBlock code={code} language="jsx">
      <CodeBlockCopyButton
        onCopy={() => console.log("Copied code to clipboard")}
        onError={() => console.error("Failed to copy code to clipboard")}
      />
    </CodeBlock>
  </div>
);

export default Example;

Installation

npx shadcn@latest add @ai-elements/example-code-block-dark

Usage

import { ExampleCodeBlockDark } from "@/components/example-code-block-dark"
<ExampleCodeBlockDark />