Atoms

Bubble

The surface of a chat message, with variants, alignment, and reactions.

shadcn/ui
Docs

Installation#

npx shadcn@latest add @formance/bubble

Install the following dependencies:

npm install class-variance-authority radix-ui

Copy and paste the following code into your project.

Update the import paths to match your project setup.

Usage#

import { Bubble, BubbleContent, BubbleReactions } from '@/components/ui/bubble';
<Bubble variant="muted">  <BubbleContent>How do withdrawals move money?</BubbleContent>  <BubbleReactions role="img" aria-label="Reaction: thumbs up">    <span>👍</span>  </BubbleReactions></Bubble>

Use muted for the messages of the user, and ghost for long assistant replies rendered with the Markdown fragment.

Composition#

Bubble├── BubbleContent└── BubbleReactions

Use BubbleGroup to group consecutive bubbles from the same sender:

BubbleGroup├── Bubble│   └── BubbleContent└── Bubble    └── BubbleContent

Features#

  • Seven variants, from a strong primary bubble to content with no frame.
  • Start and end alignment, for the user and for the assistant.
  • Reactions that attach to the edge of the bubble, with a side and an alignment.
  • A bubble is as wide as its content, to a maximum of 80% of the container.
  • asChild on BubbleContent makes a link bubble or a button bubble.
  • Each part accepts className.

Examples#

Variants#

Use variant to change the visual treatment of the bubble.

Sizes#

A bubble grows with its content: one line, a wrapped paragraph, or several paragraphs.

VariantDescription
defaultA strong primary bubble, usually for the user.
secondaryA neutral bubble for conversation content.
mutedA bubble with less emphasis, for quiet content.
tintedA bubble with a light tint of the primary color.
outlineA bubble with a border, for secondary content.
ghostContent with no frame, for assistant text.
destructiveA bubble for errors and failed actions.

The ghost variant has no maximum width, so assistant text can use the full row.

Alignment#

Use align on Bubble to align the bubble to the start or to the end of the conversation.

alignDescription
startAlign the bubble to the start of the conversation.
endAlign the bubble to the end of the conversation.

In a chat interface, set align on the Message instead. The bubbles in the message then align with it.

Bubble group#

Use BubbleGroup to group consecutive bubbles from the same sender. Set align on each Bubble, not on the BubbleGroup.

Set asChild on BubbleContent to render a bubble as a link or as a button.

<Bubble variant="muted">  <BubbleContent asChild>    <button type="button">Explain my chart of accounts</button>  </BubbleContent></Bubble>

Reactions#

Use BubbleReactions to show reactions or quick actions. Use side and align to set the position. side="top" attaches the row to the top edge. Reactions go across the edge of the bubble, so keep a large gap between rows.

Show more#

Use a Collapsible to show or hide long bubble content. A CollapsibleTrigger opens and closes it.

Tooltip#

Use a Tooltip to show metadata on hover, for example the time when a message was read.

Popover#

Use a Popover to show more information on demand, for example the full error of a failed action.

Suggestions#

Use asChild buttons in a BubbleGroup to show replies the user can pick.

Error#

Use destructive when the assistant cannot complete a request.

Accessibility#

  • Reactions are a row of emoji. A screen reader reads each glyph with no context, and reads +2 as "plus two". Set role="img" and an aria-label on BubbleReactions, so the row is announced one time.
  • When a reaction is interactive, use a button. Give an aria-label to a button that has only an icon.
  • When a bubble is interactive, use a real <button> or <a> with asChild. BubbleContent shows a focus ring, and the text of the bubble is the accessible name.
  • A variant gives meaning with color. Also give the meaning in the text, the alignment, or an icon. For a destructive bubble, put the error in the text.

API reference#

Bubble#

PropTypeDefaultDescription
variant"default" | "secondary" | "muted" | "tinted" | "outline" | "ghost" | "destructive""default"The visual treatment.
align"start" | "end""start"The side of the conversation.
classNamestring-More classes for the bubble.

BubbleContent#

PropTypeDefaultDescription
asChildbooleanfalseRender the child, for example a button or a link.
classNamestring-More classes for the content.

BubbleReactions#

PropTypeDefaultDescription
side"top" | "bottom""bottom"The edge of the bubble.
align"start" | "end""end"The position along the edge.
classNamestring-More classes for the row of reactions.

BubbleGroup#

PropTypeDefaultDescription
classNamestring-More classes for the group.