Message Bubble

Chat bubbles with tones, grouping, avatars and show-more content.

Animated Surfaces

message-bubble.tsx
"use client";

import {
  MessageBubble,
  MessageBubbleContent,
  MessageBubbleGroup,
} from "@/components/agents/message-bubble";

export function MessageBubbleUsage() {
  return (
    <MessageBubbleGroup spacing="default">
      <MessageBubble align="end" variant="solid">
        <MessageBubbleContent>
          Can you summarize the release notes?
        </MessageBubbleContent>
      </MessageBubble>

      <MessageBubble align="start" variant="soft">
        <MessageBubbleContent>
          The release improves streaming, navigation, and recovery states.
        </MessageBubbleContent>
      </MessageBubble>
    </MessageBubbleGroup>
  );
}

With Avatars

message-bubble.tsx
"use client";

import { Bot, RotateCcw, User } from "lucide-react";
import { AnimatePresence } from "motion/react";
import { useCallback, useEffect, useRef, useState } from "react";
import {
  MessageBubble,
  MessageBubbleContent,
} from "@/components/agents/message-bubble";
import {
  Message,
  MessageAvatar,
  MessageContent,
  MessageFooter,
  MessageGroup,
  MessageHeader,
} from "@/components/agents/message";
import { StreamingResponse } from "@/components/agents/streaming-response";

export function MessageBubbleAvatarsPreview() {
  const timer = useRef<number | undefined>(undefined);
  const [run, setRun] = useState(0);
  const [step, setStep] = useState(0);

  const replay = useCallback(() => {
    if (timer.current) window.clearTimeout(timer.current);
    setStep(0);
    setRun((value) => value + 1);
  }, []);

  useEffect(() => {
    if (step >= 2) return;
    timer.current = window.setTimeout(
      () => setStep((value) => value + 1),
      step === 0 ? 650 : 900,
    );
    return () => {
      if (timer.current) window.clearTimeout(timer.current);
    };
  }, [step]);

  return (
    <div className="flex h-[410px] w-full max-w-xl flex-col justify-center px-3">
      <MessageGroup key={run} spacing="default">
        <Message from="user">
          <MessageAvatar className="bg-muted text-foreground">
            <User />
          </MessageAvatar>
          <MessageContent>
            <MessageHeader>
              <span className="font-medium text-foreground/70">You</span>
              <span>Now</span>
            </MessageHeader>
            <MessageBubble variant="solid">
              <MessageBubbleContent>
                Can you turn these notes into a launch update?
              </MessageBubbleContent>
            </MessageBubble>
            <MessageFooter>Delivered</MessageFooter>
          </MessageContent>
        </Message>

        <AnimatePresence mode="popLayout">
          {step >= 1 ? (
            <Message key="draft" from="assistant">
              <MessageAvatar>
                <Bot />
              </MessageAvatar>
              <MessageContent>
                <MessageHeader>
                  <span className="font-medium text-foreground/70">Assistant</span>
                  <span>Just now</span>
                </MessageHeader>
                <MessageBubble variant="soft">
                  <MessageBubbleContent>
                    <StreamingResponse status="complete" showActions={false}>
                      Absolutely. I’ll keep it concise and lead with what changed.
                    </StreamingResponse>
                  </MessageBubbleContent>
                </MessageBubble>
              </MessageContent>
            </Message>
          ) : null}

          {step >= 2 ? (
            <Message key="follow-up" from="assistant">
              <MessageAvatar placeholder />
              <MessageContent>
                <MessageBubble variant="soft">
                  <MessageBubbleContent>
                    <StreamingResponse status="complete" showActions={false}>
                      Do you want the tone to feel more technical or more customer-facing?
                    </StreamingResponse>
                  </MessageBubbleContent>
                </MessageBubble>
              </MessageContent>
            </Message>
          ) : null}
        </AnimatePresence>
      </MessageGroup>

      <div className="flex h-11 items-end justify-center">
        <button
          type="button"
          onClick={replay}
          className="inline-flex h-8 items-center gap-1.5 rounded-full border border-border px-3 text-xs font-medium text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring"
        >
          <RotateCcw className="size-3.5" />
          Replay
        </button>
      </div>
    </div>
  );
}

Show More

message-bubble.tsx
"use client";

import { Bot } from "lucide-react";
import {
  MessageBubble,
  MessageBubbleCollapsible,
  MessageBubbleContent,
} from "@/components/agents/message-bubble";
import {
  Message,
  MessageAvatar,
  MessageContent,
  MessageHeader,
} from "@/components/agents/message";
import { StreamingResponse } from "@/components/agents/streaming-response";

export function MessageBubbleCollapsiblePreview() {
  return (
    <div className="flex h-[410px] w-full max-w-xl items-start px-3 pt-14">
      <Message from="assistant">
        <MessageAvatar>
          <Bot />
        </MessageAvatar>
        <MessageContent>
          <MessageHeader>
            <span className="font-medium text-foreground/70">Assistant</span>
            <span>Summary</span>
          </MessageHeader>
          <MessageBubble variant="soft" animateIn={false}>
            <MessageBubbleContent className="max-w-[90%]">
              <StreamingResponse status="complete" showActions={false}>
                <MessageBubbleCollapsible collapsedLines={4}>
                  <p>
                    The release is ready for a focused rollout. The main conversation flow,
                    keyboard navigation, error recovery, and reduced-motion behavior are all
                    covered.
                  </p>
                  <p>
                    I would keep advanced workflow controls out of this version. They add
                    configuration without improving the first-run experience, and the usage
                    data from this release will give us a better basis for those decisions.
                  </p>
                  <p>
                    Before publishing, run the accessibility suite once more and verify the
                    streaming behavior with a long response on a smaller viewport.
                  </p>
                </MessageBubbleCollapsible>
              </StreamingResponse>
            </MessageBubbleContent>
          </MessageBubble>
        </MessageContent>
      </Message>
    </div>
  );
}

API Reference

MessageBubble

variant?
"solid" | "soft" | "tint" | "outline" | "ghost" | "danger"

Fill and border style of the bubble. Default: "soft"

Defaultsoft
align?
"end" | "start"

Defaults to the surrounding Message alignment when omitted.

animateIn?
boolean

Plays the bubble entrance once when this component mounts.

Defaultfalse
labels?
Partial<{ showMore: string; showLess: string; }>

Override any built-in string.

className?
string

Classes merged onto the root element.

MessageBubbleContent

render?
ReactElement<unknown, string | JSXElementConstructor<any>>

Replaces the content element while preserving bubble styling.

className?
string

Classes merged onto the root element.

MessageBubbleGroup

spacing?
"compact" | "default"

Gap between bubbles. Default: "compact"

Defaultcompact
className?
string

Classes merged onto the root element.

MessageBubbleCollapsible

open?
boolean

Whether the full text shows, for controlled use.

defaultOpen?
boolean

Whether the full text shows at first when uncontrolled. Default: false

Defaultfalse
onOpenChange?
((open: boolean) => void)

Called with the new state when the text expands or collapses.

collapsedLines?
2 | 6 | 3 | 4 | 5

Lines shown while collapsed. Default: 4

Default4
moreLabel?
ReactNode

Text of the expand button. Default: "Show more"

lessLabel?
ReactNode

Text of the collapse button. Default: "Show less"

contentClassName?
string

Classes merged onto the clamped text wrapper.

triggerClassName?
string

Classes merged onto the show more button.

className?
string

Classes merged onto the root element.

Install

Add it with the shadcn CLI, or copy the source manually.

$ bunx --bun shadcn add @beui/message-bubble