Skip to content

Chat thread

A chat thread with grouped messages, reactions, read receipts, typing, and a composer with attachments.

DataNew
npx shadcn@latest add @silicon-ui/chat-thread

Installation

With the shadcn CLI

npx shadcn@latest add @silicon-ui/chat-thread

Manually

  1. Install the dependencies

    npm install lucide-react motion
  2. Copy these files into your project

    • components/silicon-ui/chat-thread/chat-thread.tsx
    • components/silicon-ui/chat-thread/chat-thread.module.css
  3. Add the foundation, once per app, for the design and motion tokens

    npx shadcn@latest add @silicon-ui/silicon-foundation

Usage

usage.tsx
import { ChatThread } from "@/components/silicon-ui/chat-thread/chat-thread";

API reference

ChatThread

PropTypeDefault
participants*ChatParticipant[]โ€”
currentUserId*stringโ€”
messages

Controlled messages, oldest first. Leave it out to let the thread keep its own list.

ChatMessage[]โ€”
defaultMessagesChatMessage[]โ€”
typing

Participant ids currently typing.

string[][]
readBy

The last message each participant has read, by participant id. Their avatar sits under that message and glides as it moves.

Record<string, string>โ€”
onSend

Called with the composer's text and files. Uncontrolled threads also append the message themselves.

(draft: ChatDraft) => void | Promise<void>โ€”
onReact(messageId: string, emoji: string) => voidโ€”
onRetry(messageId: string) => voidโ€”
reactions

Emoji offered by the reaction picker.

string[]DEFAULT_REACTIONS
placeholderstring"Message"
composer

Show the composer. Defaults to true.

booleantrue
allowAttachmentsbooleantrue
accept

File types the attach button offers, as for `<input accept>`.

stringโ€”
groupWindow

Messages from one person closer together than this, in ms, share a group. Defaults to five minutes.

number5 * 60_000
localestring"en-US"
label

Accessible name of the message log.

string"Conversation"
labels

Words for localization. Leave out any key to keep its English default.

ChatThreadLabelsโ€”
classNamestringโ€”

Also accepts the props of HTMLAttributes.

ChatComposer

PropTypeDefault
onSend*(draft: ChatDraft) => voidโ€”
placeholderstring"Message"
allowAttachmentsbooleantrue
acceptstringโ€”
disabledbooleanโ€”
labels

Words for localization. Leave out any key to keep its English default.

ChatComposerLabelsโ€”
classNamestringโ€”

Also accepts the props of HTMLAttributes.

Dependencies

npm
lucide-reactmotion
Registry
silicon-motion-tokens