AI Streaming Response with Live Typing
A bounded chat panel showing one user prompt and one AI response. The response briefly shows a skeleton loading placeholder, then reveals word by word with a blinking cursor to simulate a live streaming model response. A "Stop generating" button halts the animation early, matching the stop control found in real AI chat products.
Docs
Installation
A real shadcn registry command, not a copy-paste stand-in: it fetches this block plus its button dependencies and any missing npm packages, and installs them straight into your project.
npx shadcn add https://staaarter.com/r/ai-streaming-response-typewriter.jsonPrefer not to use the CLI? Copy the source from the Code toggle above into src/components/blocks/chat/chat5.tsx instead.
Usage
The file also exports chat5Demo, 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 { Chat5, chat5Demo } from "@/components/blocks/chat/chat5"; export default function Page() { return <Chat5 {...chat5Demo} />; }
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| heading | string | "Assistant" | Small heading shown in the panel header. |
| userPrompt | string | none | The user's chat message, shown as a static bubble above the response. |
| response | string | none | Full AI response text that gets revealed word-by-word by the typewriter effect. |
| className | string | none | Extra classes for the outer panel element. |
Behavior notes
- Real client state: a skeleton loading placeholder shows for ~700ms (useState isLoading, starts true for a deterministic SSR-safe render), then a setInterval reveals the response word-by-word into a `typed` string.
- The blinking cursor after the in-progress text is a static `|` character using CSS `animate-pulse`, not a custom keyframe.
- The "Stop generating" button is fully functional: clicking it clears the interval early and freezes the response at whatever text had been revealed so far, then shows a "Generation stopped" note.
- No timestamps or durations are computed from Date.now(); the loading delay and typing speed are fixed literal millisecond intervals.
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-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.
code-generation-chat-with-syntax-highlighting
Code Generation Chat with Syntax Highlighting
A developer chat message with a file-name tab bar, a language badge, illustrative syntax coloring, and a real copy button.
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.