> ## Documentation Index
> Fetch the complete documentation index at: https://docs.devreadykit.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Chat

> A chat component for displaying messages and handling chat interactions

export const ChatCustomStylingPreview = () => <iframe src="https://kerny-custom.vercel.app/preview/ChatCustomStylingExample" frameBorder="0" width="100%" height="460"></iframe>;

export const ChatFileUploadPreview = () => <iframe src="https://kerny-custom.vercel.app/preview/ChatFileUploadExample" frameBorder="0" width="100%" height="500"></iframe>;

export const ChatSimpleInterfacePreview = () => <iframe src="https://kerny-custom.vercel.app/preview/ChatSimpleInterface" frameBorder="0" width="100%" height="500"></iframe>;

export const ChatFileMessagesPreview = () => <iframe src="https://kerny-custom.vercel.app/preview/ChatFileMessages" frameBorder="0" width="100%" height="600"></iframe>;

export const ChatImageMessagesPreview = () => <iframe src="https://kerny-custom.vercel.app/preview/ChatImageMessages" frameBorder="0" width="100%" height="460"></iframe>;

export const ChatTextMessagesPreview = () => <iframe src="https://kerny-custom.vercel.app/preview/ChatTextMessages" frameBorder="0" width="100%" height="460"></iframe>;

export const ChatBasicExamplePreview = () => <iframe src="https://kerny-custom.vercel.app/preview/ChatBasicExample" frameBorder="0" width="100%" height="500"></iframe>;

## Overview

The Chat component provides a complete chat interface with message display, input handling, and various message types.

## Basic Usage

<Tabs>
  <Tab title="Code">
    ```tsx theme={null}
    import { Chat } from '@peppermint-design/devreadykit-custom';

    export default function App() {
      const [messages, setMessages] = useState([]);

      return (
        <Chat
          messages={messages}
          onSendMessage={(message) => {
            setMessages(prev => [...prev, message]);
          }}
        />
      );
    }
    ```
  </Tab>

  <Tab title="Preview">
    <ChatBasicExamplePreview />
  </Tab>
</Tabs>

## Message Types

### Text Messages

<Tabs>
  <Tab title="Code">
    ```tsx theme={null}
    const messages = [
      {
        id: 1,
        type: 'text',
        content: 'Hello! How are you?',
        sender: 'user',
        timestamp: new Date()
      },
      {
        id: 2,
        type: 'text',
        content: 'I\'m doing great, thanks for asking!',
        sender: 'bot',
        timestamp: new Date()
      }
    ];
    ```
  </Tab>

  <Tab title="Preview">
    <ChatTextMessagesPreview />
  </Tab>
</Tabs>

### File Messages

<Tabs>
  <Tab title="Code">
    ```tsx theme={null}
    const messages = [
      {
        id: 1,
        type: 'file',
        content: {
          name: 'document.pdf',
          size: '2.5 MB',
          url: 'https://example.com/document.pdf'
        },
        sender: 'user',
        timestamp: new Date()
      }
    ];
    ```
  </Tab>

  <Tab title="Preview">
    <ChatFileMessagesPreview />
  </Tab>
</Tabs>

## Props

| Prop             | Type                         | Default               | Description             |
| :--------------- | :--------------------------- | :-------------------- | :---------------------- |
| messages         | `Message[]`                  | `[]`                  | Array of messages       |
| onSendMessage    | `(message: Message) => void` | —                     | Send message handler    |
| placeholder      | `string`                     | `"Type a message..."` | Input placeholder       |
| disabled         | `boolean`                    | `false`               | Disable chat input      |
| className        | `string`                     | —                     | Additional CSS classes  |
| showTimestamps   | `boolean`                    | `true`                | Show message timestamps |
| allowFileUpload  | `boolean`                    | `true`                | Allow file uploads      |
| maxFileSize      | `number`                     | `10485760`            | Max file size in bytes  |
| allowedFileTypes | `string[]`                   | `[]`                  | Allowed file types      |

## Examples

### Simple Chat Interface

<Tabs>
  <Tab title="Code">
    ```tsx theme={null}
    function SimpleChat() {
      const [messages, setMessages] = useState([
        {
          id: 1,
          type: 'text',
          content: 'Welcome to the chat!',
          sender: 'bot',
          timestamp: new Date()
        }
      ]);

      const handleSendMessage = (message) => {
        const newMessage = {
          id: Date.now(),
          ...message,
          timestamp: new Date()
        };
        setMessages(prev => [...prev, newMessage]);
      };

      return (
        <div className="h-96 border rounded">
          <Chat
            messages={messages}
            onSendMessage={handleSendMessage}
            placeholder="Type your message..."
          />
        </div>
      );
    }
    ```
  </Tab>

  <Tab title="Preview">
    <ChatSimpleInterfacePreview />
  </Tab>
</Tabs>
