Streaming Text
Minimal AI text streaming with a magic-ink effect: each word fades in wearing a blue gradient, then settles into the theme's foreground once it lands.
Streaming Text
Minimal AI text streaming with a magic-ink effect: each word fades in wearing a blue gradient, then settles into the theme's foreground once it lands.
Hit the re-trigger button to replay the stream from the first word — watch the blue trail follow the stream head before each word settles into the theme foreground, and the pulsing cursor pop away when the stream completes.
Installation
Install the component with the Craft-UI Blocks CLI — it drops streaming-text.tsx into your project and wires up its runtime dependencies:
npx mvpblocks add streaming-textpnpm dlx mvpblocks add streaming-textyarn dlx mvpblocks add streaming-textbunx mvpblocks add streaming-textFile Structure
The CLI saves the component to your project's components/ui folder:
Import it from @/components/ui/streaming-text.
Usage
Pass the full text and let the component handle the reveal — typography inherits from whatever wraps it, so it drops into any message or result renderer:
import { StreamingText } from "@/components/ui/streaming-text";
export function AssistantReply() {
return (
<StreamingText
className="text-sm leading-relaxed"
text="Design is not just what it looks like — design is how it works."
/>
);
}Theming
The magic-ink look ships as exact light and dark stops. Fresh words wear a blue ribbon — sky-500 → blue-600 → indigo-500 in light mode, brightening to sky-400 → blue-400 → indigo-300 in dark — clipped to the text with bg-clip-text. Each word then crossfades into your theme's text-foreground (black in light, white in dark), so the gradient always marks what just arrived, never the settled text. Consecutive words sample a 3x-wide version of the gradient at ping-ponging offsets, so the trail reads as one continuous ribbon instead of every word restarting at sky. The cursor is a sky-400 → indigo-500 dot (brighter in dark) with a soft sky glow that breathes with its pulse. Because every animated value is opacity, words crossfade in place with zero repaint cost — the stream stays lag-free.
Animations
- Word cadence: every token is scheduled against the stream's start time rather than chaining timeouts, so render latency can never accumulate into a drifting, stuttering rhythm. Each word fades in over a deliberately long half-second — four to five words are always mid-fade at staggered opacities, turning the reveal into one continuous gradient wave instead of discrete pops.
- Settle: after
settleDelayper word, the gradient copy fades out while an identical foreground copy fades in — a true crossfade between two stacked copies, so the color handoff stays theme-correct in both modes. - Cursor: a small gradient dot pulses on a 1.2s breathe while words are landing; its glow rides the same keyframes for zero per-frame cost, and it pops out (
opacity 0, scale 0.95) in anAnimatePresenceexit the moment the stream completes. - Breaks: newlines are preserved as paragraph breaks, each costing one streaming tick, so paragraphs read as a natural beat.
- Restart: changing
textrestarts the stream from the first word — the reset happens during render so no intermediate frame shows old text sliced by the old count. - Efficiency: already-settled words are memoized, so every streaming tick re-renders only the newly revealed word.
- Reduced motion: the full text renders immediately in the foreground color — no gradient, no cursor — and
onCompletefires immediately so chained UI never hangs.
Props
Prop
Type
Registry Bundle
Install the exact registry entry shown on the right when you want the component file and its declared runtime dependencies together. Dependencies: motion.
Contact
If you find any bug or issue, feel free to raise an issue.
Last updated on