Lab // Index
Total: 07Component // Text
01 of 07Comet TextNew
Streaming text with a comet at its edge: a full block leads, and a trail of thinner and thinner bars resolves into the letters behind it
Demo // Live
InteractiveStreaming is a small lie told well. The whole answer does not exist yet, so the interface shows the part that does, and lets the edge of it glow like a comet until the words have landed.
Install // Steps
Total: 01Step 01
Copy and paste the following code into your project.
One file, React only, no dependencies. It runs on requestAnimationFrame and re-renders once per character.
import { CometText } from "@/components/craft/comet-text";
// Play a known text in
<p>
<CometText text="The whole answer does not exist yet." speed={70} />
</p>
// Or feed it a reply as it arrives: appended text carries on, it does not restart
function Reply({ stream }: { stream: string }) {
return (
<p>
<CometText text={stream} speed={120} />
</p>
);
}
// A shorter, coloured trail
<CometText text="Thinking it over" trail={[1, 0.7, 0.4, 0.15]} trailColor="#0358f7" loop />
Spec // Features
Total: 06- 01
Made for real streams
Keep appending to the text and it carries on from where it is, instead of starting over
- 02
No reflow
The whole text is laid out from the first frame, so lines wrap where they will end up and nothing below it moves
- 03
Any font
Each bar takes the width of the character it stands in for, so it works in proportional type as well as mono
- 04
The trail is yours
Pass any list of widths: a long soft tail, a short hard one, or a single block cursor
- 05
Readable by screen readers
The text is real text from the start, not revealed character by character to assistive tech
- 06
Respects reduced motion
The text simply appears
Spec // Props
Total: 08| Prop | Type | Default | Description |
|---|---|---|---|
| text | string | - | The text to stream; append to it for a live stream |
| speed | number | 70 | Characters per second |
| trail | number[] | 9 steps | Bar widths, leading edge first, each 0 to 1 |
| trailColor | string | text colour, 55% | Colour of the trail |
| loop | boolean | false | Start over after finishing |
| loopDelay | number | 1800 | Rest before looping, in ms |
| autoPlay | boolean | true | Set false to hold the text hidden |
| onDone | () => void | - | Called when the last character lands |