Message
Lays out one turn in a conversation, with an avatar, a header, the message content, a footer and alignment.
Message lays out one turn: the avatar, the side, a header above the content
and a footer below it. The content itself is usually a
Bubble, which is only the surface. An assistant's
reply, a reasoning step or a tool call can sit in the same place.
Installation
Needs the arene setup first. Also adds Bubble and Stack.
Install the packages it imports:
Set up the token layer and the StyleX compiler, if you have not already. See Installation. The message builds on Bubble and Stack, so paste those first. The examples put an Avatar in the avatar slot.
Paste this source into the file named in its title.
Change the @/ imports if your project uses different aliases.
Usage
Composition
MessageGroup stacks back-to-back messages from one sender:
The header and the footer are children of the message, not of
MessageContent. The message is a grid, and the content is its one fixed
cell: the header takes a row above it, the footer a row below, and the avatar
a column beside it, each only when it is there. Write them in reading order,
as above, so a screen reader meets them in the order they are drawn.
align on the message moves the whole turn. The avatar goes to that side,
and the header, the content and the footer line up with it. A
Bubble inside takes the message's side, so it needs
no align of its own.
Avatar
Use MessageAvatar to put an avatar beside the content. It sits level with
the bottom of the content, so a footer below the last bubble does not push it
down. With align="end" it moves to the end.
Group
MessageGroup stacks back-to-back messages from one sender. Put an
empty MessageAvatar on the earlier messages so they line up with the avatar
on the last one. gap takes a step on the spacing scale and defaults to 1.
Header and footer
MessageHeader holds the sender's name, and MessageFooter holds details such
as whether the message was delivered or read. Both are indented to line up with the text inside a
bubble, ghost included.
Actions
Put message actions in MessageFooter: copy, retry, or feedback toggles. Use
ghost icon buttons, each with a Tooltip and an
aria-label, and set aria-pressed on a toggle.
Markdown
Put an assistant's reply in a ghost bubble, so it is unframed and can take
the full width. It keeps the bubble's padding, so its text lines up with the
header and the footer.
Yes. Three things make it work:
- Pass assistant text through a Markdown renderer.
- Show user messages exactly as they were typed.
- Put the reply in a
ghostbubble so it has no frame.
Attachment
Put an Attachment in MessageContent beside
the bubble, above it or below it. It takes the message's side like a bubble
does.
Accessibility
Message is a presentational layout. Accessibility comes from what you put
in it.
Icon-only actions
Most footer actions show only an icon. Each one needs an aria-label.
Status updates
For a message in progress, use a Marker with
role="status", so assistive technology announces the update when it
appears.
API reference
Pass render to replace a part's element or compose it with another component.
Every part also takes xstyle, className and style.
Message
Renders a div. It provides its align to the bubbles inside it.
| Prop | Type | Default |
|---|---|---|
align | "start" | "end" | "start" |
MessageGroup
Renders a div: a vertical Stack whose only layout
prop is gap.
| Prop | Type | Default |
|---|---|---|
gap | SpacingStep | 1 |
MessageAvatar
Renders a div, at least 32px wide, at the bottom of the turn. Empty, it
keeps the column so grouped messages line up.
MessageContent
Renders a div: a vertical Stack whose only layout
prop is gap. It holds the bubbles and anything beside them, and lines them up
with the message's side.
| Prop | Type | Default |
|---|---|---|
gap | SpacingStep | 1.5 |
MessageHeader
Renders a div in the row above the content, in small muted type, indented
to line up with the text in a bubble.
MessageFooter
Renders a div in the row below the content, styled like the header.
messageStyles
The style maps behind the component. Spread them onto any element.
| Key | What it is |
|---|---|
base | The turn's grid, its gaps and its type |
aligns | One entry per align |
avatar | The avatar's box, level with the bottom of the content |
avatarSides | The avatar's column, one entry per align |
content | The content's cell, width and word breaking |
header | The header's row above the content, type, colour, indent |
footer | The footer's row below the content, type, colour, indent |
Data attributes
| Attribute | On | Effect |
|---|---|---|
data-slot="message" | the root | Targets the message from a parent |
data-align | the root | Reflects align |
data-slot="message-avatar" | the avatar | Targets the avatar from a parent |
data-slot="message-content" | the content | Targets the content from a parent |
data-slot="message-header" | the header | Targets the header from a parent |
data-slot="message-footer" | the footer | Targets the footer from a parent |
data-slot="message-group" | the group | Targets the group from a parent |