Chat Code Block

Fenced code surface for chat replies, pinned dark in both modes, with a language label and copy button. Lazy-loads Shiki for highlighting and waits until a streamed fence closes.

Open the preview in a new tab

The source comes with full access.

One payment of $149 opens the source right here and lets the CLI install every paid component, with lifetime updates.

Installation

pnpm dlx shadcn add @01orbital/chat-code-block
npx shadcn add @01orbital/chat-code-block
yarn shadcn add @01orbital/chat-code-block
bunx --bun shadcn add @01orbital/chat-code-block

Part of the 01orbital library. With a license, put ORBITAL_TOKEN in .env.local and the same command installs it (licensed install, pricing).

It lands at components/chat/chat-code-block.tsx, as source you own and edit.

Usage

import { ChatCodeBlock } from "@/components/chat/chat-code-block"

const CODE = `import { useChatStream } from "@/hooks/use-chat-stream"

const { turns, send, stop, streaming } = useChatStream({
  endpoint: "/api/ai/chat",
  system: "Answer in two plain sentences.",
})`

export default function ChatCodeBlockDemo() {
  return (
    <div className="grid w-full max-w-2xl place-items-center p-6">
      {/* Full width: centred alone, the figure would size to its longest
          line and spill past a phone instead of scrolling inside. */}
      <ChatCodeBlock code={CODE} lang="tsx" className="w-full" />
    </div>
  )
}

API reference

Prop

Type

Dependencies

npm: @phosphor-icons/react, cn, shiki. The CLI installs them for you.

Registry pieces it installs with it:

  • button
  • font-geist-mono
  • use-copy-to-clipboard

On this page