Communication
Message
One turn in a conversation: avatar, header, content and footer, aligned to its side. Rises in from its own side; the footer fades in after.
Examples and variants
Thread
A user turn and an agent turn.
function MessageThread() {
return (
<div className="flex w-full max-w-md flex-col gap-4">
<Message from="user">
<MessageContent>
<BubbleGroup>
<Bubble from="user">Can you make the save button calmer?</Bubble>
</BubbleGroup>
<MessageFooter>Delivered</MessageFooter>
</MessageContent>
</Message>
<Message from="agent">
<MessageAvatar>
<Avatar>
<AvatarFallback>AI</AvatarFallback>
</Avatar>
</MessageAvatar>
<MessageContent>
<MessageHeader>Assistant</MessageHeader>
<BubbleGroup>
<Bubble>Sure. I’ll use status instead of a toast.</Bubble>
<Bubble>It keeps its width, so nothing jumps.</Bubble>
</BubbleGroup>
</MessageContent>
</Message>
</div>
)
}Spec drawing
Measured from the live component at default density. Each code maps to the token that sets it; change the token and the drawing follows.
Install
With the CLI
The shadcn CLI only delivers files: it copies our code from the Isotopi registry into your project and installs the packages it uses. Add the foundation once, then the component.
npx shadcn@latest add https://isotopi.com/r/minimal.json
npx shadcn@latest add https://isotopi.com/r/message.json
npx shadcn@latest add https://isotopi.com/r/bubble.jsonBy hand
No CLI needed. Add the foundation once (see Getting started), then follow these steps. They include every component this one builds on.
Install the packages it uses.
Terminalnpm install cnCopy these 2 files to the same paths in your project. Imports use the
@/alias for your project root.components/ui/message.tsxmessage
components/ui/message.tsx"use client" import * as React from "react" import { cn } from "cn" /* Message: one turn in a conversation (person or agent). Lays out the avatar, header, content and footer, aligned to its side. New messages rise in from their own side; the footer (time, "Delivered") fades in after the content. */ const FromContext = React.createContext<"user" | "agent">("agent") function Message({ from = "agent", className, ...props }: React.ComponentProps<"div"> & { from?: "user" | "agent" }) { return ( <FromContext.Provider value={from}> <div data-slot="message" data-from={from} className={cn("message flex w-full max-w-(--message-max-width) gap-(--message-gap)", from === "user" && "ms-auto flex-row-reverse", className)} {...props} /> </FromContext.Provider> ) } function MessageAvatar({ className, ...props }: React.ComponentProps<"div">) { return <div data-slot="message-avatar" className={cn("shrink-0 pt-0.5", className)} {...props} /> } function MessageContent({ className, ...props }: React.ComponentProps<"div">) { const from = React.useContext(FromContext) return ( <div data-slot="message-content" className={cn("flex min-w-0 flex-1 flex-col gap-1", from === "user" ? "items-end" : "items-start", className)} {...props} /> ) } function MessageHeader({ className, ...props }: React.ComponentProps<"div">) { return <div data-slot="message-header" className={cn("flex items-center gap-2 text-caption text-muted-foreground", className)} {...props} /> } function MessageFooter({ className, ...props }: React.ComponentProps<"div">) { return <div data-slot="message-footer" className={cn("message-footer flex items-center gap-2 text-caption text-ink-subtle", className)} {...props} /> } export { Message, MessageAvatar, MessageContent, MessageHeader, MessageFooter }components/ui/bubble.tsxbubble
components/ui/bubble.tsx"use client" import * as React from "react" import { cn } from "cn" /* Bubble: the surface for chat text. In a BubbleGroup, consecutive bubbles from one sender melt their facing corners together, so a run reads as one shape. Reactions pop in; adding the same one again bounces it. */ function BubbleGroup({ className, ...props }: React.ComponentProps<"div">) { return <div data-slot="bubble-group" className={cn("bubble-group flex flex-col gap-0.5", className)} {...props} /> } function Bubble({ from = "agent", className, ...props }: React.ComponentProps<"div"> & { from?: "user" | "agent" }) { return ( <div data-slot="bubble" data-from={from} className={cn( "bubble w-fit max-w-(--bubble-max-width) rounded-(--bubble-corner) px-(--bubble-padding-x) py-(--bubble-padding-y) text-sm leading-relaxed break-words", from === "user" ? "ms-auto bg-(--bubble-user) text-(--bubble-user-label)" : "bg-(--bubble-agent) text-(--bubble-agent-label)", className )} {...props} /> ) } function BubbleReactions({ reactions, onReact, className, }: { reactions: { emoji: string; label: string; count: number; mine?: boolean }[] onReact?: (emoji: string) => void className?: string }) { const [bounce, setBounce] = React.useState<string | null>(null) return ( <div data-slot="bubble-reactions" className={cn("flex flex-wrap gap-1", className)}> {reactions.map((reaction) => ( <button key={`${reaction.emoji}-${bounce === reaction.emoji ? "b" : "a"}`} type="button" aria-pressed={reaction.mine} aria-label={`${reaction.label}, ${reaction.count}`} onClick={() => { setBounce(reaction.emoji) onReact?.(reaction.emoji) }} className={cn( "bubble-reaction liquid-press inline-flex h-6 items-center gap-1 rounded-(--shape-full) px-2 text-xs tabular-nums outline-none focus-visible:shadow-(--focus-ring)", reaction.mine ? "bg-(--color-bg-selected)" : "bg-(--surface-container)" )} > <span aria-hidden>{reaction.emoji}</span> {reaction.count} </button> ))} </div> ) } export { BubbleGroup, Bubble, BubbleReactions }
Imports
What the examples on this page import:
import { Attachment } from "@/components/ui/attachment"
import { Avatar, AvatarFallback } from "@/components/ui/avatar"
import { Bubble, BubbleGroup, BubbleReactions } from "@/components/ui/bubble"
import { Button } from "@/components/ui/button"
import { CodeBlock } from "@/components/ui/code-block"
import { Marker } from "@/components/ui/marker"
import { Message, MessageAvatar, MessageContent, MessageFooter, MessageHeader } from "@/components/ui/message"
import { MessageScroller } from "@/components/ui/message-scroller"
import { PromptInput } from "@/components/ui/prompt-input"
import { Questionnaire } from "@/components/ui/questionnaire"
import { StreamingText } from "@/components/ui/streaming-text"
import { Trace, TraceItem } from "@/components/ui/trace"
import { VoiceInput } from "@/components/ui/voice-input"
import { tokenMs } from "@/lib/motion/token-ms"Anatomy
- 1Avatar · Agent avatars can show the speaking ring.
- 2Header · Name, time.
- 3Content · Bubbles, markers, traces, code.
- 4Footer · Delivered, time.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
from | "user" | "agent" | "agent" | Side and alignment. |
Tokens
Every visual spec is a component token in styles/tokens/components.css, pointing at a semantic token. Change a token to restyle the component; themes change the semantic layer.
| Token | Points to | Light | Dark |
|---|---|---|---|
--message-gap | var(--space-3) | 12px | same |
--message-max-width | var(--layout-thread) | 720px | same |
Motion
| Trigger | What happens | Tokens |
|---|---|---|
| Arrive | Rises in from its side; footer fades in after the content. | --duration-settle, --duration-slow |
Calm keeps the motion without overshoot. Still (and reduced motion) keeps a designed frame with no movement.
Accessibility
- Place messages inside Message scroller (role=log).
Usage
Do
- One Message per turn.
Don’t
- Don't use for system notes (use Marker).
Code
"use client"
import * as React from "react"
import { cn } from "cn"
/*
Message: one turn in a conversation (person or agent). Lays out the avatar,
header, content and footer, aligned to its side. New messages rise in from
their own side; the footer (time, "Delivered") fades in after the content.
*/
const FromContext = React.createContext<"user" | "agent">("agent")
function Message({ from = "agent", className, ...props }: React.ComponentProps<"div"> & { from?: "user" | "agent" }) {
return (
<FromContext.Provider value={from}>
<div
data-slot="message"
data-from={from}
className={cn("message flex w-full max-w-(--message-max-width) gap-(--message-gap)", from === "user" && "ms-auto flex-row-reverse", className)}
{...props}
/>
</FromContext.Provider>
)
}
function MessageAvatar({ className, ...props }: React.ComponentProps<"div">) {
return <div data-slot="message-avatar" className={cn("shrink-0 pt-0.5", className)} {...props} />
}
function MessageContent({ className, ...props }: React.ComponentProps<"div">) {
const from = React.useContext(FromContext)
return (
<div
data-slot="message-content"
className={cn("flex min-w-0 flex-1 flex-col gap-1", from === "user" ? "items-end" : "items-start", className)}
{...props}
/>
)
}
function MessageHeader({ className, ...props }: React.ComponentProps<"div">) {
return <div data-slot="message-header" className={cn("flex items-center gap-2 text-caption text-muted-foreground", className)} {...props} />
}
function MessageFooter({ className, ...props }: React.ComponentProps<"div">) {
return <div data-slot="message-footer" className={cn("message-footer flex items-center gap-2 text-caption text-ink-subtle", className)} {...props} />
}
export { Message, MessageAvatar, MessageContent, MessageHeader, MessageFooter }