User and assistant message layouts for chat threads
import {ChatMessage} from "@peakui-pro/react" ;
import {ChatMessage, ChatMessageActions} from "@peakui-pro/react" ;
export default () => (
<>
{ /* A user turn: a bubble pushed to the far edge */ }
< ChatMessage.User >
< ChatMessage.Bubble >
< ChatMessage.Content >...</ ChatMessage.Content >
</ ChatMessage.Bubble >
</ ChatMessage.User >
{ /* An assistant turn: an avatar beside a column */ }
< ChatMessage.Assistant >
< ChatMessage.Avatar fallback = "AI" />
< ChatMessage.Body >
< ChatMessage.Content >...</ ChatMessage.Content >
< ChatMessage.Actions >
< ChatMessageActions >...</ ChatMessageActions >
</ ChatMessage.Actions >
</ ChatMessage.Body >
</ ChatMessage.Assistant >
</>
);
show={false} keeps the avatar slot empty, so bodies stay aligned.
< ChatMessage.User className = "[--chat-message-bubble-background:var(--accent)] [--chat-message-bubble-foreground:var(--accent-foreground)]" >
< ChatMessage.Bubble >
< ChatMessage.Content >Hello</ ChatMessage.Content >
</ ChatMessage.Bubble >
</ ChatMessage.User >
@layer components {
.chat-message--user {
--chat-message-bubble-background : var ( --accent );
--chat-message-bubble-foreground : var ( --accent-foreground );
}
.chat-message--assistant {
--chat-message-body-inset : 0 px ;
}
}
PeakUI follows the BEM methodology, so variants and states are plain class names you can target.
The ChatMessage component uses these CSS classes (view source styles ):
.chat-message--assistant - Assistant row: avatar beside a column
.chat-message--user - User row: bubble at the far edge
.chat-message__avatar - Avatar slot; keeps its width when the avatar is hidden
.chat-message__body - Assistant column
.chat-message__bubble - User bubble; gains a border in forced colors
.chat-message__content - Wrapping text
.chat-message__actions - Action row container
[data-slot="chat-message-assistant"]
[data-slot="chat-message-user"]
[data-slot="chat-message-avatar"] - carries [data-size="sm" | "md" | "lg"]
[data-slot="chat-message-body"]
[data-slot="chat-message-bubble"]
[data-slot="chat-message-content"]
[data-slot="chat-message-actions-container"]
Set on .chat-message--assistant and .chat-message--user:
Variable Purpose --chat-message-gapSpace between avatar and body --chat-message-padding-blockVertical padding of a row --chat-message-body-gapSpace between the parts of the body --chat-message-body-insetSpace reserved at the end of the body --chat-message-bubble-radiusBubble corner radius --chat-message-bubble-padding-blockBubble vertical padding --chat-message-bubble-padding-inlineBubble horizontal padding --chat-message-bubble-backgroundBubble background color --chat-message-bubble-foregroundBubble text color --chat-message-bubble-max-widthWidest the bubble grows
Set on .chat-message__avatar:
Variable Purpose --chat-message-avatar-sizeWidth of the avatar slot, by size: 2rem, 2.5rem, 3rem
Prop Type Default Description classNamestring- Additional classes renderDOMRenderFunction<'div', undefined>- Replaces the rendered <div> with your own element ...restComponentProps<'div'>- Native <div> attributes
Prop Type Default Description classNamestring- Additional classes renderDOMRenderFunction<'div', undefined>- Replaces the rendered <div> with your own element ...restComponentProps<'div'>- Native <div> attributes
Prop Type Default Description srcstring- The image; without it, or until it loads, the fallback shows fallbackReactNode- Initials or a glyph shown until the image loads, and on the server altstring""Text alternative of the image; empty because the message already names the speaker showbooleantrueWhen false the slot stays and is empty color'default' | 'accent' | 'success' | 'warning' | 'danger''default'Fallback color of the core Avatar size'sm' | 'md' | 'lg''sm'Avatar size; also sets the width of the slot variant'default' | 'soft''default'Core Avatar style classNamestring- Additional classes renderDOMRenderFunction<'div', undefined>- Replaces the rendered <div> with your own element ...restOmit<ComponentProps<'div'>, 'children' | 'color'>- Native <div> attributes; the slot's own children are the Avatar
Prop Type Default Description classNamestring- Additional classes renderDOMRenderFunction<'div', undefined>- Replaces the rendered <div> with your own element ...restComponentProps<'div'>- Native <div> attributes
Prop Type Default Description classNamestring- Additional classes renderDOMRenderFunction<'div', undefined>- Replaces the rendered <div> with your own element ...restComponentProps<'div'>- Native <div> attributes
Prop Type Default Description classNamestring- Additional classes renderDOMRenderFunction<'div', undefined>- Replaces the rendered <div> with your own element ...restComponentProps<'div'>- Native <div> attributes
Prop Type Default Description classNamestring- Additional classes renderDOMRenderFunction<'div', undefined>- Replaces the rendered <div> with your own element ...restComponentProps<'div'>- Native <div> attributes. Holds the container only; put ChatMessageActions inside. Also exported as ChatMessageActionsContainer