Docs
Chat Message

Chat Message

A customizable message bubble component for chat interfaces with support for user and AI messages.

Hello! What is your name?

Hello! I go by ChatGPT. How are you?

The ChatMessage component provides a styled message bubble with support for markdown content, timestamps, animations, and contextual actions.

Installation

npx shadcn@latest add https://shadcn-chatbot-kit.vercel.app/r/chat-message.json

Usage

import { ChatMessage } from "@/components/ui/chat-message"
 
export function ChatDemo() {
  return (
    <div className="space-y-4">
      <ChatMessage
        role="user"
        content="Hello, how are you?"
        createdAt={new Date()}
        showTimeStamp
      />
      <ChatMessage
        role="assistant"
        content="I'm doing well, thank you for asking!"
        createdAt={new Date()}
        showTimeStamp
      />
    </div>
  )
}

Props

PropTypeDefaultDescription
role"user" | "assistant" | stringRequiredThe role of the message sender
contentstringRequiredThe message content (supports markdown)
createdAtDate-Timestamp for the message
showTimeStampbooleanfalseWhether to show the timestamp
animation"none" | "slide" | "scale" | "fade""scale"Animation style for the message bubble
actionsReactNode-Actions to show on hover (assistant only)
idstringRequiredUnique identifier for the message
attachmentsFile[]-Array of attached files

Examples

Different Animation Styles

Slide animation

Scale animation

Fade animation

No animation

With Actions

Here's a message with actions

With Timestamp

Message with timestamp

Custom Styling

This message will be red

This message will be outlined

Accessibility

  • Messages are properly structured for screen readers
  • Timestamps use semantic HTML
  • Actions are keyboard accessible
  • Color contrast meets WCAG guidelines