Components / AI Chat Interfaces

AI Chat Bubble

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

tsx
"use client";

import React, { useState } from "react";
import { cn } from "@/lib/utils";

interface Message {
  id: string;
  role: "user" | "assistant";
  content: string;
  timestamp: Date;
}

interface AIChatBubbleProps {
  message: Message;
  isTyping?: boolean;
}

export default function AIChatBubble({ message, isTyping = false }: AIChatBubbleProps) {
  const isAI = message.role === "assistant";

  return (
    <div className={cn("flex gap-3 mb-4", isAI ? "flex-row" : "flex-row-reverse")}>
      <div className={cn(
        "h-8 w-8 rounded-full flex items-center justify-center text-xs font-bold shrink-0",
        isAI ? "bg-gradient-to-br from-violet-500 to-purple-600 text-white" : "bg-zinc-200 dark:bg-zinc-700 text-zinc-700 dark:text-zinc-200"
      )}>
        {isAI ? "AI" : "U"}
      </div>
      <div className={cn(
        "max-w-[75%] rounded-2xl px-4 py-2.5 text-sm leading-relaxed",
        isAI
          ? "bg-zinc-100 dark:bg-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-tl-sm"
          : "bg-blue-600 text-white rounded-tr-sm"
      )}>
        {isTyping ? (
          <div className="flex items-center gap-1 py-1">
            <span className="h-2 w-2 rounded-full bg-zinc-400 animate-bounce" style={{ animationDelay: "0ms" }} />
            <span className="h-2 w-2 rounded-full bg-zinc-400 animate-bounce" style={{ animationDelay: "150ms" }} />
            <span className="h-2 w-2 rounded-full bg-zinc-400 animate-bounce" style={{ animationDelay: "300ms" }} />
          </div>
        ) : (
          <>
            <p>{message.content}</p>
            <p className={cn(
              "text-[10px] mt-1 opacity-60",
              isAI ? "text-zinc-500" : "text-blue-100"
            )}>
              {message.timestamp.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" })}
            </p>
          </>
        )}
      </div>
    </div>
  );
}

Installation

Dependencies

  • react
                            npm install react
                        

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.