# Mini chat

A picture in picture chat over the app: fling it to a corner, move it from the keyboard, or shrink it to a pill that follows the answer.

> chatcn Pro: needs a Pro license (https://chatcn.dev/pro). Install from the `@chatcn-pro` registry with your license token; setup at https://chatcn.dev/docs/chatcn-pro.

Example: Mini chat. Floating over a shipment page, it shrinks to a pill that follows the answer, moves to another corner and opens again. Preview: https://chatcn.dev/preview/mini-chat-demo

## Installation

```bash
npx shadcn@latest add @chatcn-pro/mini-chat
```

## Usage

```tsx
import { MiniChat } from "@/components/ui/chatcn/pro/mini-chat"

<MiniChat
  title="Harbourline assistant"
  messages={messages}
  status={status}
  onSend={send}
  onClose={() => setShown(false)}
/>
```

It floats over the app so the reader can keep working while they ask. Drag it by its bar and let go: it travels to the nearest corner on the kit's spring, and a quick flick throws it to the corner it was heading for, measured from the pointer's velocity. From the keyboard, focus the bar and use the arrow keys. Shrink it and it becomes a pill that shows the last line of the answer as it arrives (or Answering before the first words), so the reader can follow along without the window in the way; click the pill to open it again. Corners follow the reading direction. `placement="contained"` keeps it inside its parent.

## Examples

### States

Example: States. Empty, answered in another corner, a pill while answering, a pill with the last line, and a failed answer. Preview: https://chatcn.dev/preview/mini-chat-states

## Props

| Prop | Type | Notes |
| --- | --- | --- |
| `messages` | `ChatcnMessage[]` | The thread, in the kit's message contract |
| `status`, `error`, `onStop`, `onRetry` | `"ready" | "submitted" | "streaming" | "error"` | Send becomes Stop while it streams; an error offers Try again |
| `value`, `defaultValue`, `onValueChange` | `string` | The draft, controlled or not |
| `onSend` | `(text) => void` |  |
| `title` | `ReactNode` | On the bar and in the window's name |
| `corner`, `defaultCorner`, `onCornerChange` | `"top-start" | "top-end" | "bottom-start" | "bottom-end"` | Default bottom end |
| `collapsed`, `defaultCollapsed`, `onCollapsedChange` | `boolean` | The pill |
| `onClose` | `() => void` | Shows a close button |
| `placement` | `"fixed" | "contained"` | Over the viewport, or inside the parent |
| `disabled` | `boolean` |  |
| `labels` | `Partial<MiniChatLabels>` | Every string, for translation |

## Keyboard

| Key | Action |
| --- | --- |
| Arrow keys on the bar | Move to the corner in that direction |
| Escape | Shrink to the pill, focus on the pill |
| Enter or Space on the pill | Open the window, focus in the input |
| Enter, Shift Enter | Send, new line |

## Accessibility

- The window is a non modal dialog, so the app behind it stays usable.
- The bar is a button that says it moves the window and how to do it from the keyboard.
- The pill is named by what it opens; its status dot always has the words beside it.
- Shrinking and opening move focus to the pill and back to the input.

## Motion

Moving between corners uses the kit's critically damped spring, so a flick lands without overshoot. While dragging it follows the pointer exactly. Shrinking to the pill animates size and corner radius in 260 ms. Under reduced motion it jumps between corners and sizes.

Source: https://chatcn.dev/docs/components/mini-chat