Components / AI Chat Interfaces

AI Chat Bubble

A conversational chat bubble component with typing indicator, avatar support, and message timestamps for AI chat interfaces.

Live Preview — ai-chat-bubble-01
U
Can you explain what ShadCN UI is?
10:02 AM
C
Sure! ShadCN UI is a collection of accessible and composable React components built on top of Tailwind CSS, perfect for building modern UIs quickly.
10:03 AM

Installation

Shadcn UI Setup

Add the necessary Shadcn UI primitives.

npm
npx shadcn-ui@latest add avatar card scroll-area

Source Code

ai-chat-bubble-01.tsx
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import { Card, CardContent } from "@/components/ui/card";
import { ScrollArea } from "@/components/ui/scroll-area";
import { cn } from "@/lib/utils";

export default function AIChatBubble01() {
  // Self-contained LLM chat messages
  const messages = [
    {
      id: 1,
      author: "User",
      avatar: "https://i.pravatar.cc/40?img=5",
      text: "Can you explain what ShadCN UI is?",
      timestamp: "10:02 AM",
    },
    {
      id: 2,
      author: "ChatGPT",
      avatar: "https://i.pravatar.cc/40?img=12",
      text: "Sure! ShadCN UI is a collection of accessible and composable React components built on top of Tailwind CSS, perfect for building modern UIs quickly.",
      timestamp: "10:03 AM",
    },
  ];

  return (
    <Card className="border-0 p-12">
      <CardContent className="p-0">
        <ScrollArea className="h-[400px]">
          {messages.map((msg) => (
            <div
              key={msg.id}
              className={cn(
                "flex items-start gap-3 mb-4",
                msg.author === "ChatGPT" ? "flex-row" : "flex-row-reverse"
              )}
            >
              <Avatar>
                <AvatarImage src={msg.avatar} />
                <AvatarFallback>{msg.author[0]}</AvatarFallback>
              </Avatar>
              <div className="flex flex-col">
                {/* Use ShadCN card-like bubbles without custom colors */}
                <Card className="p-2 rounded-lg border border-border max-w-md">
                  <CardContent className="p-0">
                    {msg.text}
                  </CardContent>
                </Card>
                <span className="text-xs text-muted-foreground mt-1 self-end">
                  {msg.timestamp}
                </span>
              </div>
            </div>
          ))}
        </ScrollArea>
      </CardContent>
    </Card>
  );
}

Shadcn Components

Primitives required in your @/components/ui directory.

Component Path
avatar @/components/ui/avatar
card @/components/ui/card
scroll area @/components/ui/scroll-area

Functional Logic

Internal functions used to handle component logic.

Function Parameters
AIChatBubble01() None

Variables

All variable declarations found in this component.

Name Kind Value
messages const [

JSX Tags Usage

Every JSX/HTML tag used in this component, with usage count and source.

Tag Count Type Source
<Avatar> Library @/components/ui/avatar
<AvatarFallback> Library @/components/ui/avatar
<AvatarImage> Library @/components/ui/avatar
<Card> Library @/components/ui/card
<CardContent> Library @/components/ui/card
<ScrollArea> Library @/components/ui/scroll-area
<div> Native Native HTML
<span> Native Native HTML

Related Components

  • AI Chat Input Bar — A modern chat input bar with send button, attachment support, and auto-resize textarea for AI conversation interfaces.
  • AI Chat Window — A full-featured AI chat window with message history, streaming response animation, and conversation management.
  • AI Streaming Text — A typewriter-style streaming text component that simulates token-by-token AI response generation with cursor animation.
  • AI Chat Sidebar — A conversation history sidebar listing previous AI chat sessions with search, date grouping, and active state indicators.
  • AI Model Selector — A dropdown model selector for choosing between AI models (GPT-4, Claude, Gemini) with model info badges and capability indicators.
  • AI Response Actions — An action bar for AI responses with copy, regenerate, thumbs up/down, and share buttons with tooltip labels.