Search documentation

Search pages, components, blocks, styles and colours.

Get started
Skip to content

Bubble

PreviousNext

Displays conversational content in a message bubble. Supports variants, alignment, grouping, reactions, and collapsible content.

Bubble on iOS

Installation

bunx --bun fabricator-ui@latest add bubble

Usage

import {
  Bubble,
  BubbleContent,
  BubbleGroup,
  BubbleReactions,
} from "@/components/ui/bubble"
import { Text } from "@/components/ui/text"
{VARIANTS.map((variant) => (
  <Bubble key={variant} variant={variant}>
    <BubbleContent>A {variant} bubble, in the chat.</BubbleContent>
  </Bubble>
))}

Composition

  • Bubble
  • BubbleContent
  • BubbleGroup
  • BubbleReactions

Examples

bubble-example.tsx
import { Pressable } from "react-native"
 
import {
  Bubble,
  BubbleContent,
  BubbleGroup,
  BubbleReactions,
} from "@/components/ui/bubble"
import { Text } from "@/components/ui/text"
 
const VARIANTS = [
  "default",
  "secondary",
  "muted",
  "tinted",
  "outline",
  "ghost",
  "destructive",
] as const
 
function BubbleExample() {
  return (
    <ExampleWrapper>
      <Example title="Variants" className="items-stretch">
        {VARIANTS.map((variant) => (
          <Bubble key={variant} variant={variant}>
            <BubbleContent>A {variant} bubble, in the chat.</BubbleContent>
          </Bubble>
        ))}
      </Example>
      <Example title="Alignment" className="items-stretch">
        <Bubble variant="muted" align="start">
          <BubbleContent>Did the build pass?</BubbleContent>
        </Bubble>
        <Bubble align="end">
          <BubbleContent>
            It did, and this reply is long enough to wrap so the bubble's width
            shows.
          </BubbleContent>
        </Bubble>
      </Example>
      <Example title="Group" className="items-stretch">
        <BubbleGroup>
          <Bubble variant="muted">
            <BubbleContent>I checked the registry addresses.</BubbleContent>
          </Bubble>
          <Bubble variant="muted">
            <BubbleContent>They all resolve.</BubbleContent>
          </Bubble>
        </BubbleGroup>
      </Example>
      <Example title="Pressable" className="items-stretch">
        <Bubble variant="tinted" align="end">
          <BubbleContent render={<Pressable onPress={() => {}} />}>
            I forgot my password
          </BubbleContent>
        </Bubble>
        <Bubble variant="outline" align="end">
          <BubbleContent asChild>
            <Pressable onPress={() => {}}>
              <Text>Talk to a person</Text>
            </Pressable>
          </BubbleContent>
        </Bubble>
      </Example>
      <Example title="Reactions" className="items-stretch gap-10 py-10">
        <Bubble variant="muted" align="end">
          <BubbleContent>
            I don't need tests, I know my code works.
          </BubbleContent>
          <BubbleReactions
            align="start"
            role="img"
            aria-label="Reactions: thumbs up"
          >
            <Text>👍</Text>
          </BubbleReactions>
        </Bubble>
        <Bubble variant="muted">
          <BubbleContent>Bold.</BubbleContent>
          <BubbleReactions role="img" aria-label="Reactions: eyes, and 2 more">
            <Text>👀</Text>
            <Text>+2</Text>
          </BubbleReactions>
        </Bubble>
        <Bubble align="end">
          <BubbleContent>Tests passed on the first try.</BubbleContent>
          <BubbleReactions
            side="top"
            align="start"
            role="img"
            aria-label="Reactions: party"
          >
            <Text>🎉</Text>
          </BubbleReactions>
        </Bubble>
        <Bubble>
          <BubbleContent>Reactions sit on the bubble's edge.</BubbleContent>
          <BubbleReactions
            side="bottom"
            align="end"
            role="img"
            aria-label="Reactions: clap"
          >
            <Text>👏</Text>
          </BubbleReactions>
        </Bubble>
      </Example>
    </ExampleWrapper>
  )
}
 
export { BubbleExample }

API reference

PropValues
variantdefault, destructive, ghost, muted, outline, secondary, tinted
sidebottom, top
alignend, start

Props it adds to what it wraps: align, side.

Differences from web

Same. It works as it does on the web, with onPress for onClick.

Accessibility

Text is read as it appears. Give a control with no text an accessibilityLabel.