Components
Chat
NativeMessage bubbles for a conversation, with a typing indicator.
Installation
npx nook-ui@latest add chatPrompt
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.
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
Group chat
Long message
No messages yet
No messages yet. Say hello to Maya to start the conversation.
Waiting for a reply
Message not sent
Props
Chat
The conversation.
| Prop | Type | Default | Description |
|---|---|---|---|
| ...props | React.HTMLAttributes<HTMLDivElement> | – | Everything the native element accepts, such as `id`, `aria-*` and event handlers. |
ChatMessage
One turn.
| Prop | Type | Default | Description |
|---|---|---|---|
| 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.