Streaming TextProv1.0.0
A reply arriving word by word: each new word settles in from a faint blur and a calm caret breathes at the end. Feed it your growing text, an async stream of chunks, or a whole string to reveal; screen readers hear phrases, and reduced motion shows the text at once.
pnpm dlx shadcn@latest add @beautiful-ui-pro/lumen-streaming-textNeeds your registry key. Your components.json style picks the Base UI or Radix build: radix-*, new-york and default get Radix, base-* gets Base UI.
Styles didn't apply?
The CLI adds the styles to the CSS file named in components.json (tailwind.css). Check that it points at your global stylesheet, that the project uses Tailwind CSS v4, and that the file is imported in your root layout. Installed by hand: paste styles.css into that file.
Usage
Import it and pass your content. The props that matter most are listed next.
"use client";
import * as React from "react";
import { StreamingText } from "@/components/ui/lumen/controls/streaming-text";
// The text grows as your stream arrives (useChat, a reducer, a fetch reader).
export function Answer({ text, streaming }: { text: string; streaming: boolean }) {
return <StreamingText text={text} streaming={streaming} className="text-sm leading-6" />;
}
// Or hand it the stream itself: an async iterable of chunks.
export async function* chunks(res: Response) {
const reader = res.body!.pipeThrough(new TextDecoderStream()).getReader();
try {
for (;;) {
const { value, done } = await reader.read();
if (done) return;
yield value;
}
} finally {
// Stopping early (unmount, a new question) releases the response.
void reader.cancel().catch(() => {});
}
}
export function StreamedAnswer({ res }: { res: Response }) {
// A response body can be read once: make the iterable once per response, not on every render.
const source = React.useMemo(() => chunks(res), [res]);
return (
<StreamingText
source={source}
onDone={(t) => console.log("complete", t.length)}
onStreamError={(error, partial) => console.error("stream failed after", partial.length, "characters", error)}
/>
);
}Props
text / streaming–string / booleanThe text so far as your stream grows (useChat, a reducer), and whether more is coming.
source–string | AsyncIterable<string>Instead of text: an async iterable of chunks (read once, safe under Strict Mode), or a whole string revealed at speed.
speed32numberWords per second when source is a string.
carettruebooleanThe breathing caret while streaming.
announce / announceMstrue / 1200boolean / numberRead phrases to screen readers at most this often. Turn off inside a live log (Conversation already announces).
onDone–(text: string) => voidCalled once when the text completes.
Show all 7 propsShow fewer
onStreamError–(error, text) => voidThe source failed part-way: what arrived stays, onDone isn't called.
Source
components/ui/lumen/controls/streaming-text.tsx
This component is included with Pro.
Try the live preview above. Get Pro to install the source.