nook
Browse the docs

Components

Chat

Native

Message bubbles for a conversation, with a typing indicator.

See the prompt
MC
Morning! Did the launch page copy get approved?
Maya, 9:41
Yes, legal signed off last night.
I only changed the pricing line, the rest is yours word for word.
Read 9:43
MC

Installation

npx nook-ui@latest add chat

Prompt

Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.

Short. For assistants that can run commands in your project.

Plain text
Add the Nook "Chat" component to this project, exactly as Nook ships it.

Message bubbles for a conversation, with a typing indicator.

Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add chat`. It writes `components/ui/chat.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/chat.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:

```tsx
import { Avatar, AvatarFallback } from "@/components/ui/avatar";
import { Chat, ChatBubble, ChatContent, ChatMessage, ChatMeta, ChatTyping } from "@/components/ui/chat";

export default function ChatDefault() {
  return (
    <Chat aria-label="Conversation with Maya" className="max-w-md">
      <ChatMessage>
        <Avatar className="size-7 text-xs">
          <AvatarFallback>MC</AvatarFallback>
        </Avatar>
        <ChatContent>
          <ChatBubble>Morning! Did the launch page copy get approved?</ChatBubble>
          <ChatMeta>Maya, 9:41</ChatMeta>
        </ChatContent>
      </ChatMessage>
      <ChatMessage side="end">
        <ChatContent>
          <ChatBubble>Yes, legal signed off last night.</ChatBubble>
          <ChatBubble>I only changed the pricing line, the rest is yours word for word.</ChatBubble>
          <ChatMeta>Read 9:43</ChatMeta>
        </ChatContent>
      </ChatMessage>
      <ChatMessage>
        <Avatar className="size-7 text-xs">
          <AvatarFallback>MC</AvatarFallback>
        </Avatar>
        <ChatContent>
          <ChatTyping label="Maya is typing" />
        </ChatContent>
      </ChatMessage>
    </Chat>
  );
}
```

API
- `Chat`: The conversation.
  - `...props` (`React.HTMLAttributes<HTMLDivElement>`): Everything the native element accepts, such as `id`, `aria-*` and event handlers.
- `ChatMessage`: One turn.
  - `side` (`"start" | "end"`, default "start"): `end` is for the person using the app.
- `ChatContent, ChatBubble, ChatMeta, ChatTyping`: The stack of bubbles, a bubble, the small line under it, and the typing indicator.

Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: The conversation has role=log, so new messages are announced without stealing focus: name it with `aria-label`. Who is speaking comes from the text and the meta line, never from the side or the color alone.

Done when the component renders like the example in light and dark mode and the project type-checks.

Usage

import { Avatar, AvatarFallback } from "@/components/ui/avatar";
import { Chat, ChatBubble, ChatContent, ChatMessage, ChatMeta, ChatTyping } from "@/components/ui/chat";

export default function ChatDefault() {
  return (
    <Chat aria-label="Conversation with Maya" className="max-w-md">
      <ChatMessage>
        <Avatar className="size-7 text-xs">
          <AvatarFallback>MC</AvatarFallback>
        </Avatar>
        <ChatContent>
          <ChatBubble>Morning! Did the launch page copy get approved?</ChatBubble>
          <ChatMeta>Maya, 9:41</ChatMeta>
        </ChatContent>
      </ChatMessage>
      <ChatMessage side="end">
        <ChatContent>
          <ChatBubble>Yes, legal signed off last night.</ChatBubble>
          <ChatBubble>I only changed the pricing line, the rest is yours word for word.</ChatBubble>
          <ChatMeta>Read 9:43</ChatMeta>
        </ChatContent>
      </ChatMessage>
      <ChatMessage>
        <Avatar className="size-7 text-xs">
          <AvatarFallback>MC</AvatarFallback>
        </Avatar>
        <ChatContent>
          <ChatTyping label="Maya is typing" />
        </ChatContent>
      </ChatMessage>
    </Chat>
  );
}

Examples

Replying to a message

Can we move the pricing table above the fold?
Maya, 9:41

Replying to MayaCan we move the pricing table above the fold?

Group chat

NH
Who's joining the review at 3?
Noor, 13:02
DW
Me. I'll bring the new empty states.
Dana, 13:04
Count me in. Can we start with the checkout flow?
You, 13:05

Long message

Hi, I was charged twice for the November plan on the 3rd and again on the 4th, and the second charge shows a different last four digits than my card on file. Can you check what happened and refund the extra one?
You, 10:12
Sorry about that. I found both charges and I'm refunding the second one now.
Support, 10:15

No messages yet

No messages yet. Say hello to Maya to start the conversation.

Waiting for a reply

My export has been stuck at 80% for ten minutes.
Sent 14:02
SU

Message not sent

Can you send me the final invoice before noon?
Not sent. You are offline.

Props

Chat

The conversation.

PropTypeDefaultDescription
...propsReact.HTMLAttributes<HTMLDivElement>–Everything the native element accepts, such as `id`, `aria-*` and event handlers.

ChatMessage

One turn.

PropTypeDefaultDescription
side"start" | "end""start"`end` is for the person using the app.

ChatContent, ChatBubble, ChatMeta, ChatTyping

The stack of bubbles, a bubble, the small line under it, and the typing indicator.

Accessibility

The conversation has role=log, so new messages are announced without stealing focus: name it with `aria-label`. Who is speaking comes from the text and the meta line, never from the side or the color alone.

Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.