Message
A chat turn: a plain article for the assistant, a bubble for the user. Adapted from beUI (MIT).
The item lays a turn out and ships no bubble. An assistant turn is a full-width column; a user turn sits at the end of the row, and the bubble is your own element inside it. With animateIn a turn rises and fades in as it arrives; with reduced motion it is in place at once.
User and assistant
import { Message } from "@/components/ui/message"
export default function MessageUserAndAssistant() {
return (
<div className="flex w-full max-w-md flex-col gap-4">
<Message from="user">
<p className="max-w-[85%] rounded-xl bg-muted px-3 py-2">Which tasks are still open for the March release?</p>
</Message>
<Message from="assistant">
<p>Three tasks are open. Two are in review and one has no owner yet.</p>
</Message>
<Message from="user">
<p className="max-w-[85%] rounded-xl bg-muted px-3 py-2">Assign the last one to the design team.</p>
</Message>
<Message from="assistant">
<p>Done. The export dialog task now belongs to the design team and is due on Thursday.</p>
</Message>
</div>
)
}
Animate in
"use client"
import { useState } from "react"
import { Button } from "@/components/ui/button"
import { Message } from "@/components/ui/message"
const drafts = ["Add the changelog.", "Move the review to Thursday.", "Close the tasks that shipped."]
export default function MessageAnimateIn() {
const [sent, setSent] = useState<string[]>([])
const next = drafts[sent.length]
return (
<div className="flex w-full max-w-md flex-col gap-4">
<div className="flex min-h-44 flex-col gap-2">
<Message from="assistant">
<p>What should change before the release goes out?</p>
</Message>
{sent.map((text) => (
<Message key={text} from="user" animateIn>
<p className="max-w-[85%] rounded-xl bg-muted px-3 py-2">{text}</p>
</Message>
))}
</div>
<Button variant="outline" className="self-end" onClick={() => setSent(next ? [...sent, next] : [])}>
{next ? "Send a message" : "Clear"}
</Button>
</div>
)
}
With its own name
import { Message } from "@/components/ui/message"
export default function MessageWithItsOwnName() {
return (
<div className="flex w-full max-w-md flex-col gap-4">
<Message from="user" aria-label="Your message, sent at 09:41">
<p className="max-w-[85%] rounded-xl bg-muted px-3 py-2">Is the invoice for the workshop paid?</p>
</Message>
<Message from="assistant" aria-label="Reply from the assistant, 09:41">
<p>Yes. Invoice 0142 was paid in full on Monday.</p>
</Message>
</div>
)
}
Installation
npx shadcn@latest add @khaeli/messagebunx --bun shadcn@latest add @khaeli/messageInstall @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.
Installs with
- Registry items
- npm packages
- motion ^12.23.12
Accessible name
- Each turn is an
articlenamed fromfrom:user messageorassistant message. - Pass
aria-labelto say more than the side, such as who wrote the turn or when.
Registry JSON
The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/message.json