Message
One chat message with avatar, author, time, actions and a sending, sent, delivered, read or failed state. Bubble or plain row.
pnpm dlx shadcn@latest add @haze/message---
import { Check, CheckCheck, CircleAlert, Info, LoaderCircle } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
import Avatar from "./avatar.astro";
interface Props {
/** Required. The author name gets `${id}-author` so the article can be named by it. */
id: string;
/** Who wrote the message. It is read first, and the avatar shows its initials. */
name?: string;
/** user is right-aligned in the bubble look, assistant is left-aligned, system is a centered note. */
role?: "user" | "assistant" | "system";
/** Short text read after the name, such as "Customer" or "AI". Leave empty to hide it. */
roleLabel?: string;
/** bubble puts the text on a surface; plain is a full-width transcript row. */
appearance?: "bubble" | "plain";
/** Machine-readable time for the `<time>` element, such as "2026-11-23T09:41:00Z". Pass a fixed value, never the current time. */
time?: string;
/** Time as it should read, such as "09:41". Falls back to the ISO string. */
timeLabel?: string;
/** Delivery state of a message the reader sent. Failed offers the retry slot. Set `data-status` on the status line to change it later; the icon swaps with a pop. */
status?: "sending" | "sent" | "delivered" | "read" | "failed";
/** Text next to the status icon. */
statusLabels?: { sending: string; sent: string; delivered: string; read: string; failed: string };
/** Accessible name of the group that holds the actions slot. */
actionsLabel?: string;
class?: string;
[key: string]: unknown;
}
const {
id,
name = "Mira",
role = "assistant",
roleLabel,
appearance = "bubble",
time,
timeLabel,
status,
statusLabels = { sending: "Sending…", sent: "Sent", delivered: "Delivered", read: "Read", failed: "Not sent" },
actionsLabel = "Message actions",
class: className,
...rest
} = Astro.props;
const user = role === "user";
const system = role === "system";
const bubble = appearance === "bubble";
const hasActions = Astro.slots.has("actions");
const hasRetry = Astro.slots.has("retry");
const statusStates = [
{ key: "sending", Icon: LoaderCircle, icon: "animate-spin" },
{ key: "sent", Icon: Check, icon: "motion-safe:group-data-[status=sent]/status:animate-pop" },
{ key: "delivered", Icon: CheckCheck, icon: "motion-safe:group-data-[status=delivered]/status:animate-pop" },
{ key: "read", Icon: CheckCheck, icon: "motion-safe:group-data-[status=read]/status:animate-pop" },
{ key: "failed", Icon: CircleAlert, icon: "motion-safe:group-data-[status=failed]/status:animate-pop" },
] as const;
const stateShown = {
sending: "group-data-[status=sending]/status:visible group-data-[status=sending]/status:opacity-100",
sent: "group-data-[status=sent]/status:visible group-data-[status=sent]/status:opacity-100",
delivered: "group-data-[status=delivered]/status:visible group-data-[status=delivered]/status:opacity-100",
read: "group-data-[status=read]/status:visible group-data-[status=read]/status:opacity-100",
failed: "group-data-[status=failed]/status:visible group-data-[status=failed]/status:opacity-100",
};
const mirrored = user && bubble;
---
{
system ? (
<article
id={id}
aria-labelledby={`${id}-author`}
class={cn("flex items-start justify-center gap-1.5 text-xs/4 text-muted-foreground", className)}
{...rest}
>
<Info aria-hidden="true" class="mt-px size-3.5 shrink-0" />
<span id={`${id}-author`} class="sr-only">{name}:</span>
<div class="min-w-0 wrap-anywhere"><slot /></div>
{time && <time datetime={time} class="shrink-0 tabular-nums">{timeLabel ?? time}</time>}
</article>
) : (
<article
id={id}
aria-labelledby={`${id}-author`}
class={cn(
"flex min-w-0 gap-2.5",
mirrored && "ml-auto w-fit max-w-[92%] flex-row-reverse",
className,
)}
{...rest}
>
<Avatar name={name} size="sm" class="mt-px" />
<div class={cn("flex min-w-0 flex-col gap-1", mirrored ? "items-end" : "flex-1 items-start")}>
<header class={cn("flex flex-wrap items-baseline gap-x-2 text-xs/4", mirrored && "justify-end")}>
<span id={`${id}-author`} class="font-medium text-foreground">{name}</span>
{roleLabel && <span class="text-muted-foreground">{roleLabel}</span>}
{time && <time datetime={time} class="text-muted-foreground tabular-nums">{timeLabel ?? time}</time>}
</header>
<div
class={cn(
"min-w-0 text-[0.8125rem]/5 wrap-anywhere",
bubble
? cn("rounded-2xl px-3.5 py-2", user ? "rounded-br-md bg-primary text-primary-foreground" : "rounded-bl-md bg-popover text-foreground")
: "w-full text-foreground",
)}
>
<slot />
</div>
{
status && (
<div data-message-status data-status={status} aria-live="polite" class={cn("group/status flex flex-wrap items-center gap-x-2 gap-y-1 text-xs/4 text-muted-foreground data-[status=read]:text-foreground data-[status=failed]:text-destructive", mirrored && "justify-end")}>
<span aria-hidden="true" class={cn("grid", mirrored ? "justify-items-end" : "justify-items-start")}>
{statusStates.map(({ key, Icon, icon }) => (
<span data-state-key={key} class={cn("invisible col-start-1 row-start-1 inline-flex items-center gap-1 opacity-0 transition-[opacity,visibility] duration-150 ease-snappy", stateShown[key])}>
<Icon aria-hidden="true" class={cn("size-3.5", icon)} />
{statusLabels[key]}
</span>
))}
</span>
<span data-message-status-text class="sr-only">{statusLabels[status]}</span>
{hasRetry && <span class="hidden group-data-[status=failed]/status:contents"><slot name="retry" /></span>}
</div>
)
}
{
hasActions && (
<div role="group" aria-label={actionsLabel} class={cn("-mx-1 flex flex-wrap items-center gap-0.5", mirrored && "justify-end")}>
<slot name="actions" />
</div>
)
}
</div>
</article>
)
}
<script>
// Keep a text node in the live region in step with data-status, so assistive technology hears a text change.
function watchStatus(line: HTMLElement) {
if (line.hasAttribute("data-status-watched")) return;
line.setAttribute("data-status-watched", "");
const text = line.querySelector<HTMLElement>("[data-message-status-text]");
if (!text) return;
new MutationObserver(() => {
const label = line.querySelector<HTMLElement>(`[data-state-key="${line.dataset.status}"]`)?.textContent?.trim();
if (label) text.textContent = label;
}).observe(line, { attributes: true, attributeFilter: ["data-status"] });
}
const init = () => document.querySelectorAll<HTMLElement>("[data-message-status]").forEach(watchStatus);
init();
if (!document.documentElement.hasAttribute("data-haze-message-listener")) {
document.documentElement.setAttribute("data-haze-message-listener", "");
document.addEventListener("astro:page-load", init);
}
</script>When to use
- Building a chat or support thread from single messages instead of the ready-made chat-thread panel
- An AI transcript where each reply carries copy, retry or rating buttons
- A sent message that can fail and needs a visible retry
When not to use
- You want a complete panel with a message box. Use chat-thread.
- Entries are comments with replies and reactions under a post. Use comment-thread.
Installation
Add the Haze registry to components.json once, then install Message with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/messagenpx shadcn@latest add @haze/messageyarn dlx shadcn@latest add @haze/messagebunx --bun shadcn@latest add @haze/messageFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| id* | string | – | Id of the article; the author name gets `${id}-author` and names it. |
| name | string | "Mira" | Author name; also the source of the avatar initials. |
| role | "user" | "assistant" | "system" | "assistant" | User is right-aligned in the bubble look, assistant left-aligned, system a centered note without avatar. |
| roleLabel | string | – | Short visible text after the name, such as "You" or "Support assistant". |
| appearance | "bubble" | "plain" | "bubble" | Bubble puts the text on a surface; plain is a full-width transcript row. |
| time | string | – | ISO date-time for the time element. Pass a fixed value, never the current time. |
| timeLabel | string | – | Time as it reads, such as "09:41". |
| status | "sending" | "sent" | "delivered" | "read" | "failed" | – | Delivery state, shown as an icon and text under the message. Sent is a check, delivered a muted double check, read a foreground double check. Change data-status on the status line (the element with data-message-status) to swap the state; the icon pops in. |
| statusLabels | { sending: string; sent: string; delivered: string; read: string; failed: string } | { sending: "Sending…", sent: "Sent", delivered: "Delivered", read: "Read", failed: "Not sent" } | Text for each delivery state. |
| actionsLabel | string | "Message actions" | Accessible name of the group around the actions slot. |
| class | string | – | Extra classes on the article. |
| ...rest | HTML attributes | – | Passed to the article. |
| default slot | slot | – | The message content. |
| actions | slot | – | Small ghost icon buttons such as copy, retry or rate, each with an aria-label. |
| retry | slot | – | A button shown next to the text when status is failed. |
Keyboard interactions
- Tab
- Move through the buttons in the actions and retry slots.
Accessibility
- Each message is an article named by its author, so a screen reader announces who wrote it before the content. Put the articles inside a list or a role="log" container; the component does not add the list item itself.
- The time is a time element with a datetime value.
- Delivery state is an icon plus text (Sending, Sent, Delivered, Read, Not sent), never color alone. The status line is a polite live region with a screen-reader text that follows data-status, so a state change is read once; the icons are hidden from assistive technology and the pop is skipped under reduced motion.
- Action buttons are your own, and each needs an aria-label because they show only an icon. They sit in a group named by actionsLabel.
- This one component covers both a message and a bubble: appearance switches between the two looks, and the markup is the same.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI component "Message" with `npx shadcn@latest add @haze/message`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import Message from "@/components/haze/ui/message.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/message.md
Customize with real content
Adapt the Haze message ui for our product. Replace the demo values of these props with our real content: id, name, role, roleLabel, appearance, time, timeLabel, status, statusLabels, actionsLabel, class, ...rest, default slot, actions, retry. Keep the layout, the heading level rules and these accessibility details: Each message is an article named by its author, so a screen reader announces who wrote it before the content. Put the articles inside a list or a role="log" container; the component does not add the list item itself. The time is a time element with a datetime value. Delivery state is an icon plus text (Sending, Sent, Delivered, Read, Not sent), never color alone. The status line is a polite live region with a screen-reader text that follows data-status, so a state change is read once; the icons are hidden from assistive technology and the pop is skipped under reduced motion. Action buttons are your own, and each needs an aria-label because they show only an icon. They sit in a group named by actionsLabel. This one component covers both a message and a bubble: appearance switches between the two looks, and the markup is the same. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using message, check it fits: use it when building a chat or support thread from single messages instead of the ready-made chat-thread panel; an ai transcript where each reply carries copy, retry or rating buttons; a sent message that can fail and needs a visible retry. Avoid it when you want a complete panel with a message box. use chat-thread.; entries are comments with replies and reactions under a post. use comment-thread.. Alternatives: @haze/chat-thread, @haze/comment-thread, @haze/marker.
Dependencies
- npm: @lucide/astro
- @haze/avatar
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.