Message
One turn in a conversation: a bubble or plain text in six variants, with an avatar, header, footer, timestamp, reactions, hover actions and a caret while the reply streams.
Installation
npx shadcn@latest add "@aiellie/message"shadcn needs the @aiellie registry in components.json first. npx aiellie add message adds it on its first run, then installs the same way.
Message lays out one turn of a conversation: an optional avatar, then a column of parts with a header above them and a footer below. Parts that follow each other stack tightly and only the last one gets the tail, so a reply sent as several bubbles reads as one message. align puts it on either side and variant sets how its parts are filled.
Getting started
Render a turn
A message needs
MessageContentand at least oneMessagePart. Put the user's on the end side and the assistant's on the start side, usually asghostso a long reply reads as plain text.components/turn.tsximport { Message, MessageContent, MessagePart, } from "@/components/aiellie/message" export function Turn({ from, text, }: { from: "user" | "assistant" text: string }) { return ( <Message align={from === "user" ? "end" : "start"} variant={from === "user" ? "secondary" : "ghost"} > <MessageContent> <MessagePart>{text}</MessagePart> </MessageContent> </Message> ) }Add the actions
MessageFootergoes after the parts.MessageActionsshows on hover where there's a pointer that can hover, and always on touch, and eachMessageActionis aTooltipIconButton.components/turn.tsximport { Copy01Icon, RepeatIcon } from "@hugeicons/core-free-icons" import { HugeiconsIcon } from "@hugeicons/react" import { MessageAction, MessageActions, MessageFooter, } from "@/components/aiellie/message" <MessageFooter> <MessageActions> <MessageAction tooltip="Copy" onClick={copy}> <HugeiconsIcon icon={Copy01Icon} /> </MessageAction> <MessageAction tooltip="Retry" onClick={retry}> <HugeiconsIcon icon={RepeatIcon} /> </MessageAction> </MessageActions> </MessageFooter>With an avatar, the avatar rises to sit beside the last part rather than the footer.
Anatomy
<div data-slot="message-group"> {/* optional: a run of messages */}
<div data-slot="message" data-align="start" data-variant="ghost" data-streaming>
<div data-slot="message-avatar" />
<div data-slot="message-content">
<div data-slot="message-header" />
<div data-slot="message-part">
<div data-slot="message-reactions" />
<span data-slot="message-caret" /> {/* shown on the last part while streaming */}
</div>
<div data-slot="message-footer">
<time data-slot="message-time" />
<div data-slot="message-actions">
<button /> {/* MessageAction */}
</div>
</div>
</div>
</div>
</div>Every part reads align and variant from its message, so nothing below Message takes either. streaming sets data-streaming and aria-busy, and shows a caret after the last part, unless that part holds a StreamText, which draws its own.
Examples
Variants
primary and secondary fill the part, tinted washes it with the primary color, outline draws a border, ghost drops the bubble for plain text the width of the thread, and destructive is for a reply that failed.
A part that does something
MessagePart takes render, so a part can be a button or a link. It gets a hover fill and a focus border to match its variant.
Reactions
MessageReactions sits on the edge of the part it's in. side picks the top or bottom edge and align the corner; give the part a bottom margin so the next row clears it.
<MessagePart className="mb-2">
Ship it on Friday?
<MessageReactions side="bottom" align="end">👍 2</MessageReactions>
</MessagePart>API reference
Message
| Prop | Type | Default | Description |
|---|---|---|---|
align | "start" | "end" | "start" | Which side the message sits on. |
variant | "primary" | "secondary" | "tinted" | "outline" | "ghost" | "destructive" | "secondary" | How its parts are filled. |
streaming | boolean | false | Shows a caret after the last part while the reply is still being written. |
className | string | Merged onto the root. |
All other div props are forwarded.
MessagePart
| Prop | Type | Default | Description |
|---|---|---|---|
render | ReactElement | function | Swaps the div for another element, like a button or a. | |
className | string | Merged onto the part. |
It grows to 80% of the thread, or the whole width as ghost, and keeps the text's own line breaks.
MessageReactions
| Prop | Type | Default | Description |
|---|---|---|---|
side | "top" | "bottom" | "bottom" | Which edge of the part it sits on. |
align | "start" | "end" | "end" | Which corner of that edge. |
MessageActions
| Prop | Type | Default | Description |
|---|---|---|---|
reveal | "hover" | "always" | "hover" | Whether the actions wait for the pointer. On touch they always show. |
MessageAction
Takes the props of TooltipIconButton, tooltip among them.
| Prop | Type | Default | Description |
|---|---|---|---|
tooltip | ReactNode | required | The tooltip, which is also its accessible name. |
Other parts
| Part | Element | Description |
|---|---|---|
MessageGroup | div | A column of messages. |
MessageAvatar | div | A 28px circle beside the parts; icons inside it are 16px. |
MessageContent | div | The column of header, parts and footer. |
MessageHeader | div | A caption above the parts, like a name. |
MessageFooter | div | A row below the parts, for the time and actions. |
MessageTime | time | The time it was sent, in tabular figures. |
Each takes its element's props and merges className.