← All proposals

Chat Message

ChatMessage, with sender: user or agent.

Net-new componentOpen in Storybook

proposals/ChatMessage/HANDOFF.md145 lines · View on GitHub

Handoff: ChatMessage

Rewritten 2026-11-20 against v2.0.0-beta.21 to the lessons template. Every prop, class and token below was checked against ChatMessage.tsx, ChatMessageList.tsx, chat-message.css, chat-message-list.css and the stories as they are now. Nothing here was checked by eye in a session.

What and why

One turn in an AI chat or agent conversation. PDS has no component for it. The user's message (a filled bubble on the right) and the agent's reply (plain content across the full width) are the same kind of thing, so it is one component with two variants, plus a thin ChatMessageList that stacks turns and owns the gap between them. Figma: Chat Message page (first sent 2026-10-19; the designer has since replaced the captures with a hand-built ChatMessage component set, Sender variants, in a section named "Chat message"). Context: context.md.

Exploration and decisions

  • One component with sender: 'agent' | 'user', not two components: same slots, same screen-reader need, a chat maps over messages with one field. Not role (collides with the HTML attribute) and not variant (set per message by who sent it).
  • The component owns only the frame (alignment, width, user bubble, hidden sender label). Content is children, because agent messages hold arbitrary content.
  • ChatMessageList exists so the gap between turns is a real, annotated part of the proposal and a place for list behavior later. See "Expect to change" 3: a layout component may already cover it.
  • Rich agent content (markdown output) is the renderer's: fenced code maps to the PDS CodeBlock; inline code is the package's styled <code> (see Target-version check). One exception: ul / ol in an agent message get start padding.
  • Type uses the semantic pds-copy-s class instead of font primitives (2026-10-19).

Full list and reasons: decisions.md. That file has two stale lines, corrected by a dated note at its bottom (the Storybook title, and "PDS has no inline code style").

API

ChatMessage (a div; extends div props, spread onto the root):

Prop Type Default Purpose
children ReactNode none (required) Message content: text for a user message; anything for an agent message (text, lists, a Thinking State, Chain of Thought).
className string none Additional class names.
label string none (required) Who sent it, read by screen readers before the message (for example "You" or "Zappy"). Visually hidden. No dev warning when missing.
sender 'agent' | 'user' 'agent' user: bubble on the right, hugs its content, max 80%. agent: no container, full width.

ChatMessageList (a div; extends div props, spread onto the root): children (the messages, required) and className. The consumer adds role / aria-label (for example role='log'). It has no props of its own beyond those.

Exported types: ChatMessageSender, ChatMessageProps, ChatMessageListProps.

Variants and states: agent, user. Stories: Agent, User, Conversation. ChatMessageList has no story or Controls of its own; it appears only in Conversation.

Story-only helpers (L9): none in this folder. The sample text constants and the Conversation content (including the list in the agent reply) exist only in the stories.

Tokens used

From chat-message.css and chat-message-list.css as they are now:

  • --pds-border-radius-card
  • --pds-color-foreground-default
  • --pds-color-surface-default-secondary
  • --pds-spacing-2xs
  • --pds-spacing-l
  • --pds-spacing-s

Impact

From impact.md: no existing PDS component is reached and no --pds-* token is redefined. The generated report says no other proposal imports ChatMessage by code. In fact ChatPanel (ChatPanel.stories.tsx) and ChatWithAgent (ChatWithAgent.stories.tsx) import both ChatMessage and ChatMessageList in their stories, so port ChatMessage first or those stories break. (The generator misses story imports; not changed here.)

Reused vs net-new

  • Reused: the semantic pds-copy-s type class, the visually-hidden class, PDS tokens only. No PDS component is composed.
  • Net-new: .pds-chat-message (--agent, --user, __content) and .pds-chat-message-list; props: all of ChatMessageProps and ChatMessageListProps; custom CSS variables --chat-message-max-width (80%) and --chat-message-list-gap (--pds-spacing-l). No raw values kept. Details in custom.md.

Accessibility

Nothing here was run: the a11y panel has not been run, and light and dark were not checked by eye. What the code does:

  • The sender label is a visually hidden span before the content, so a screen reader reads "You" or "Zappy" first. Do not repeat the sender in the visible content.
  • No interactive elements, so no keyboard behavior or focus styles of its own; content inside an agent message brings its own.
  • ChatMessageList has no role of its own. The screen adds one. role='log' was only suggested; it is untested and the live-region behavior (what is announced while an agent streams, and when) is not designed yet. ChatWithAgent.stories.tsx uses a separate visually hidden role='status' span, not the list.
  • A missing label is silent: the message is then read with no sender.

Decisions and open questions

Each carries a recommended answer (a recommendation, not a decision; the designer or engineer decides).

  • Bubble radius and 80% width vs the design. The code uses --pds-border-radius-card (8px) and 80%. Recommendation: confirm by eye against Figma; it is a one-token change.
  • User fill in dark mode. surface-default-secondary is oklch 0.2520 in dark on a surface-default of 0.2178 (light: 0.9731 on 1.0). Both gaps are small and nothing has been looked at. Recommendation: check the bubble against the actual panel surface in both themes before porting. The package has only three surface tokens (surface-default, surface-default-secondary, surface-reverse), so there is no in-between fill to fall back on; if it is too faint, add a border instead (border-default), which is a design call.
  • Who owns spacing between blocks inside an agent message (reference --pds-spacing-l)? Today it is the renderer's. Recommendation: keep it the renderer's; the component stays a frame.
  • Inline code. Resolved by the package: see Target-version check. Recommendation: no InlineCode component; use the package's <code> style.
  • Next for the list: scroll and live-region behavior, an avatar, agent actions (copy, regenerate, feedback), user extras (attachments, edit, timestamps). Recommendation: leave all out of this port; design the live region first.

Extension or new component

New component. Nothing in the package at beta.21 is a chat turn: it has no message, bubble or conversation component, and the closest candidates are not extensions. Panel and SectionMessage are containers with their own chrome; IdentityBlock and AvatarLabel identify who, they do not frame content. No human behavior of an existing component is changed. ChatMessageList may not need to exist: see Expect to change 3.

Footprint

Nothing is drawn outside the box: no shadow, outline, pseudo-element or negative offset. What a parent could size or clip wrongly:

  • The user bubble is max-width: 80% of the message's own width (the root is a flex column with align-items: flex-end). A parent with no definite width (a shrink-to-fit or inline container) makes that 80% resolve against the content, so the bubble may not reach 80% of the screen. Use it in a block-level, full-width list.
  • min-width: 0 and overflow-wrap: anywhere on the content keep long words inside the bubble. Wide agent content (a code block or table) has no overflow rule here and is not clipped or scrolled by this component; not checked.
  • The bubble keeps typed line breaks (white-space: pre-wrap), so a user message with many lines is tall; nothing clamps it.
  • Agent messages are width: 100%; in a flex row parent they take the whole row.
  • ChatMessageList is a flex column with a spacing-l (20px) gap. Messages add no margin of their own, so a message outside the list has no spacing from its neighbors.

Dark mode and per-size values

Single size: there is no size prop, and the CSS has no per-theme override. Colors are semantic tokens that the theme files redefine (values from variables.light.css and variables.dark.css; how they look is not checked).

Part Value Light Dark
Text foreground-default, class pds-copy-s oklch(0.2178 0 0) oklch(0.9702 0 0)
User bubble fill surface-default-secondary oklch(0.9731 0 0) oklch(0.2520 0 0)
User bubble radius border-radius-card 8px 8px
User bubble padding block spacing-2xs (8px), inline spacing-s (12px) same same
User bubble max width --chat-message-max-width 80% same same
Agent content no container, width: 100% same same
Agent ul / ol padding-inline-start: spacing-l (20px) same same
Gap between turns (list) --chat-message-list-gap = spacing-l (20px) same same

The surface behind the bubble is whatever the parent sets (for example surface-default: light oklch(1.0000 0 0), dark oklch(0.2178 0 0)). Contrast of text on the bubble in both themes: not checked.

Expect to change

Each choice below breaks, or may break, a toolkit convention. The answer in italics is a recommendation.

  1. label is required with no dev warning (L2, L3). It is the sender's screen-reader text, top-level and translatable (good), but required in the type and silent when empty. The shipped pattern for "who is this" is isAgent plus agentLabel (IdentityBlock, AvatarLabel); label is neutral because it names either sender ("You", "Zappy"). Recommendation: make it optional and add a [ChatMessage] warning under process.env.NODE_ENV !== 'production' when it is missing; keep it a top-level prop. The name is the engineer's call; senderLabel would say more than label.
  2. Two exports in one proposal (ChatMessage and ChatMessageList). Recommendation: keep ChatMessage; see 3 for the list.
  3. ChatMessageList may duplicate an existing layout. FlexContainer (utilities/FlexContainer, in the package) takes flexDirection='column' and gap='l' (maps to --pds-spacing-l) and extends div props, so it can carry a role and aria-label. Recommendation: port ChatMessage alone and use FlexContainer for the stack; keep ChatMessageList only if the list behavior (scroll, live region, avatars) gets designed. Not verified: how FlexContainer renders with Annotate or that nothing in it conflicts with role='log'.
  4. sender string union with a default of 'agent' (L2). A boolean such as isUser would also work; the union keeps room for a third sender (for example a system message). Recommendation: keep the union; the default is fine because the agent is the unmarked case, but confirm the default with the engineer.
  5. Component CSS variables for two values (L11). --chat-message-max-width (80%) and --chat-message-list-gap are internal hooks, not props, and are one right value each. Recommendation: do not turn either into a prop.
  6. List padding rule inside agent content (L7). ul / ol in an agent message get spacing-l start padding because the markers were clipped. The package's foundation lists.css already sets padding-inline-start: var(--pds-spacing-m) on ul, ol (checked at beta.21); the proposal's note said the PDS reset removes list padding, and that was not rechecked in a browser. Recommendation: drop the rule and check whether the markers show; if they do, the renderer owns lists like every other block.
  7. white-space: pre-wrap on the user bubble. Keeps typed line breaks. Recommendation: keep; it is behavior, not a knob.
  8. Local mergeClasses stand-in. Recommendation: use @libs/components/utils.

Target-version check

Checked in .pds-reference/src at v2.0.0-beta.21 (and CHANGELOG.mdx). The changelog has no entry for a chat message or conversation component.

Item In beta.21? Notes
A chat message, bubble or conversation component no none in src/components
Inline code style yes foundations/inline-code/inline-code.css styles <code> inside p, span and li (background, border, radius, code font, padding). Our docs said PDS had none; that was stale.
FlexContainer with flexDirection and gap yes utilities/FlexContainer; gap scale includes l
ul / ol padding in the foundation yes foundations/lists/lists.css, padding-inline-start: var(--pds-spacing-m)
CodeBlock (fenced code) yes components/code-display/CodeBlock
Classes pds-copy-s, visually-hidden yes typography styles and foundations/a11y.css
Tokens (border-radius-card, spacing 2xs, s, l, surface and foreground) yes pds-design-tokens files
mergeClasses yes in source @libs/components/utils; the published package does not export it

Not verified: how FlexContainer behaves with role='log' in a browser.

Port notes

Would live in src/components/ (a new chat or conversation category folder; generator npm run generate:component). Not yet matching v2: the local mergeClasses stand-in (use @libs/components/utils). The pds-copy-s class is !important, so a rule on the same element cannot override size or weight. Port before ChatPanel, ChatWithAgent and anything else whose stories import it.

Preview

npm run storybook, story Component Proposals / AI Chat / Chat Message. Figma: https://www.figma.com/design/AMGWJbraJoi2PKWnxo29Ah/PDS-Proposals?node-id=257-43