Conversation

Chat Thread

The conversation itself — user and assistant turns, grouping, date dividers, unread marker and a jump-to-latest pill.

3 variantsMIT

Preview

Installation

Copies the component into components/ui and installs its dependencies and theme tokens.

pnpm dlx shadcn@latest add https://uilab.tmih06.com/r/chat-thread.json

Usage

Pass your own data and wire the callbacks to your agent runtime.

import { ChatThread } from "@/components/ui/chat-thread";
import { StreamingMessage } from "@/components/ui/streaming-message";

export function Conversation({ messages, lastReadId }: Props) {
  return (
    <ChatThread
      agentName="Claude"
      data={{
        unreadFrom: lastReadId,
        messages: messages.map((m) => ({
          id: m.id,
          role: m.role,
          at: m.createdAt,
          streaming: m.status === "streaming",
          // Any node: plain text, a StreamingMessage, tool calls, charts…
          content: m.role === "assistant" ? <StreamingMessage data={m} /> : m.text,
        })),
      }}
    />
  );
}

// Pass null while the first page is in flight; keep stale data and set
// loading when refetching. Empty message arrays still render as an empty thread.
export function ConversationState({ query }: { query: MessagesQuery }) {
  return (
    <ChatThread
      agentName="Claude"
      data={query.data ? toThreadData(query.data) : null}
      loading={query.isRefetching}
      skeleton={{ count: 5 }}
    />
  );
}

Props

PropTypeDefaultDescription
data*{ messages: ThreadMessage[]; unreadFrom?: string } | null—Turns in order. Consecutive turns from one side within five minutes share a header; `unreadFrom` puts an Unread divider before that message. Pass null while they load; an empty messages array is a valid empty thread.
loadingbooleanfalseForce the layout-preserving skeleton while refetching, even when stale messages are available.
skeleton{ count?: number }—Shape hints for the loading state; count is the number of message placeholders.
density"default" | "dense""default"Dense drops avatars and tightens spacing for side panels.
agentNamestring"Assistant"Header name for assistant turns.
userNamestring"You"Header name for user turns.
renderAvatar(message: ThreadMessage) => ReactNode—Custom avatar; defaults to a sparkle for the agent and an initial for people.
heightnumber | string420 (100% when bare)Height of the scroll area. The thread follows new content while you're at the bottom and shows Jump to latest when you scroll up.
barebooleanfalseDrop the shell and panel so the thread is just the scroll area and fills its parent — for full screens where the thread is the page.
footerReactNode—Rendered after the last message inside the scroll area, e.g. follow-up chips.
bottomInsetnumber0Pixels kept free at the bottom for a composer that floats over the thread; Jump to latest sits above it.
contentClassNamestring—Classes for the message column, e.g. `mx-auto max-w-3xl`.
localestring"en-US"BCP 47 locale for message times and day dividers.
labelsPartial<ChatThreadLabels>—Your own UI strings (loading announcement, Unread, Today, Jump to latest…), for translating the thread. Right-to-left works under `dir="rtl"`.
classNamestring—Extra classes for the shell.
type ThreadMessage = {
  id: string;
  role: "user" | "assistant";
  content: ReactNode;
  at: string;          // ISO timestamp
  author?: string;
  streaming?: boolean; // shows a caret and keeps the thread pinned while it grows
};