Chat thread

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

npx shadcn@latest add @silicon-ui/chat-thread
datanew
Loading…

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. Shared files are skipped if you already have them.

    • components/silicon-ui/chat-thread/chat-thread.tsx
    • components/silicon-ui/chat-thread/chat-thread.module.css
  3. Install the foundation once per app for the design and motion tokens: npx shadcn@latest add @silicon-ui/silicon-foundation

Usage

Source codetsx
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