AI Streaming Text

AiStreamingText renders an AI-style typewriter animation that reveals a text string one character or one word at a time, with an optional blinking cursor. It calls an optional onComplete callback when the full text has been shown.

AI Streaming Text
LIVE · running in a sandboxed iframe
Installed with plain shadcn add · no workarounds · theme neutral (none shipped)
See how it was built

Installation

pnpm dlx shadcn@latest add @elements/streaming-text

Requires @elements in the registries of your components.json (shadcn adds official directory namespaces automatically).

Usage

usage.tsx
import { AiStreamingText } from "@/components/elements/ai-streaming-text"export function Example() {  return <AiStreamingText text="Hello, I am your assistant." />}
  • Showing an AI or chatbot response that appears gradually, as if being generated live
  • Adding a typewriter effect to a hero headline, tagline, or demo text
  • Revealing a long paragraph word by word for emphasis or storytelling
  • Displaying a streamed answer where you want a visible completion signal via onComplete

Examples

Word-by-word reveal

Reveals the text one word at a time with a faster interval.

word-by-word-reveal.tsx
import { AiStreamingText } from "@/components/elements/ai-streaming-text"export function WordModeExample() {  return (    <AiStreamingText      text="Streaming text arrives one word at a time."      mode="word"      speed={80}    />  )}

Completion callback

Uses onComplete to react when the animation finishes, such as enabling a button.

completion-callback.tsx
"use client"import * as React from "react"import { AiStreamingText } from "@/components/elements/ai-streaming-text"export function CompletionExample() {  const [done, setDone] = React.useState(false)  return (    <div className="space-y-2">      <AiStreamingText        text="Your report is ready. You can download it now."        onComplete={() => setDone(true)}      />      <button disabled={!done} className="text-sm underline disabled:opacity-50">        Download      </button>    </div>  )}

Chat bubble without cursor

Hides the cursor and applies a custom class to style the streamed message inside a bubble.

chat-bubble-without-cursor.tsx
import { AiStreamingText } from "@/components/elements/ai-streaming-text"export function ChatBubbleExample() {  return (    <div className="max-w-md rounded-2xl bg-muted px-4 py-3 text-sm">      <AiStreamingText        text="Sure! Here is a short summary of the article you shared."        showCursor={false}        className="leading-relaxed"      />    </div>  )}

API reference

PropTypeDefaultDescription
textstring—The full text to reveal. Changing it restarts the animation from an empty string.
speednumber30Delay in milliseconds between revealing each token (character or word). Lower values are faster.
mode"character" | "word""character"Whether text is revealed one character at a time or one word at a time. In word mode, whitespace is kept as separate tokens.
showCursorbooleantrueShows a pulsing vertical cursor after the text while the animation is running. The cursor is hidden once complete.
onComplete() => void—Called once when all tokens have been revealed.
classNamestring—Additional class names merged onto the root div via cn().

Accessibility

  • The root element has role="status" and aria-live="polite", so screen readers announce updates politely without interrupting the user.
  • The root has aria-label="AI response", which gives assistive technology a label for the region. Consider providing context if multiple instances appear on one page.
  • The cursor is a decorative empty span with no text content, so it adds no noise for screen readers, but it is not hidden with aria-hidden; set showCursor={false} if the cursor is visually distracting.
  • Because text is revealed progressively, screen readers may announce partial content repeatedly. For long responses, consider rendering the full text in an sr-only element or setting showCursor to false.
  • Respect reduced motion preferences by choosing a larger speed or disabling the cursor pulse in your own wrapper, since the component does not read prefers-reduced-motion itself.

Docs written by anthropic:claude-haiku-5-5 from the registry source.

Use with Coding Agent

Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.

prompt.md
Use the "AI Streaming Text" component (elements/streaming-text) from its shadcn registry.1. Install it with: npx shadcn@latest add @elements/streaming-text2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: text, speed, mode, showCursor, onComplete, className.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { AiStreamingText } from "@/components/elements/ai-streaming-text"export function Example() {  return <AiStreamingText text="Hello, I am your assistant." />}```

Files & dependencies

  • registry/default/blocks/ai/ai-streaming-text/components/elements/ai-streaming-text.tsx

Looks similar, elsewhere