Staaarter

Code Generation Chat with Syntax Highlighting

A chat exchange focused on generated code: the user's prompt as a bubble, then a code panel with a file-name and language badge header and a hand-styled code sample with a few semantic color spans to suggest syntax highlighting. A copy button in the header genuinely writes the code to the clipboard.

By Staaarter Team
Chat
Docs
Live preview

Docs

Installation

A real shadcn registry command, not a copy-paste stand-in: it fetches this block plus its badge, button dependencies and any missing npm packages, and installs them straight into your project.

npx shadcn add https://staaarter.com/r/code-generation-chat-with-syntax-highlighting.json

Prefer not to use the CLI? Copy the source from the Code toggle above into src/components/blocks/chat/chat7.tsx instead.

Usage

The file also exports chat7Demo, the exact props behind the preview above. Spread it to get a working section in one line, then replace it with your own data.

import { Chat7, chat7Demo } from "@/components/blocks/chat/chat7";

export default function Page() {
  return <Chat7 {...chat7Demo} />;
}

Props

PropTypeDefaultDescription
headingstring"Assistant"Small heading shown in the panel header.
promptstring"Write a function that greets a user by name."User's chat message shown above the code panel.
fileNamestring"greet.js"File name shown in the code panel's tab bar.
languagestring"JavaScript"Language label shown as a badge in the tab bar.
classNamestringnoneExtra classes for the outer panel element.

Behavior notes

  • The code sample and its colored spans are a fixed, hardcoded illustration (a CODE_LINES token array), not derived from a real tokenizer or from any prop, since no syntax-highlighter dependency was added.
  • The copy button is fully real: it calls navigator.clipboard.writeText with the exact code text and flips a useState 'copied' flag for ~2 seconds to show a check icon.
  • fileName/language/prompt are configurable props for the surrounding chrome, but the code block content itself is intentionally static.