

<Demo name="chat/demos/chat" />

## Installation [#installation]

<CodeBlockTabs defaultValue="npm">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="npm">
      npm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="pnpm">
      pnpm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="yarn">
      yarn
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="bun">
      bun
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="npm">
    ```bash
    npx shadcn@latest add @dotui/chat
    ```
  </CodeBlockTab>

  <CodeBlockTab value="pnpm">
    ```bash
    pnpm dlx shadcn@latest add @dotui/chat
    ```
  </CodeBlockTab>

  <CodeBlockTab value="yarn">
    ```bash
    yarn dlx shadcn@latest add @dotui/chat
    ```
  </CodeBlockTab>

  <CodeBlockTab value="bun">
    ```bash
    bun x shadcn@latest add @dotui/chat
    ```
  </CodeBlockTab>
</CodeBlockTabs>

## Usage [#usage]

```tsx
import { Conversation, Message, MessageContent } from "@/ui/chat"
```

```tsx
<Conversation>
  <Message role="user">
    <MessageContent>How do I center a div?</MessageContent>
  </Message>
  <Message role="assistant">
    <MessageContent>Center it with place-items.</MessageContent>
  </Message>
</Conversation>
```

## Anatomy [#anatomy]

`Conversation` is the scroll container for the message list. Each `Message` sets
the role its children style against: `user` renders `MessageContent` as a
contained bubble aligned to the end of the row, `assistant` renders it plain and
full-width. `MessageAvatar` is optional and sits on the sender's side of the row.

```tsx
import { Conversation, Message, MessageAvatar, MessageContent } from "@/ui/chat"
```

```tsx
<Conversation>
  <Message role="assistant">
    <MessageAvatar name="AI" />
    <MessageContent>{/* message body */}</MessageContent>
  </Message>
</Conversation>
```

`PromptInput` is the composer. It renders a form, so `PromptInputSubmit` — or
pressing Enter in the textarea — submits it; Shift+Enter inserts a newline. The
textarea grows with its content, and the shell is the same input group the rest
of your fields use, so it follows their style, radius and density.

```tsx
import {
  PromptInput,
  PromptInputSubmit,
  PromptInputTextarea,
  PromptInputToolbar,
} from "@/ui/chat"
```

```tsx
<PromptInput onSubmit={handleSubmit}>
  <PromptInputTextarea placeholder="Ask anything…" aria-label="Message" />
  <PromptInputToolbar>
    {/* attachments, tools… */}
    <PromptInputSubmit isIconOnly aria-label="Send message">
      <ArrowUpIcon />
    </PromptInputSubmit>
  </PromptInputToolbar>
</PromptInput>
```

## Examples [#examples]

<Examples className="md:grid-cols-2">
  <Example name="chat/demos/basic" title="Basic" />

  <Example name="chat/demos/with-avatars" title="With Avatars" />

  <Example name="chat/demos/prompt-input" title="Prompt Input" />

  <Example name="chat/demos/with-toolbar" title="With Toolbar" />
</Examples>

## API Reference [#api-reference]

### Conversation [#conversation]

<Reference name="conversation" />

### Message [#message]

<Reference name="message" />

### MessageContent [#messagecontent]

<Reference name="message-content" />

### MessageAvatar [#messageavatar]

<Reference name="message-avatar" />

### PromptInput [#promptinput]

<Reference name="prompt-input" />

### PromptInputTextarea [#promptinputtextarea]

<Reference name="prompt-input-textarea" />

### PromptInputToolbar [#promptinputtoolbar]

<Reference name="prompt-input-toolbar" />

### PromptInputSubmit [#promptinputsubmit]

<Reference name="prompt-input-submit" />
