Streaming Text

Text that arrives word by word, as a model writes it.

Try the Ethiopia Guji. It is a washed light roast with peach and jasmine notes, close to the Kenyan coffee you reordered twice. Brew it at 93 °C and give the bloom a full 30 seconds.

'use client';

import { useState } from 'react';
import { Button, StreamingText } from '@brand-studio/ui';

const answer = 'Try the Ethiopia Guji. It is a washed light roast with peach and jasmine notes, close to the Kenyan coffee you reordered twice. Brew it at 93 °C and give the bloom a full 30 seconds.';

export default function StreamingTextDemo() {
  const [run, setRun] = useState(0);
  return (
    <div style={{ display: 'grid', gap: 20, maxWidth: 520 }}>
      <StreamingText key={run} text={answer} />
      <div><Button tone="secondary" onClick={() => setRun(run + 1)}>Replay</Button></div>
    </div>
  );
}

Installation

pnpm add @brand-studio/ui

Usage

import { StreamingText } from '@brand-studio/ui';
<StreamingText text={answer} />

Accessibility

  • The whole text is in the HTML from the first byte; CSS reveals it word by word.
  • Screen readers hear the text once, not word by word.
  • Change the key to replay. Under reduced motion the text appears at once.

API Reference

PropTypeDefault
textstring
wordsPerSecond?number14
as?React.ElementType
className?string''
onDone?(() => void)

Still, Deskhand and Hollis are fictional brands. The coffee photographs are original generated artwork. @brand-studio/ui is MIT licensed.