Skip to content

Add the Message family #98

Closed
Closed

Description

@pratikbuilds

Render one message and its surroundings as small composable parts: author, time, content, delivery state, actions, reactions and replies.

Part of #94.

Depends on #95, #96.

Why

A chat message carries more than text: who wrote it, when, whether it was delivered, actions, reactions and replies. Small parts let each app choose what to show, and markdown stays the host's choice through a render prop.

What

  • src/ui/message.tsx: Message (from: agent, person or own; status; onRetry), MessageAvatar, MessageHeader, MessageContent (the render prop for markdown), MessageFooter. The own-message bubble is built here.
  • src/ui/message-fold.tsx: MessageFold, which folds a long answer.
  • src/ui/message-actions.tsx: MessageActions, MessageAction, and an overflow menu for extras.
  • src/ui/message-reactions.tsx: MessageReactions.
  • src/ui/message-replies.tsx: MessageReplies (count, and last reply time via relative-time.ts).
  • src/hooks/use-copy.ts: useCopy.
  • stories/chat/message.stories.tsx: agent, person, own, no avatars, actions, reactions, replies, sending, failed and a very long answer, using the shared samples from Add sample conversations for the chat stories #96.
  • e2e/fixtures.tsx: scenarios for the fold and the overflow menu, with e2e/message.spec.ts.
  • src/hooks/use-copy.test.ts, src/ui/message.test.tsx, src/ui/message-fold.test.tsx; exports in src/index.ts.

Requirements

  • R16: Message with avatar, header, content (one render slot, no separate response part) and footer; own messages in a bubble; avatars and names optional.
  • R17: MessageFold folds past a length threshold and keeps the reader's place when folding from inside.
  • R18: actions with an overflow menu, reactions, replies, and useCopy.
  • R19: sending shows it is on its way; failed shows the error and a retry that calls onRetry.
  • R5–R12: the shared component rules.

Constraints

  • Reuse the existing Avatar and Button. The old MessageBubble stays until Remove the old chat components #110.
  • No bubble on agent replies when avatar and header are left out; own messages sit in a bubble on the right.
  • The overflow menu doesn't import ui/menu; build it on useDismissablePopover.
  • MessageFold keeps the reader's place with its own measurement (scroll the nearest scroll container by the height delta). It doesn't import useConversation or need a Conversation ancestor.
  • The shared rules in Replace the chat components with a stateless Conversation family #94 apply: no new dependency or peer, no optional-peer import, token-only styling, no change to existing modules, additions only to src/index.ts and e2e/fixtures.tsx.

Done when

  • Unit tests cover:
    • useCopy: copied turns on after copy and off after the timeout; the timer is cleared on unmount; a rejected clipboard write leaves copied false.
    • MessageFold: under the threshold there is no toggle; over it, it folds by default and toggles; streaming content never folds.
    • Message: sending shows its state; failed shows the error and a retry control that calls onRetry once; MessageContent passes its text through render.
  • Browser spec covers:
    • Folding MessageFold from inside the folded answer keeps the fold control at the same viewport offset (±1px).
    • The overflow menu opens from the keyboard, arrow keys move between items, Escape closes it and focus returns to the trigger.
  • No serious or critical axe violation in the new stories, in light or dark.
  • bun run check, bun run build, bun run test:e2e and bun run dep-guard pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions