---
title: "Bubble"
description: "Bubble with accessible presentation and local state."
---

# Bubble

Bubble with accessible presentation and local state.

## Installation

Install the shared package once in your Exact app. This version is a beta.

```sh
bun add --exact @rightui/ui@0.4.0-beta.4
```

Or choose another package manager:

```sh
npm install --save-exact @rightui/ui@0.4.0-beta.4
pnpm add --save-exact @rightui/ui@0.4.0-beta.4
yarn add --exact @rightui/ui@0.4.0-beta.4
```

Exact compilation uses Bun 1.4.2. Register Geist and Newsreader, declare the font marker and add the root provider using [Installation](/docs/installation).

### Manual source setup

Install an editable copy of the complete package:

```sh
mkdir -p vendor/rightui vendor/rightui-ui
npm pack @rightui/ui@0.4.0-beta.4 --pack-destination vendor/rightui
tar -xzf ./vendor/rightui/rightui-ui-0.4.0-beta.4.tgz -C vendor/rightui-ui --strip-components=1
bun add file:./vendor/rightui-ui
```

Keep package.json, the Contract files, ui.tamber, assets and licenses together.

### Import

```contract
use Bubble, BubbleOptions, BubbleFrame, BubbleGroup, BubbleContent, BubbleButton, BubbleLink, BubbleReactions, BubbleAction, BubblePopoverAction from "@rightui/ui"
```

## Usage

Import Bubble(id, body, align, variant, collapsible) for the legacy wrapper. Use BubbleOptions to also supply reactions, reduced, initialCollapsed and previewLength explicitly. Compose grouped content, links, buttons, reactions and popovers with the public Bubble parts; pass every required prop. Variants are default, secondary, muted, tinted, outline, destructive and ghost; primary remains a legacy alias. Use MarkdownDocument and parseMarkdown inside BubbleContent for Markdown.

## Example

````contract
use FontWeights from "@rightui/ui"
use uiFontFamily, BubbleOptions, BubbleFrame, BubbleContent, BubbleGroup, BubbleReactions, BubbleButton, BubbleLink, BubbleAction, BubblePopoverAction, MarkdownDocument, parseMarkdown, Button from "@rightui/ui"

component Demo
  props
    width: number
    reduced: bool
  inject
    uiWeights: FontWeights
    uiFont: string
  state reply = "Choose a reply."
  state helpful = false
  state approved = false
  state copied = false
  state read = false
  action choose(value: string)
    reply = value
  action react
    helpful = not helpful
  action approve
    approved = true
  action copy
    copyText("The RightUI component sources are ready for review.")
    copied = true
  action showRead
    read = true
  view
    column gap="ui.space-32" min-width="0px" max-width="100%" width="100%"
      text "Conversation and grouping" font-weight=uiWeights.semibold font-family=uiFontFamily(uiFont) data-rightui-font="body"
      BubbleOptions(id="bubble-outgoing", body="Can you show me the RightUI conversation components?", align="end", variant="default", collapsible=false, reactions=false, reduced=reduced, initialCollapsed=false, previewLength=180)
      BubbleGroup(id="bubble-incoming-group", label="Assistant replies")
        BubbleOptions(id="bubble-incoming-one", body="Yes. Start with the message surface.", align="start", variant="muted", collapsible=false, reactions=false, reduced=reduced, initialCollapsed=false, previewLength=180)
        BubbleFrame(id="bubble-incoming-two", align="start", variant="muted")
          BubbleContent(id="bubble-incoming-two-content")
            text "Group consecutive replies and keep reactions close to the message." font-size="ui.text-sm" line-height="ui.leading-code" font-family=uiFontFamily(uiFont) data-rightui-font="body"
          BubbleReactions(id="bubble-incoming-reactions", label="Reactions: thumbs up, fire, eyes, and two more", interactive=false, side="bottom", align="end")
            text "👍 🔥 👀 +2" font-family=uiFontFamily(uiFont) data-rightui-font="body"
      BubbleGroup(id="bubble-outgoing-group", label="Your consecutive replies")
        BubbleOptions(id="bubble-outgoing-one", body="Show me the variants.", align="end", variant="default", collapsible=false, reactions=false, reduced=reduced, initialCollapsed=false, previewLength=180)
        BubbleOptions(id="bubble-outgoing-two", body="Then show me the actions.", align="end", variant="default", collapsible=false, reactions=false, reduced=reduced, initialCollapsed=false, previewLength=180)
      text "Seven variants" font-weight=uiWeights.semibold font-family=uiFontFamily(uiFont) data-rightui-font="body"
      BubbleOptions(id="bubble-default", body="Default RightUI bubble", align="start", variant="default", collapsible=false, reactions=false, reduced=reduced, initialCollapsed=false, previewLength=180)
      BubbleOptions(id="bubble-secondary", body="Secondary RightUI bubble", align="end", variant="secondary", collapsible=false, reactions=false, reduced=reduced, initialCollapsed=false, previewLength=180)
      BubbleOptions(id="bubble-muted", body="Muted supporting message", align="start", variant="muted", collapsible=false, reactions=false, reduced=reduced, initialCollapsed=false, previewLength=180)
      BubbleOptions(id="bubble-tinted", body="Tinted RightUI bubble", align="end", variant="tinted", collapsible=false, reactions=false, reduced=reduced, initialCollapsed=false, previewLength=180)
      BubbleOptions(id="bubble-outline", body="Outline RightUI bubble", align="start", variant="outline", collapsible=false, reactions=false, reduced=reduced, initialCollapsed=false, previewLength=180)
      BubbleOptions(id="bubble-destructive", body="Error: the local command could not open the requested file.", align="end", variant="destructive", collapsible=false, reactions=false, reduced=reduced, initialCollapsed=false, previewLength=180)
      BubbleOptions(id="bubble-ghost", body="Ghost content spans the available width without a frame.", align="start", variant="ghost", collapsible=false, reactions=false, reduced=reduced, initialCollapsed=false, previewLength=180)
      text "Markdown" font-weight=uiWeights.semibold font-family=uiFontFamily(uiFont) data-rightui-font="body"
      BubbleFrame(id="bubble-markdown-user", align="end", variant="muted")
        BubbleContent(id="bubble-markdown-user-content")
          MarkdownDocument(id="bubble-markdown-question", blocks=parseMarkdown("Can you explain **reusable components** and `Exact Contract`?"))
      BubbleFrame(id="bubble-markdown-assistant", align="start", variant="ghost")
        BubbleContent(id="bubble-markdown-assistant-content")
          MarkdownDocument(id="bubble-markdown-document", blocks=parseMarkdown("## RightUI components\n\nUse **public components** for consistent behavior.\n\n- Keep keyboard focus visible.\n- Respect *reduced motion*.\n\n> Reuse the same tokens across the library.\n\n```contract\ncomponent Greeting\n  view\n    text \"Hello from RightUI\"\n```\n\n[Jump to reply feedback](#bubble-help-result)"))
      text "Links and buttons" font-weight=uiWeights.semibold font-family=uiFontFamily(uiFont) data-rightui-font="body"
      BubbleOptions(id="bubble-help-question", body="How can I help you today?", align="start", variant="muted", collapsible=false, reactions=false, reduced=reduced, initialCollapsed=false, previewLength=180)
      BubbleGroup(id="bubble-help-options", label="Reply options")
        BubbleButton(id="bubble-help-password-button", label="I forgot my password", press=choose("Password help selected. Use your account's password reset flow."), align="end", variant="tinted")
        BubbleButton(id="bubble-help-subscription-button", label="I need help with my subscription", press=choose("Subscription help selected. Check the billing section in your account."), align="end", variant="tinted")
        BubbleButton(id="bubble-help-human-button", label="Something else. Talk to a human.", press=choose("Human support selected. This local demo records your choice."), align="end", variant="tinted")
      BubbleLink(id="bubble-link-feedback", label="Jump to reply feedback", href="#bubble-help-result", align="end", variant="outline")
      text reply id="bubble-help-result" testId="bubble-help-result" role="status" font-size="ui.text-sm" font-family=uiFontFamily(uiFont) data-rightui-font="body"
      text "Reactions and actions" font-weight=uiWeights.semibold font-family=uiFontFamily(uiFont) data-rightui-font="body"
      BubbleFrame(id="bubble-reaction-start", align="end", variant="muted")
        BubbleContent(id="bubble-reaction-start-content")
          text "These reactions sit at the start of the lower edge." font-size="ui.text-sm" line-height="ui.leading-code" font-family=uiFontFamily(uiFont) data-rightui-font="body"
        BubbleReactions(id="bubble-reaction-start-row", label="Reactions: thumbs up and surprised", align="start", interactive=false, side="bottom")
          text "👍 😮" font-family=uiFontFamily(uiFont) data-rightui-font="body"
      BubbleFrame(id="bubble-reaction-top", align="end", variant="default")
        BubbleContent(id="bubble-reaction-top-content")
          text "These reactions sit above the message." font-size="ui.text-sm" line-height="ui.leading-code" font-family=uiFontFamily(uiFont) data-rightui-font="body"
        BubbleReactions(id="bubble-reaction-top-row", label="Reactions: party popper and clapping hands", side="top", align="start", interactive=false)
          text "🎉 👏" font-family=uiFontFamily(uiFont) data-rightui-font="body"
      BubbleFrame(id="bubble-action-message", align="start", variant="muted")
        BubbleContent(id="bubble-action-content")
          text "The RightUI component sources are ready for review." font-size="ui.text-sm" line-height="ui.leading-code" font-family=uiFontFamily(uiFont) data-rightui-font="body"
        BubbleReactions(id="bubble-action-row", label="Message actions", side="bottom", align="end", interactive=true)
          BubbleAction(id="bubble-action-helpful", label=(helpful ? "Remove helpful reaction" : "Mark as helpful"), icon="hand.thumbsup", pressed=some(helpful), press=react)
          BubbleAction(id="bubble-action-copy", label=(copied ? "Message copied" : "Copy message"), icon=(copied ? "check" : "copy"), press=copy, pressed=none)
      if helpful or copied
        text (copied ? "Message copied to the clipboard." : "Helpful reaction added.") role="status" font-size="ui.text-xs" font-family=uiFontFamily(uiFont) data-rightui-font="body"
      BubbleFrame(id="bubble-confirmation", align="start", variant="destructive")
        BubbleContent(id="bubble-confirmation-content")
          text (approved ? "Local action approved." : "Approve this local action?") font-size="ui.text-sm" line-height="ui.leading-code" font-family=uiFontFamily(uiFont) data-rightui-font="body"
        BubbleReactions(id="bubble-confirmation-actions", label="Approval action", side="bottom", align="end", interactive=true)
          Button(id="bubble-confirm-action", label=(approved ? "Approved" : "Yes, approve it"), variant="ghost", disabled=approved, press=approve)
      text "Read receipt tooltip" font-weight=uiWeights.semibold font-family=uiFontFamily(uiFont) data-rightui-font="body"
      BubbleOptions(id="bubble-tooltip-question", body="Did you remove the stale route?", align="start", variant="secondary", collapsible=false, reactions=false, reduced=reduced, initialCollapsed=false, previewLength=180)
      BubbleFrame(id="bubble-tooltip-message", align="end", variant="default")
        BubbleContent(id="bubble-tooltip-content")
          text "Yes, removed it from the registry." font-size="ui.text-sm" line-height="ui.leading-code" font-family=uiFontFamily(uiFont) data-rightui-font="body"
        BubbleReactions(id="bubble-tooltip-receipt", label="Read receipt", side="bottom", align="end", interactive=true)
          BubbleAction(id="bubble-tooltip-action", label="Read on Jan 5, 2026 at 4:32 PM", icon="check", press=showRead, pressed=none)
      if read
        text "Read on Jan 5, 2026 at 4:32 PM" role="status" font-size="ui.text-xs" font-family=uiFontFamily(uiFont) data-rightui-font="body"
      text "Error details popover" font-weight=uiWeights.semibold font-family=uiFontFamily(uiFont) data-rightui-font="body"
      BubbleOptions(id="bubble-popover-request", body="Run the local command.", align="end", variant="default", collapsible=false, reactions=false, reduced=reduced, initialCollapsed=false, previewLength=180)
      BubbleFrame(id="bubble-popover-message", align="start", variant="destructive")
        BubbleContent(id="bubble-popover-content")
          text "Failed to run the command." font-size="ui.text-sm" line-height="ui.leading-code" font-family=uiFontFamily(uiFont) data-rightui-font="body"
        BubbleReactions(id="bubble-popover-actions", label="Error actions", side="bottom", align="end", interactive=true)
          BubblePopoverAction(id="bubble-error-details", label="Show error details", reduced=reduced)
            text "Command failed with exit code 1" role="heading" aria-level=3 font-size="ui.text-sm" font-weight=uiWeights.semibold font-family=uiFontFamily(uiFont) data-rightui-font="body"
            text "ENOENT: no such file or directory, open pnpm-lock.yaml" font-size="ui.text-sm" color="ui.muted-foreground" overflow-wrap="break-word" font-family=uiFontFamily(uiFont) data-rightui-font="body"
      text "Show more / show less" font-weight=uiWeights.semibold font-family=uiFontFamily(uiFont) data-rightui-font="body"
      BubbleOptions(id="content-bubble-in", body="Here is the session brief.\nPlease check the spaces and lighting before our appointment.\n\nKeep keyboard focus visible in the dialog, menu and drawer. Reuse the shared RightUI tokens so the other themes can choose their own focus treatment.\n\nCheck the full message before preparing the final selection.", align="start", variant="muted", collapsible=true, initialCollapsed=true, reduced=reduced, reactions=true, previewLength=180)

````

## API Reference

| Property | Type |
| --- | --- |
| BubbleGroup.id | string |
| BubbleGroup.label | string |
| BubbleContent.id | string |
| BubbleButton.id | string |
| BubbleButton.label | string |
| BubbleButton.align | string |
| BubbleButton.variant | string |
| BubbleButton.press | action |
| BubbleLink.id | string |
| BubbleLink.label | string |
| BubbleLink.href | string |
| BubbleLink.align | string |
| BubbleLink.variant | string |
| BubbleReactions.id | string |
| BubbleReactions.label | string |
| BubbleReactions.side | string |
| BubbleReactions.align | string |
| BubbleReactions.interactive | bool |
| BubbleAction.id | string |
| BubbleAction.label | string |
| BubbleAction.icon | string |
| BubbleAction.pressed | option<bool> |
| BubbleAction.press | action |
| BubblePopoverAction.id | string |
| BubblePopoverAction.label | string |
| BubblePopoverAction.reduced | bool |
| BubbleFrame.id | string |
| BubbleFrame.align | string |
| BubbleFrame.variant | string |
| Bubble.id | string |
| Bubble.body | string |
| Bubble.align | string |
| Bubble.variant | string |
| Bubble.collapsible | bool |
| BubbleOptions.id | string |
| BubbleOptions.body | string |
| BubbleOptions.align | string |
| BubbleOptions.variant | string |
| BubbleOptions.collapsible | bool |
| BubbleOptions.reactions | bool |
| BubbleOptions.reduced | bool |
| BubbleOptions.initialCollapsed | bool |
| BubbleOptions.previewLength | number |

## Source

File: packages/ui/conversation.contract

```contract
use FontWeights from "./typography-context.contract"
use uiFontFamily from "./typography-context.contract"
use Control from "./styles.contract"
use AttachmentFrame, AttachmentMedia, AttachmentContent, AttachmentTitle, AttachmentDescription, AttachmentActions, AttachmentAction, AttachmentTrigger, AttachmentPreview from "./attachment-parts.contract"
use BubbleFrame from "./conversation-parts.contract"
use BubbleReactions from "./bubble-parts.contract"
use Avatar from "./display.contract"

component Attachment
  props
    id: string
    name: string
    metadata: string
    content: string
    status: string
    remove: action
  view
    AttachmentOptions(id=id, name=name, metadata=metadata, content=content, status=status, remove=remove, size="default", orientation="horizontal", imageSource="", cardWidth="", previewHref="", reduced=true, copyable=false, copyValue="")

component AttachmentOptions
  props
    id: string
    name: string
    metadata: string
    content: string
    status: string
    remove: action
    size: string
    orientation: string
    imageSource: string
    cardWidth: string
    previewHref: string
    reduced: bool
    copyable: bool
    copyValue: string
  inject
    uiFont: string
  state preview = false
  state copied = false
  action toggle
    preview = not preview
  action dismiss
    preview = false
    focus(id + "-preview")
  action copy
    copyText(copyValue == "" ? content : copyValue)
    copied = true
  view
    AttachmentFrame(id=id, status=status, size=size, orientation=orientation, cardWidth=cardWidth)
      AttachmentMedia(name=name, source=imageSource, status=status, size=size, orientation=orientation, reduced=reduced)
      AttachmentContent()
        AttachmentTitle(name=name, status=status, size=size, reduced=reduced)
        if metadata != ""
          AttachmentDescription(text=metadata, status=status)
      AttachmentActions(orientation=orientation)
        if copyable and (content != "" or copyValue != "")
          AttachmentAction(id=id + "-copy", label=(copied ? "Copied " : copyValue == "" ? "Copy " : "Copy link to ") + name, icon="copy", press=copy)
        AttachmentAction(id=id + "-remove", label="Remove " + name, icon="remove", press=remove)
      AttachmentTrigger(id=id + "-preview", label=(previewHref == "" ? "Preview " + name : "Open " + name + " (opens in a new tab)"), disabled=(status != "done"), expanded=preview, controls=id + "-dialog", href=(status == "done" ? previewHref : ""), press=toggle)
    if copied
      text ("Copied " + name) role="status" font-size="ui.text-xs" color="ui.muted-foreground" font-family=uiFontFamily(uiFont) data-rightui-font="body"
    AttachmentPreview(id=id + "-dialog", open=preview, name=name, metadata=metadata, content=content, contentId=id + "-content", imageSource=imageSource, reduced=reduced, dismiss=dismiss)

component Bubble
  props
    id: string
    body: string
    align: string
    variant: string
    collapsible: bool
  view
    BubbleOptions(id=id, body=body, align=align, variant=variant, collapsible=collapsible, reactions=true, reduced=true, initialCollapsed=false, previewLength=180)

component BubbleOptions
  props
    id: string
    body: string
    align: string
    variant: string
    collapsible: bool
    reactions: bool
    reduced: bool
    initialCollapsed: bool
    previewLength: number
  inject
    uiWeights: FontWeights
    uiFont: string
  state bubbleCollapsed: bool = initialCollapsed
  state bubbleReacted: bool = false
  derive shownBody = collapsible and bubbleCollapsed ? body.slice(0, previewLength) + (body.length > previewLength ? "…" : "") : body
  action toggle
    bubbleCollapsed = not bubbleCollapsed
  action react
    bubbleReacted = not bubbleReacted
  view
    BubbleFrame(id=id, align=align, variant=variant)
      column gap="ui.space-6" min-width="0px"
        text shownBody id=(id + "-body") testId=(id + "-body") font-size="ui.text-sm" line-height="ui.leading-code" white-space="pre-wrap" overflow-wrap="break-word" font-family=uiFontFamily(uiFont) data-rightui-font="body"
        if collapsible
          button id=(id + "-collapse") testId=(id + "-collapse") class=Control font-weight=uiWeights.medium press=toggle aria-expanded=(not bubbleCollapsed) aria-controls=(id + "-body") display="flex" align-items="center" gap="ui.space-4" padding="0px" min-height="ui.space-24" border="none" background-color="transparent" color="inherit" align-self="flex-start"
            text (bubbleCollapsed ? "Show more" : "Show less") font-size="ui.text-xs" font-family=uiFontFamily(uiFont) data-rightui-font="body"
            svg width="ui.space-14" height="ui.space-14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="ui.stroke-standard" rotate=(bubbleCollapsed ? "0deg" : "180deg") transition=(reduced ? "none" : "rotate ui.duration-fast ui.easing") aria-hidden=true
              path d="m6 9 6 6 6-6"
      if reactions
        BubbleReactions(id=id + "-reactions", label="Message reactions", side="bottom", align="end", interactive=true)
          button id=(id + "-reaction") testId=(id + "-reaction") class=Control font-weight=uiWeights.medium press=react aria-pressed=bubbleReacted aria-label="Helpful reaction" min-height="ui.space-24" padding="ui.space-2 ui.space-8" border="none" border-radius="ui.radius-full" background-color="transparent" color="ui.foreground"
            text (bubbleReacted ? "Helpful · 1" : "Helpful") font-size="ui.text-xs" font-family=uiFontFamily(uiFont) data-rightui-font="body"

component Marker
  props
    id: string
    label: string
    variant: string
  inject
    uiFont: string
  view
    row id=id testId=id gap="ui.space-8" align-items="center" min-height="ui.space-16" padding-bottom=(variant == "border" ? "ui.space-8" : "0px") border-bottom-width=(variant == "border" ? "ui.border-width" : "0px") border-bottom-style="solid" border-bottom-color="ui.border"
      if variant == "separator"
        view flex=1 height="ui.border-width" background-color="ui.border" aria-hidden=true
      text label font-size="ui.text-sm" color="ui.muted-foreground" overflow-wrap="break-word" font-family=uiFontFamily(uiFont) data-rightui-font="body"
      if variant == "separator"
        view flex=1 height="ui.border-width" background-color="ui.border" aria-hidden=true

component Message
  props
    id: string
    author: string
    initials: string
    time: string
    align: string
  slot
  view
    MessageRow(id=id, align=align)
      MessageAvatar()
        Avatar(id=id + "-avatar", src="", name=author, fallback=initials)
      MessageBody(align=align)
        if author != ""
          MessageHeader(label=author)
        children
        if time != ""
          MessageMeta(label=time, align=align)

component MessageGroup
  props
    id: string
  slot
  view
    column id=id testId=id gap="ui.space-8" width="100%" min-width="0px" max-width="100%"
      children

component MessageRow
  props
    id: string
    align: string
  slot
  view
    row id=id testId=id gap="ui.space-8" width="100%" min-width="0px" flex-direction=(align == "end" ? "row-reverse" : "row")
      children

component MessageAvatar
  slot
  view
    view flex-shrink=0 align-self="flex-end" width="ui.avatar-size" min-width="ui.avatar-size" display="flex" align-items="center" justify-content="center"
      children

component MessageBody
  props
    align: string
  slot
  view
    column gap="ui.space-10" flex=1 min-width="0px" align-items=(align == "end" ? "flex-end" : "flex-start") overflow-wrap="break-word"
      children

component MessageHeader
  props
    label: string
  inject
    uiWeights: FontWeights
    uiFont: string
  slot
  view
    row gap="ui.space-8" align-items="center" max-width="100%" min-width="0px" padding="0px ui.space-12"
      if label != ""
        text label font-size="ui.text-xs" font-weight=uiWeights.medium color="ui.muted-foreground" font-family=uiFontFamily(uiFont) data-rightui-font="body"
      children

component MessageMeta
  props
    label: string
    align: string
  inject
    uiFont: string
  slot
  view
    row gap="ui.space-8" align-items="center" justify-content=(align == "end" ? "flex-end" : "flex-start") align-self=(align == "end" ? "flex-end" : "flex-start") flex-wrap="wrap" max-width="100%" min-width="0px" padding="0px ui.space-12"
      if label != ""
        text label font-size="ui.text-xs" color="ui.muted-foreground" font-family=uiFontFamily(uiFont) data-rightui-font="body"
      children

keyframes uiTypingWave
  from translate="0px 0px"
  25% translate="0px -4px"
  50% translate="0px 0px"
  to translate="0px 0px"

component MessageTyping
  props
    id: string
    label: string
    reduced: bool
  inject
    uiFont: string
  view
    row id=id testId=id role="status" aria-label=label align-items="center" gap="ui.space-8" color="ui.muted-foreground"
      row aria-hidden=true gap="ui.space-4" align-items="center" height="ui.space-16"
        for dot in [0, 1, 2] key=dot
          view testId=(id + "-dot-" + dot.toString()) width="ui.space-4" height="ui.space-4" border-radius="ui.radius-full" background-color="currentColor" animation=(reduced ? "none" : ("uiTypingWave 1s ease-in-out " + (dot * 0.15).toString() + "s infinite"))
      text label font-size="ui.text-xs" font-family=uiFontFamily(uiFont) data-rightui-font="body"

```
