# Streaming Text

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

```tsx
'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

```sh
npm install @brand-studio/ui
```

React 18 or 19 is a peer dependency. Import the stylesheet once and wrap the app in a brand theme:

```tsx
import '@brand-studio/ui/styles.css';
import { BrandTheme, StreamingText } from '@brand-studio/ui';
import brand from './brand.json';

<BrandTheme palette={brand.tokens} mode="system">
  {/* your app */}
</BrandTheme>
```

## Usage

```tsx
import { StreamingText } from '@brand-studio/ui';
```

```tsx
<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

| Prop | Type | Default |
|---|---|---|
| `text` | `string` | – |
| `wordsPerSecond?` | `number` | `14` |
| `as?` | `React.ElementType` | – |
| `className?` | `string` | `''` |
| `onDone?` | `(() => void)` | – |

Source: https://brandstudio.js.org/docs/components/streaming-text/
