Cameron Kelliher

AI Messages

AI chats 7

About

A scrollable chat message list container that auto-scrolls to the newest message and shows a scroll-to-bottom button when the user scrolls up.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds AI Messages to your project and fits it to your theme.

Code

How AI Messages is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

import { AiMessages } from "@/components/ui/ai-messages";

function MessageBubble({
  role,
  children,
}: {
  role: "user" | "assistant";
  children: React.ReactNode;
}) {
  return (
    <div
      className={
        role === "user"
          ? "ml-auto max-w-[80%] rounded-lg bg-primary px-4 py-2 text-primary-foreground"
          : "mr-auto max-w-[80%] rounded-lg bg-muted px-4 py-2 text-foreground"
      }
    >
      {children}
    </div>
  );
}

export default function AiMessagesDemo() {
  return (
    <div className="h-[500px] w-full max-w-2xl border">
      <AiMessages>
        <MessageBubble role="user">
          Hey, can you explain what useEffect does?
        </MessageBubble>
        <MessageBubble role="assistant">
          Sure! useEffect lets you run side effects in a React component, like
          fetching data or subscribing to events, after the component renders.
        </MessageBubble>
        <MessageBubble role="user">Does it run on every render?</MessageBubble>
        <MessageBubble role="assistant">
          By default yes, but you can control that with a dependency array —
          pass an empty array to run it only once, or specific values to run it
          when they change.
        </MessageBubble>
        <MessageBubble role="user">Got it, thanks!</MessageBubble>
        <MessageBubble role="assistant">
          You're welcome! Happy coding 🎉
        </MessageBubble>
      </AiMessages>
    </div>
  );
}

Dependencies

More by Cameron Kelliher

View all
  • AI Chain of Thought

    AI Chain of Thought

    111
  • Helix Loader

    Helix Loader

    94
  • AI Streaming Text

    AI Streaming Text

    50
  • AI Tool Call

    AI Tool Call

    45
  • Signal Bars Loader

    Signal Bars Loader

    41
  • Glitch Text Loader

    Glitch Text Loader

    41
  • AI Prompt Diff

    AI Prompt Diff

    39
  • AI Routing Indicator

    AI Routing Indicator

    34

More in AI chats

View all
  • AI Actions

    AI Actions

    319
  • Agent Chat

    Agent Chat

    17
  • System Message

    System Message

    54
  • Message Thread

    Message Thread

    35
  • Color Picker

    Color Picker

    81
  • AI Task List

    AI Task List

    160
  • Modal Card

    Modal Card

    101
  • Quota Banner

    Quota Banner

    21