Examples

Streaming conversation

Send a message: the reply streams word by word and is announced once, when complete. Scroll up while it streams and the list stays put.

Preview
You
What is a live region?
Assistant
A live region announces changes without moving focus. In a chat, announce each reply once it is complete, so screen-reader users are not interrupted by every streamed word.
0 / 1000
Example.tsx
import { useEffect, useRef, useState } from 'react';
import { Message, MessageList, PromptInput, type MessageStatus } from '@reactloom/chat';
import { Avatar, IconButton } from '@reactloom/ui';
import { CopyIcon } from '@reactloom/icons';

interface Turn {
  id: number;
  sender: 'user' | 'assistant';
  text: string;
  status: MessageStatus;
}

const answer =
  'A live region announces changes without moving focus. In a chat, announce each reply once it is complete, so screen-reader users are not interrupted by every streamed word.';

export default function Example() {
  const [turns, setTurns] = useState<Turn[]>([
    { id: 1, sender: 'user', text: 'What is a live region?', status: 'complete' },
    { id: 2, sender: 'assistant', text: answer, status: 'complete' },
  ]);
  const timer = useRef<ReturnType<typeof setInterval>>(undefined);
  const streaming = turns.some((t) => t.status === 'streaming');
  useEffect(() => () => clearInterval(timer.current), []);

  const stop = () => {
    clearInterval(timer.current);
    setTurns((all) => all.map((t) => (t.status === 'streaming' ? { ...t, status: 'complete' } : t)));
  };

  // Stand-in for a model: streams the same answer word by word.
  const send = (text: string) => {
    const id = Date.now();
    setTurns((all) => [...all, { id, sender: 'user', text, status: 'complete' }, { id: id + 1, sender: 'assistant', text: '', status: 'streaming' }]);
    const words = answer.split(' ');
    let i = 0;
    clearInterval(timer.current);
    timer.current = setInterval(() => {
      i += 1;
      setTurns((all) => all.map((t) => (t.id === id + 1 ? { ...t, text: words.slice(0, i).join(' ') } : t)));
      if (i >= words.length) stop();
    }, 90);
  };

  return (
    <div style={{ display: 'flex', flexDirection: 'column', gap: 12, width: '100%', maxWidth: 640, height: 460 }}>
      <MessageList style={{ flex: 1, border: '1px solid var(--pl-color-border-default)', borderRadius: 8 }}>
        {turns.map((t) => (
          <Message
            key={t.id}
            sender={t.sender}
            status={t.status}
            avatar={t.sender === 'assistant' ? <Avatar name="Loom" alt="" size="sm" /> : undefined}
            actions={
              t.sender === 'assistant' ? (
                <IconButton icon={<CopyIcon />} label="Copy reply" size="sm" variant="ghost" onClick={() => void navigator.clipboard?.writeText(t.text)} />
              ) : undefined
            }
          >
            {t.text}
          </Message>
        ))}
      </MessageList>
      <PromptInput onSubmit={send} streaming={streaming} onStop={stop} maxLength={1000} />
    </div>
  );
}

Sources, tool calls and errors

ToolCall is collapsed by default; CitationRef markers link to the numbered Citations list.

Preview
You
Will I need an umbrella in Oslo today?
Loom

Probably: there is a 70% chance of rain this afternoon1.

Sources

  1. MET Norway forecastmet.noRain likely from 14:00, 12°C.
Loom
Example.tsx
import { CitationRef, Citations, Message, MessageList, ToolCall } from '@reactloom/chat';

export default function Example() {
  return (
    <MessageList style={{ width: '100%', maxWidth: 640 }} messages={{ label: 'Weather conversation' }}>
      <Message sender="user">Will I need an umbrella in Oslo today?</Message>
      <Message author="Loom">
        <ToolCall name="get_forecast" input={{ city: 'Oslo', hours: 12 }} output={{ rain_probability: 0.7, temperature_c: 12 }} />
        <p>
          Probably: there is a 70% chance of rain this afternoon
          <CitationRef index={1} href="#chat-source-met" title="MET Norway forecast" />.
        </p>
        <Citations idPrefix="chat-source-" sources={[{ id: 'met', title: 'MET Norway forecast', href: 'https://www.met.no/en', snippet: 'Rain likely from 14:00, 12°C.' }]} />
      </Message>
      <Message author="Loom" status="error" error="The forecast service did not answer." onRetry={() => {}} />
    </MessageList>
  );
}

API reference

MessageList props
PropTypeDefault
children
Message elements, oldest first.
ReactNode—
followOutput
Keep the newest message in view while the reader is at the bottom.
booleantrue
bottomThreshold
Pixels from the bottom that still count as “at the bottom”.
number32
messages
Transcript name and “Jump to latest”.
Partial<MessageListMessages>—
Message props
PropTypeDefault
sender
Alignment and default author name.
'user' | 'assistant' | 'system''assistant'
author · avatar · time
Header content; author is also the message’s name.
ReactNode · ReactNode · Date—
status
Streaming shows a typing indicator and marks the message busy.
'complete' | 'streaming' | 'error''complete'
error · onRetry
Error text and a Retry button.
ReactNode · () => void—
actions
Buttons under the message (copy, feedback).
ReactNode—
announce
Announce the message when it completes.
booleantrue except for user messages
PromptInput props
PropTypeDefault
onSubmitrequired
Called with the trimmed text; the input then clears.
(value: string) => void—
value · defaultValue · onValueChange
Controlled or uncontrolled text.
string—
streaming · onStop
Send becomes Stop; Enter no longer sends.
boolean · () => void—
maxLength
Shows a count and blocks sending above it.
number—
onAttach · accept · attachments
Attach button, file types and the attachments shown above the text.
(files) => void · string · ReactNode—
toolbar
Extra controls before the send button.
ReactNode—
maxRows
Rows before the text area scrolls.
number8
submitOnEnter
Enter sends; with false, Ctrl/⌘ + Enter sends.
booleantrue
Citations, CitationRef and ToolCall
PropTypeDefault
Citations sourcesrequired
Numbered sources; the host of href is shown when source is omitted.
{ id, title, href?, source?, snippet? }[]—
Citations idPrefix · linkProps
Item ids for CitationRef links; props for every link (target, rel).
string · anchor props'source-'
CitationRef index · href · title
An inline numbered link, named “Source 1: Title”.
number · string · string—
ToolCall name · status
Header of the collapsible block.
string · running | complete | error—
ToolCall input · output
Objects are shown as formatted JSON.
unknown—

Customization

Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.

MessageList

Slot class names

Add classes to inner parts with classNames (className is shorthand for root): root, viewport, jump, announcer.

CSS variables

VariableDefault
--pl-chat-gapvar(--pl-space-4)
--pl-chat-paddingvar(--pl-space-4)

Theme tokens it reads

--pl-focus-ring-color --pl-focus-ring-width --pl-shadow-md

Message

Slot class names

Add classes to inner parts with classNames (className is shorthand for root): root, avatar, body, header, author, time, content, typing, error, actions.

CSS variables

VariableDefault
--pl-message-max-width42rem
--pl-message-user-bgvar(--pl-color-accent-subtle)
--pl-message-user-fginherit

State attributes

Target these in your CSS to style states without depending on class names.

AttributeValues
[data-sender]user · assistant · system

Theme tokens it reads

--pl-color-accent-subtle --pl-color-danger-fg --pl-color-fg-muted --pl-font-size-sm --pl-font-size-xs --pl-radius-full --pl-radius-lg

PromptInput

Slot class names

Add classes to inner parts with classNames (className is shorthand for root): root, attachments, textarea, toolbar, attach, counter, submit.

CSS variables

VariableDefault
--pl-prompt-radiusvar(--pl-radius-lg)

State attributes

Target these in your CSS to style states without depending on class names.

AttributeValues
[data-disabled]present when on
[data-over]present when on

Theme tokens it reads

--pl-color-bg-surface --pl-color-border-default --pl-color-danger-fg --pl-color-fg-muted --pl-focus-ring-color --pl-font-size-xs --pl-radius-lg

Citations

Slot class names

Add classes to inner parts with classNames (className is shorthand for root): root, label, list, item, number, title, source, snippet.

Theme tokens it reads

--pl-color-accent-fg --pl-color-bg-subtle --pl-color-border-default --pl-color-fg-muted --pl-focus-ring-color --pl-focus-ring-width --pl-font-size-sm --pl-font-size-xs --pl-radius-full --pl-radius-md

CitationRef

Theme tokens it reads

--pl-color-accent-subtle --pl-color-bg-subtle --pl-color-fg-muted --pl-focus-ring-color --pl-focus-ring-width --pl-font-size-xs --pl-radius-full

ToolCall

Slot class names

Add classes to inner parts with classNames (className is shorthand for root): root, trigger, status, content, section, code.

CSS variables

VariableDefault
--pl-motion-duration-fast120ms
--pl-tool-call-max-height16rem

State attributes

Target these in your CSS to style states without depending on class names.

AttributeValues
[data-status]running · complete · error

Theme tokens it reads

--pl-color-bg-subtle --pl-color-border-default --pl-color-danger-fg --pl-color-fg-muted --pl-color-success-fg --pl-focus-ring-color --pl-focus-ring-width --pl-font-size-sm --pl-font-size-xs --pl-radius-md --pl-radius-sm

Accessibility

  • The transcript is a named role="log" that is not live itself: streamed tokens are not read out one by one. Each completed reply is announced once through a status region; history is not read on load.
  • Each message is an article named by its author; a streaming message is aria-busy.
  • Scrolling up is never interrupted. “Jump to latest” appears instead and moves focus back to the transcript.
  • The prompt never sends text still being composed with an input method (Japanese, Chinese, Korean).
Keyboard interactions
KeyAction
EnterSend (in the prompt)
Shift + EnterNew line
TabMove to attach, Send or Stop

Usage guidelines

Do

  • Show who is speaking, and keep Stop reachable while a reply streams.
  • Render model output as text or sanitised markdown.

Don’t

  • Don’t move focus to new replies; announce them instead.