aiellie

Search

Find a component, template or page

GitHub
Components

Message

One turn in a conversation: a bubble or plain text in six variants, with an avatar, header, footer, timestamp, reactions, hover actions and a caret while the reply streams.

Can you split this into two messages?
Like a quick follow-up.
👍
Assistant
Parts that follow each other stack tightly, and only the last one gets the tail. Hover this reply to see its actions.
And while a reply is still being written
Open full screen
fig. 01 · open it full screen from the corner

Installation

npx shadcn@latest add "@aiellie/message"

shadcn needs the @aiellie registry in components.json first. npx aiellie add message adds it on its first run, then installs the same way.

Message lays out one turn of a conversation: an optional avatar, then a column of parts with a header above them and a footer below. Parts that follow each other stack tightly and only the last one gets the tail, so a reply sent as several bubbles reads as one message. align puts it on either side and variant sets how its parts are filled.

Getting started

  1. Render a turn

    A message needs MessageContent and at least one MessagePart. Put the user's on the end side and the assistant's on the start side, usually as ghost so a long reply reads as plain text.

    components/turn.tsx
    import {
      Message,
      MessageContent,
      MessagePart,
    } from "@/components/aiellie/message"
    
    export function Turn({
      from,
      text,
    }: {
      from: "user" | "assistant"
      text: string
    }) {
      return (
        <Message
          align={from === "user" ? "end" : "start"}
          variant={from === "user" ? "secondary" : "ghost"}
        >
          <MessageContent>
            <MessagePart>{text}</MessagePart>
          </MessageContent>
        </Message>
      )
    }
  2. Add the actions

    MessageFooter goes after the parts. MessageActions shows on hover where there's a pointer that can hover, and always on touch, and each MessageAction is a TooltipIconButton.

    components/turn.tsx
    import { Copy01Icon, RepeatIcon } from "@hugeicons/core-free-icons"
    import { HugeiconsIcon } from "@hugeicons/react"
    
    import {
      MessageAction,
      MessageActions,
      MessageFooter,
    } from "@/components/aiellie/message"
    
    <MessageFooter>
      <MessageActions>
        <MessageAction tooltip="Copy" onClick={copy}>
          <HugeiconsIcon icon={Copy01Icon} />
        </MessageAction>
        <MessageAction tooltip="Retry" onClick={retry}>
          <HugeiconsIcon icon={RepeatIcon} />
        </MessageAction>
      </MessageActions>
    </MessageFooter>

    With an avatar, the avatar rises to sit beside the last part rather than the footer.

Anatomy

<div data-slot="message-group"> {/* optional: a run of messages */}
  <div data-slot="message" data-align="start" data-variant="ghost" data-streaming>
    <div data-slot="message-avatar" />
    <div data-slot="message-content">
      <div data-slot="message-header" />
      <div data-slot="message-part">
        <div data-slot="message-reactions" />
        <span data-slot="message-caret" /> {/* shown on the last part while streaming */}
      </div>
      <div data-slot="message-footer">
        <time data-slot="message-time" />
        <div data-slot="message-actions">
          <button /> {/* MessageAction */}
        </div>
      </div>
    </div>
  </div>
</div>

Every part reads align and variant from its message, so nothing below Message takes either. streaming sets data-streaming and aria-busy, and shows a caret after the last part, unless that part holds a StreamText, which draws its own.

Examples

Variants

primary and secondary fill the part, tinted washes it with the primary color, outline draws a border, ghost drops the bubble for plain text the width of the thread, and destructive is for a reply that failed.

primary
secondary
tinted
outline
ghost
destructive

A part that does something

MessagePart takes render, so a part can be a button or a link. It gets a hover fill and a focus border to match its variant.

Pick one to carry on

Reactions

MessageReactions sits on the edge of the part it's in. side picks the top or bottom edge and align the corner; give the part a bottom margin so the next row clears it.

<MessagePart className="mb-2">
  Ship it on Friday?
  <MessageReactions side="bottom" align="end">👍 2</MessageReactions>
</MessagePart>

API reference

Message

PropTypeDefaultDescription
align"start" | "end""start"Which side the message sits on.
variant"primary" | "secondary" | "tinted" | "outline" | "ghost" | "destructive""secondary"How its parts are filled.
streamingbooleanfalseShows a caret after the last part while the reply is still being written.
classNamestringMerged onto the root.

All other div props are forwarded.

MessagePart

PropTypeDefaultDescription
renderReactElement | functionSwaps the div for another element, like a button or a.
classNamestringMerged onto the part.

It grows to 80% of the thread, or the whole width as ghost, and keeps the text's own line breaks.

MessageReactions

PropTypeDefaultDescription
side"top" | "bottom""bottom"Which edge of the part it sits on.
align"start" | "end""end"Which corner of that edge.

MessageActions

PropTypeDefaultDescription
reveal"hover" | "always""hover"Whether the actions wait for the pointer. On touch they always show.

MessageAction

Takes the props of TooltipIconButton, tooltip among them.

PropTypeDefaultDescription
tooltipReactNoderequiredThe tooltip, which is also its accessible name.

Other parts

PartElementDescription
MessageGroupdivA column of messages.
MessageAvatardivA 28px circle beside the parts; icons inside it are 16px.
MessageContentdivThe column of header, parts and footer.
MessageHeaderdivA caption above the parts, like a name.
MessageFooterdivA row below the parts, for the time and actions.
MessageTimetimeThe time it was sent, in tabular figures.

Each takes its element's props and merges className.