Components
Chat Widget
Built on Base UIA chat that opens from a button in the corner, for an assistant or for support.
Your page
Installation
npx nook-ui@latest add chat-widgetPrompt
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 Widget" component to this project, exactly as Nook ships it.
A chat that opens from a button in the corner, for an assistant or for support.
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-widget`. It writes `components/ui/chat-widget.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-widget.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
"use client";
import * as React from "react";
import { ChatWidget, type ChatWidgetMessage } from "@/components/ui/chat-widget";
const ANSWERS: Record<string, string> = {
default: "You can change that in Settings, under Workspace. Want me to take you there?",
"How do I invite my team?": "Open Settings, choose Members, then press Invite. Each person gets an email with a link.",
"Where are my invoices?": "Invoices are under Settings, Billing. You can download each one as a PDF.",
};
export default function ChatWidgetDefault() {
const [messages, setMessages] = React.useState<ChatWidgetMessage[]>([]);
const [pending, setPending] = React.useState(false);
const send = (text: string) => {
setMessages((list) => [...list, { id: `u${list.length}`, role: "user", content: text }]);
setPending(true);
setTimeout(() => {
setMessages((list) => [...list, { id: `a${list.length}`, role: "assistant", content: ANSWERS[text] ?? ANSWERS.default }]);
setPending(false);
}, 900);
};
return (
<div className="relative flex h-24 w-full items-center justify-center rounded-lg border border-dashed border-border text-sm text-muted-foreground">
Your page
<ChatWidget
className="absolute right-3 bottom-3"
title="Nook assistant"
description="Answers from the help center"
launcherLabel="Ask the assistant"
suggestions={["How do I invite my team?", "Where are my invoices?"]}
messages={messages}
pending={pending}
onSend={send}
/>
</div>
);
}
```
API
- `ChatWidget`: The launcher and the panel. You keep the messages and answer in `onSend`.
- `messages` (`{ id; role: "user" | "assistant"; content }[]`): The conversation so far.
- `onSend` (`(text: string) => void`): Called with what the person wrote or picked.
- `pending` (`boolean`): Shows the typing indicator and holds back sending.
- `title, description` (`string`): The panel header.
- `suggestions` (`string[]`): Questions offered while the conversation is empty.
- `open, defaultOpen, onOpenChange` (`boolean, boolean, (open) => void`): Control whether it is open.
- `ChatComposer`: The message field on its own, for a full-page chat.
- `onSend` (`(text: string) => void`): Called with the trimmed text.
- `busy` (`boolean`): Holds back sending.
- `actions` (`ReactNode`): Extra controls before the send button.
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 button opens a named panel and focus moves into it; Escape closes it and returns focus. New answers are announced. Enter sends and Shift Enter starts a new line.
Done when the component renders like the example in light and dark mode and the project type-checks.Usage
"use client";
import * as React from "react";
import { ChatWidget, type ChatWidgetMessage } from "@/components/ui/chat-widget";
const ANSWERS: Record<string, string> = {
default: "You can change that in Settings, under Workspace. Want me to take you there?",
"How do I invite my team?": "Open Settings, choose Members, then press Invite. Each person gets an email with a link.",
"Where are my invoices?": "Invoices are under Settings, Billing. You can download each one as a PDF.",
};
export default function ChatWidgetDefault() {
const [messages, setMessages] = React.useState<ChatWidgetMessage[]>([]);
const [pending, setPending] = React.useState(false);
const send = (text: string) => {
setMessages((list) => [...list, { id: `u${list.length}`, role: "user", content: text }]);
setPending(true);
setTimeout(() => {
setMessages((list) => [...list, { id: `a${list.length}`, role: "assistant", content: ANSWERS[text] ?? ANSWERS.default }]);
setPending(false);
}, 900);
};
return (
<div className="relative flex h-24 w-full items-center justify-center rounded-lg border border-dashed border-border text-sm text-muted-foreground">
Your page
<ChatWidget
className="absolute right-3 bottom-3"
title="Nook assistant"
description="Answers from the help center"
launcherLabel="Ask the assistant"
suggestions={["How do I invite my team?", "Where are my invoices?"]}
messages={messages}
pending={pending}
onSend={send}
/>
</div>
);
}Examples
Already open
Waiting for a reply
First question
Answer failed
Props
ChatWidget
The launcher and the panel. You keep the messages and answer in `onSend`.
| Prop | Type | Default | Description |
|---|---|---|---|
| messages | { id; role: "user" | "assistant"; content }[] | – | The conversation so far. |
| onSend | (text: string) => void | – | Called with what the person wrote or picked. |
| pending | boolean | – | Shows the typing indicator and holds back sending. |
| title, description | string | – | The panel header. |
| suggestions | string[] | – | Questions offered while the conversation is empty. |
| open, defaultOpen, onOpenChange | boolean, boolean, (open) => void | – | Control whether it is open. |
ChatComposer
The message field on its own, for a full-page chat.
| Prop | Type | Default | Description |
|---|---|---|---|
| onSend | (text: string) => void | – | Called with the trimmed text. |
| busy | boolean | – | Holds back sending. |
| actions | ReactNode | – | Extra controls before the send button. |
Accessibility
The button opens a named panel and focus moves into it; Escape closes it and returns focus. New answers are announced. Enter sends and Shift Enter starts a new line.
Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.