Lab // Index

Total: 07

Component // Text

01 of 07

Comet 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

Interactive

Streaming 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.

Speed
70/s

Install // Steps

Total: 01

Step 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
Comet Text props
PropTypeDefaultDescription
textstring-The text to stream; append to it for a live stream
speednumber70Characters per second
trailnumber[]9 stepsBar widths, leading edge first, each 0 to 1
trailColorstringtext colour, 55%Colour of the trail
loopbooleanfalseStart over after finishing
loopDelaynumber1800Rest before looping, in ms
autoPlaybooleantrueSet false to hold the text hidden
onDone() => void-Called when the last character lands