Stream Text
AI-style streaming text reveal where chunks arrive with a short blur trail and a blinking caret cursor.
Customize
Installation
npx shadcn@latest add @kinetic/stream-textUsage
Pass a string to text to simulate a chunked stream on mount, or switch trigger to "inView" or "manual".
import { StreamText } from "@/components/kinetic/ui/stream-text";
export function AssistantReply() {
return (
<StreamText
text="Streaming responses arrive in short word chunks with a gentle blur settle."
className="text-base text-foreground"
/>
);
}External streaming
Drive the reveal from a live stream by passing chunks as tokens arrive, or by growing text over time with streaming={true}. Set streaming={false} when the stream closes to hide the caret and fire onComplete.
import { StreamText } from "@/components/kinetic/ui/stream-text";
interface LiveAnswerProps {
readonly text: string;
readonly streaming: boolean;
}
export function LiveAnswer({ text, streaming }: LiveAnswerProps) {
return <StreamText text={text} streaming={streaming} showCursor />;
}Imperative control
Attach a ref typed as StreamTextHandle to restart or clear the stream programmatically. Calling play() restarts from the first chunk, and reverse() clears the revealed chunks.
import { useRef } from "react";
import { StreamText, type StreamTextHandle } from "@/components/kinetic/ui/stream-text";
export function ControlledStream() {
const streamRef = useRef<StreamTextHandle>(null);
return (
<div className="space-y-3">
<StreamText
ref={streamRef}
trigger="manual"
text="Call play to stream from the start, or reverse to clear."
/>
<div className="flex gap-2">
<button type="button" onClick={() => streamRef.current?.play()}>
Play
</button>
<button type="button" onClick={() => streamRef.current?.reverse()}>
Clear
</button>
</div>
</div>
);
}Motion preferences
Use chunkDelayMs, durationMs, blurPx (clamped to 8 px), and speed to tune pacing. Timing scales with data-tempo. Under reduced motion, the full text renders immediately without blur or timers, and the caret stops blinking.
API Reference
StreamText
Streaming text renderer supporting internal chunk simulation or controlled external streams.
| Prop | Type | Default | Description |
|---|---|---|---|
text | string | - | Full text to stream or growing controlled string. |
streaming | boolean | - | Enables external controlled streaming mode. |
chunkDelayMs | number | 75 | Base delay between chunks in simulated mode. |
blurPx | number | 8 | Blur trail radius for incoming chunks (max 8px). |
showCursor | boolean | true | Shows a blinking caret while streaming. |