Components
An inbox list and an opened message.
- Maya ChenLegal signed off last night. I only changed the pricing line.
- UnreadBillingInvoice INV-004 for $450.00 is ready to download.
- Arif RahmanThe rounding bug is gone. Can you check staging before noon?
Launch page copy, final
Hi,
Legal signed off last night. I only changed the pricing line.
Thanks,
Maya Chen
Installation
npx nook-ui@latest add mailPrompt
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 "Mail" component to this project, exactly as Nook ships it.
An inbox list and an opened message.
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 mail`. It writes `components/ui/mail.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/mail.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 { Avatar, AvatarFallback } from "@/components/ui/avatar";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { MailItem, MailList, MailMessage } from "@/components/ui/mail";
const MAILS = [
{ id: "1", sender: "Maya Chen", initials: "MC", address: "maya@acme.com", subject: "Launch page copy, final", preview: "Legal signed off last night. I only changed the pricing line.", time: "9:41", unread: true, label: "Launch" },
{ id: "2", sender: "Billing", initials: "B", address: "billing@acme.com", subject: "Your invoice for November", preview: "Invoice INV-004 for $450.00 is ready to download.", time: "8:02", unread: true },
{ id: "3", sender: "Arif Rahman", initials: "AR", address: "arif@acme.com", subject: "Checkout total is fixed", preview: "The rounding bug is gone. Can you check staging before noon?", time: "Yesterday", unread: false },
];
export default function MailDefault() {
const [open, setOpen] = React.useState("1");
const [starred, setStarred] = React.useState<string[]>(["3"]);
const mail = MAILS.find((item) => item.id === open)!;
return (
<div className="grid w-full gap-4 @container">
<div className="grid gap-4 @2xl:grid-cols-[minmax(0,18rem)_1fr]">
<MailList aria-label="Inbox" className="rounded-lg border-(length:--edge) border-(--field-edge) bg-card p-1">
{MAILS.map((item) => (
<MailItem
key={item.id}
sender={item.sender}
subject={item.subject}
preview={item.preview}
time={item.time}
unread={item.unread && item.id !== open}
selected={item.id === open}
starred={starred.includes(item.id)}
onStarChange={(on) => setStarred((list) => (on ? [...list, item.id] : list.filter((id) => id !== item.id)))}
onOpen={() => setOpen(item.id)}
labels={item.label && item.id !== open ? <Badge variant="outline">{item.label}</Badge> : null}
/>
))}
</MailList>
<MailMessage
className="rounded-lg border-(length:--edge) border-(--field-edge) bg-card p-4"
subject={mail.subject}
from={mail.sender}
address={mail.address}
to="you"
time={mail.time}
avatar={
<Avatar className="size-9 text-xs">
<AvatarFallback>{mail.initials}</AvatarFallback>
</Avatar>
}
actions={
<>
<Button size="sm" variant="outline">Reply</Button>
<Button size="sm" variant="ghost">Archive</Button>
</>
}
>
<p>Hi,</p>
<p>{mail.preview}</p>
<p>Thanks,<br />{mail.sender}</p>
</MailMessage>
</div>
</div>
);
}
```
API
- `MailList`: The list.
- `MailItem`: One message in the list.
- `sender, subject, preview, time` (`string`): What the row shows.
- `unread` (`boolean`): Marks it unread.
- `selected` (`boolean`): Marks the message that is open.
- `starred, onStarChange` (`boolean, (starred) => void`): Adds a star toggle.
- `onOpen / href` (`() => void / string`): Opens the message.
- `labels` (`ReactNode`): Small labels after the subject.
- `MailMessage`: A message opened for reading. Children are the body.
- `subject, from, address, to, time` (`string`): The header.
- `avatar, actions` (`ReactNode`): The sender's avatar, and buttons such as Reply.
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 whole row opens the message, while staying one button or link; the star is a separate toggle. Unread is said in words as well as shown by the square dot.
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 { Avatar, AvatarFallback } from "@/components/ui/avatar";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { MailItem, MailList, MailMessage } from "@/components/ui/mail";
const MAILS = [
{ id: "1", sender: "Maya Chen", initials: "MC", address: "maya@acme.com", subject: "Launch page copy, final", preview: "Legal signed off last night. I only changed the pricing line.", time: "9:41", unread: true, label: "Launch" },
{ id: "2", sender: "Billing", initials: "B", address: "billing@acme.com", subject: "Your invoice for November", preview: "Invoice INV-004 for $450.00 is ready to download.", time: "8:02", unread: true },
{ id: "3", sender: "Arif Rahman", initials: "AR", address: "arif@acme.com", subject: "Checkout total is fixed", preview: "The rounding bug is gone. Can you check staging before noon?", time: "Yesterday", unread: false },
];
export default function MailDefault() {
const [open, setOpen] = React.useState("1");
const [starred, setStarred] = React.useState<string[]>(["3"]);
const mail = MAILS.find((item) => item.id === open)!;
return (
<div className="grid w-full gap-4 @container">
<div className="grid gap-4 @2xl:grid-cols-[minmax(0,18rem)_1fr]">
<MailList aria-label="Inbox" className="rounded-lg border-(length:--edge) border-(--field-edge) bg-card p-1">
{MAILS.map((item) => (
<MailItem
key={item.id}
sender={item.sender}
subject={item.subject}
preview={item.preview}
time={item.time}
unread={item.unread && item.id !== open}
selected={item.id === open}
starred={starred.includes(item.id)}
onStarChange={(on) => setStarred((list) => (on ? [...list, item.id] : list.filter((id) => id !== item.id)))}
onOpen={() => setOpen(item.id)}
labels={item.label && item.id !== open ? <Badge variant="outline">{item.label}</Badge> : null}
/>
))}
</MailList>
<MailMessage
className="rounded-lg border-(length:--edge) border-(--field-edge) bg-card p-4"
subject={mail.subject}
from={mail.sender}
address={mail.address}
to="you"
time={mail.time}
avatar={
<Avatar className="size-9 text-xs">
<AvatarFallback>{mail.initials}</AvatarFallback>
</Avatar>
}
actions={
<>
<Button size="sm" variant="outline">Reply</Button>
<Button size="sm" variant="ghost">Archive</Button>
</>
}
>
<p>Hi,</p>
<p>{mail.preview}</p>
<p>Thanks,<br />{mail.sender}</p>
</MailMessage>
</div>
</div>
);
}Examples
Read mail and empty trash
- Arif RahmanThe rounding bug is gone. Thanks for the quick look.
- Dana WhitfieldThree requests came up twice: CSV export, saved filters and a weekly digest.
- Trash is empty. Deleted messages stay here for 30 days.
Long subject
Re: Offsite planning for the whole design and engineering group in March
Hi all,
Three venues are still in the running. The lakeside one is the cheapest, the city one is easiest to reach, and the farm has room for workshops.
Please vote by Friday so we can hold the dates.
Imran
Loading inbox
Could not load
We could not reach your mail server. Your messages are safe.
Props
MailList
The list.
MailItem
One message in the list.
| Prop | Type | Default | Description |
|---|---|---|---|
| sender, subject, preview, time | string | – | What the row shows. |
| unread | boolean | – | Marks it unread. |
| selected | boolean | – | Marks the message that is open. |
| starred, onStarChange | boolean, (starred) => void | – | Adds a star toggle. |
| onOpen / href | () => void / string | – | Opens the message. |
| labels | ReactNode | – | Small labels after the subject. |
MailMessage
A message opened for reading. Children are the body.
| Prop | Type | Default | Description |
|---|---|---|---|
| subject, from, address, to, time | string | – | The header. |
| avatar, actions | ReactNode | – | The sender's avatar, and buttons such as Reply. |
Accessibility
The whole row opens the message, while staying one button or link; the star is a separate toggle. Unread is said in words as well as shown by the square dot.
Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.