Skip to content

Bubble

Holds one turn of a conversation, with a visual weight that tells the reader who is speaking and what kind of message it is.

Which supplier is late on the Padova order?
Lamivo Metalli. The delivery for order 4417 is two days past its date.

Installation

pnpm dlx shadcn@latest add @silkware/bubble

To copy the component by hand, install its dependencies:

pnpm add class-variance-authority cn

Then copy the source into components/ui/bubble.tsx:

components/ui/bubble.tsx
import * as React from "react"import { cva, type VariantProps } from "class-variance-authority"import { cn } from "cn"
function BubbleGroup({ className, ...props }: React.ComponentProps<"div">) {  return (    <div      data-slot="bubble-group"      className={cn("flex min-w-0 flex-col gap-2", className)}      {...props}    />  )}
const bubbleVariants = cva(  "group/bubble relative flex w-fit max-w-[80%] min-w-0 flex-col gap-1 group-data-[align=end]/message:self-end data-[align=end]:self-end data-[variant=ghost]:max-w-full",  {    variants: {      variant: {        default:          "*:data-[slot=bubble-content]:bg-primary *:data-[slot=bubble-content]:text-primary-foreground [&>[data-slot=bubble-content]:is(button,a):hover]:bg-primary/80",        secondary:          "*:data-[slot=bubble-content]:bg-secondary *:data-[slot=bubble-content]:text-secondary-foreground [&>[data-slot=bubble-content]:is(button,a):hover]:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)]",        muted:          "*:data-[slot=bubble-content]:bg-muted [&>[data-slot=bubble-content]:is(button,a):hover]:bg-[color-mix(in_oklch,var(--muted),var(--foreground)_5%)]",        tinted:          "*:data-[slot=bubble-content]:bg-[oklch(from_var(--primary)_0.93_calc(c*0.4)_h)] *:data-[slot=bubble-content]:text-foreground dark:*:data-[slot=bubble-content]:bg-[oklch(from_var(--primary)_0.3_calc(c*0.4)_h)] [&>[data-slot=bubble-content]:is(button,a):hover]:bg-[oklch(from_var(--primary)_0.88_calc(c*0.5)_h)] dark:[&>[data-slot=bubble-content]:is(button,a):hover]:bg-[oklch(from_var(--primary)_0.35_calc(c*0.5)_h)]",        outline:          "*:data-[slot=bubble-content]:border-border *:data-[slot=bubble-content]:bg-background [&>[data-slot=bubble-content]:is(button,a):hover]:bg-muted [&>[data-slot=bubble-content]:is(button,a):hover]:text-foreground dark:[&>[data-slot=bubble-content]:is(button,a):hover]:bg-input/30",        ghost:          "border-none *:data-[slot=bubble-content]:rounded-none *:data-[slot=bubble-content]:bg-transparent *:data-[slot=bubble-content]:p-0 [&>[data-slot=bubble-content]:is(button,a):hover]:bg-muted [&>[data-slot=bubble-content]:is(button,a):hover]:text-foreground dark:[&>[data-slot=bubble-content]:is(button,a):hover]:bg-muted/50",        destructive:          "*:data-[slot=bubble-content]:bg-destructive/10 *:data-[slot=bubble-content]:text-destructive dark:*:data-[slot=bubble-content]:bg-destructive/20 [&>[data-slot=bubble-content]:is(button,a):hover]:bg-destructive/20 dark:[&>[data-slot=bubble-content]:is(button,a):hover]:bg-destructive/30",      },    },    defaultVariants: {      variant: "default",    },  })
function Bubble({  variant = "default",  align = "start",  className,  ...props}: React.ComponentProps<"div"> &  VariantProps<typeof bubbleVariants> & {    align?: "start" | "end"  }) {  return (    <div      data-slot="bubble"      data-variant={variant}      data-align={align}      className={cn(bubbleVariants({ variant }), className)}      {...props}    />  )}
function BubbleContent({  className,  render,  children,  ...props}: React.ComponentProps<"div"> & {  render?: (props: React.HTMLAttributes<HTMLElement>) => React.ReactNode}) {  if (render) {    const renderProps = {      ...props,      "data-slot": "bubble-content",      className: cn(        "w-fit max-w-full min-w-0 overflow-hidden rounded-xl border border-transparent px-3 py-2 text-sm leading-relaxed wrap-break-word group-data-[align=end]/bubble:self-end [button]:text-left [button,a]:transition-colors [button,a]:outline-none [button,a]:focus-visible:border-ring [button,a]:focus-visible:ring-3 [button,a]:focus-visible:ring-ring/50",        className      ),      children,    }
    return render(renderProps)  }
  return (    <div      {...props}      data-slot="bubble-content"      className={cn(        "w-fit max-w-full min-w-0 overflow-hidden rounded-xl border border-transparent px-3 py-2 text-sm leading-relaxed wrap-break-word group-data-[align=end]/bubble:self-end [button]:text-left [button,a]:transition-colors [button,a]:outline-none [button,a]:focus-visible:border-ring [button,a]:focus-visible:ring-3 [button,a]:focus-visible:ring-ring/50",        className      )}    >      {children}    </div>  )}
const bubbleReactionsVariants = cva(  "absolute z-10 flex w-fit shrink-0 items-center justify-center gap-1 rounded-full bg-muted px-1.5 py-0.5 text-sm ring-3 ring-card has-[button]:p-0",  {    variants: {      side: {        top: "top-0 -translate-y-3/4",        bottom: "bottom-0 translate-y-3/4",      },      align: {        start: "left-3",        end: "right-3",      },    },    defaultVariants: {      side: "bottom",      align: "end",    },  })
function BubbleReactions({  side = "bottom",  align = "end",  className,  ...props}: React.ComponentProps<"div"> & {  align?: "start" | "end"  side?: "top" | "bottom"}) {  return (    <div      data-slot="bubble-reactions"      data-align={align}      data-side={side}      className={cn(bubbleReactionsVariants({ side, align }), className)}      {...props}    />  )}
export { BubbleGroup, Bubble, BubbleContent, BubbleReactions }

Usage

import {  Bubble,  BubbleContent,  BubbleGroup,  BubbleReactions,} from "@/components/ui/bubble"
<Bubble variant="muted">  <BubbleContent>Lamivo Metalli is two days late on order 4417.</BubbleContent></Bubble>

A bubble is the surface of a message and nothing more. The row around it, with the avatar, the header and the footer, is a Message. Inside a Message the bubble takes its side from the message, so set align on the Message, and set it on the Bubble only when you use a bubble on its own. The patterns that put both in a conversation are Chat and Message.

Examples

Variants

Seven weights. default is the strongest and the colour of the primary action; secondary and muted are neutral tints; tinted is a pale version of the primary colour; outline has an edge and no fill; ghost has neither fill, padding nor width limit; destructive is crimson, for failures.

The default variant
The secondary variant
The muted variant
The tinted variant
The outline variant
The ghost variant
The destructive variant

Alignment

align is start or end. Put the person using the interface at the end and everyone else at the start, in every conversation.

Aligned to the start, the default.
Aligned to the end.

Group

BubbleGroup stacks bubbles from the same sender with a small gap. Set align on each bubble, not on the group.

Send order 4417 to Lamivo Metalli.
Use the 2026 price list.
Sent. They confirm within two working days.

Ghost for the agent

A ghost bubble drops the frame so a long answer reads as text and can use the full width. It is the usual choice for an agent on Agentic OS, with the person's own message in a filled bubble.

Check the open price lists.
Two price lists are still open. The 2026 list waits for Giulia, and the steel list for Marco.

Reactions

BubbleReactions sits on the edge of a bubble for a small mark, such as who has seen or approved it. side is top or bottom and align is start or end. It overlaps the bubble, so leave vertical room between messages. Give it role="img" and an aria-label when it holds only icons.

The price list is ready for review.
I approved it.

BubbleContent takes a render function, so a bubble can be a real button or a. The bubble then gains a hover colour and a focus ring. Use it for quick replies.

Order 4417 is ready. What next?

Accessibility

A plain bubble is text in a div, so it has no keyboard behaviour. The keys below apply to a bubble rendered as a button or a link.

KeyAction
TabMoves focus to the next bubble that is a button or a link.
EnterActivates a bubble rendered as a button or a link.
SpaceActivates a bubble rendered as a button.

The component provides:

  • Text that wraps and breaks long words, so a bubble never forces the page to scroll sideways.
  • A visible focus ring, through focus-visible, on a bubble rendered as a button or a link.
  • Layout only. The bubble sets no role, so what it contains is read as ordinary content in order.

You provide:

  • The speaker. Colour and side are not enough: the sender must also be in the text around the bubble, for example in a MessageHeader, or in the structure of a transcript with a log role such as Message Scroller.
  • role="img" and an aria-label on BubbleReactions that hold icons, such as "Approved by Giulia". Without them the reaction is silent.
  • The right element when a bubble is interactive: pass render with a button or an a, never an onClick on a div.
  • Text for failures in a destructive bubble. The crimson tint is not the message.

Guidelines

When to use

  • For each turn in a chat between people, or between a person and an agent.
  • For quick replies the person can choose, rendered as buttons.
  • For a failed turn, with the destructive variant.

When not to use

  • For a notice about the page, such as a failed sync. Use an Alert.
  • For a short confirmation after an action. Use a Toast.
  • For a card with a title, a body and actions. Use a Card.
  • For a label or a status. Use a Badge.
  • For a line that marks a time or a step in the conversation, such as "Today". Use a Marker.

Content

  • Write the way a colleague would say it: short sentences, the object named, no filler.
  • Keep one idea per bubble, and use a group for several in a row.
  • Use sentence case, and no exclamation marks or emoji.
  • For an agent, say what it did and what it found, not that it was happy to help.

Variants and roles

Choose one pairing and keep it everywhere. In Silkware the person is default or secondary at the end, other people are muted at the start, and an agent is ghost. Use destructive only for a failure.

How many orders wait for me?
Three. The oldest is from Monday.
Do

Give each role one variant and keep it for the whole conversation.

How many orders wait for me?
Three.
The oldest is from Monday.
Approve them today.
Don’t

Don’t use a different variant for each message. The reader cannot tell who said what, and the colour carries no meaning.

Order 4417 was not sent. The price list is out of date.
Do

Use the destructive variant for a failure and say what failed.

Your order was approved.
Don’t

Don’t use the destructive variant for emphasis or for good news. Crimson means something went wrong.

The steel price list is ready.
Do

Label a reaction that is only an icon so it is announced.

The steel price list is ready.
Don’t

Don’t leave an icon reaction without a label. A screen reader reads nothing, and a sighted reader may not know what the mark means.

API reference

Bubble

Renders a <div> that sizes to its content, up to 80% of the row. The ghost variant has no limit. It accepts every prop of a div.

PropTypeDefaultDescription
variant?"default" | "secondary" | "muted" | "tinted" | "outline" | "ghost" | "destructive""default"The visual weight of the bubble.
align?"start" | "end""start"The side of the row the bubble sits on. Inside a Message, the message sets it.
className?stringNoneClasses merged after the variant classes.

BubbleContent

Renders the <div> that holds the text, with the fill, padding and corners. With render it renders your element, such as a button or an a, and passes it the props to spread.

PropTypeDefaultDescription
render?(props: HTMLAttributes<HTMLElement>) => ReactNodeNoneA function that returns the element to render. The element receives the classes, the data slot and the children.
children?ReactNodeNoneThe message.
className?stringNoneClasses merged after the content classes.

BubbleReactions

Renders a <div> that overlaps an edge of the bubble, for marks and quick actions.

PropTypeDefaultDescription
side?"top" | "bottom""bottom"The edge of the bubble it sits on.
align?"start" | "end""end"The end of that edge it sits near.
role?stringNoneSet it to img on a reaction made of icons, with an aria-label.
className?stringNoneClasses merged after the reaction classes.

BubbleGroup

Renders a <div> that stacks bubbles from one sender with a small gap.

PropTypeDefaultDescription
className?stringNoneClasses merged after the layout classes.