Skip to content
UI

Search docs

Search components and documentation

New
Menu

Code Block

A styled code container with a one-click copy button, dependency-free.

bash
npx logic2b@latest add code-block

Installation

npx logic2b@latest add code-block

Usage

import { CodeBlock } from "@/components/ui/code-block"

<CodeBlock language="tsx" code={`const answer = 42`} />

The copy button writes code to the clipboard and shows a checkmark for two seconds. Omit language to render a bare block with a floating copy button in the corner.

Highlighting

CodeBlock is deliberately dependency-free and does not ship a syntax highlighter. To add highlighting, render your highlighter’s output inside the <pre> — e.g. pass Shiki/Prism-generated HTML — or wrap this component. Keeping the base free of a highlighter means it stays tiny and framework-agnostic.

API

Prop Type Default
code string — (required)
language string (display label)
…props React.ComponentProps<"div">