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.
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.jsonPrefer 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
| Prop | Type | Default | Description |
|---|---|---|---|
| heading | string | "Assistant" | Small heading shown in the panel header. |
| prompt | string | "Write a function that greets a user by name." | User's chat message shown above the code panel. |
| fileName | string | "greet.js" | File name shown in the code panel's tab bar. |
| language | string | "JavaScript" | Language label shown as a badge in the tab bar. |
| className | string | none | Extra 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.
More Chat Blocks
View all →rich-prompt-input-with-suggestions
Rich Prompt Input with Smart Suggestions
An AI prompt composer with attachment icons, a model selector, and a grid of clickable prompt suggestion cards.
ai-streaming-response-typewriter
AI Streaming Response with Live Typing
A single AI chat exchange with a skeleton loading state, a word-by-word typewriter reveal, and a stop-generating control.
ai-response-with-cited-sources
AI Response with Cited Sources
A Perplexity-style answer with inline numbered citation markers and an expandable source list below it.
prompt-starter-grid
AI Prompt Starter Grid
A tabbed grid of prompt template cards, filterable by category, each with an icon, title, and description.
ai-agent-profile-card
AI Agent Profile Card
A showcase card for an AI agent with avatar, capability badges, a sample chat preview, stats, and action buttons.
floating-chat-widget
Floating Chat Widget with Expandable Window
A corner chat bubble with a pulsing notification dot that expands into a mini chat window.