# Mail

> A webmail: folders with unread counts and their menus, filters, the message list with selection, bulk actions and stars, the thread with an HTML mail in its sandbox and one-click unsubscribe for newsletters, and the composer in a drawer wit

Pattern · Halo kit · [Live page](https://ui.twentyfirst.media/halo/patterns/MailScreen/)

A webmail: folders with unread counts and their menus, filters, the message list with selection, bulk actions and stars, the thread with an HTML mail in its sandbox and one-click unsubscribe for newsletters, and the composer in a drawer with "Send later" and Undo.

## Code

```tsx
import * as React from "react";
import {
  AppShell,
  Button,
  Drawer,
  IconButton,
  InboxList,
  MailComposer,
  MailFilterBar,
  MailFolders,
  MailHtml,
  MailThread,
  PageHeader,
  Toaster,
  toast,
} from "@twentyfirstmedia/halo";
import type { InboxListItem, MailFilters } from "@twentyfirstmedia/halo";
import { FOLDERS, NEWSLETTER_HTML, PEOPLE } from "./_mail";

const MAILS: InboxListItem[] = [
  {
    id: 1,
    from: "Example Weekly",
    time: "09:12",
    subject: "The weekly digest",
    snippet: "Three things shipped this week: faster exports, saved views and a new audit log.",
    unread: true,
  },
  {
    id: 2,
    from: "Ida Nolan",
    time: "08:40",
    subject: "Seat upgrade before renewal",
    snippet: "We are growing faster than planned and need 40 more seats.",
    unread: true,
    attachments: true,
    agent: { label: "Draft ready", tone: "highlight" },
  },
  {
    id: 3,
    from: "Jonah Petit",
    time: "Yesterday",
    subject: "Pricing review moved",
    snippet: "Can we move the pricing review to Thursday so Growth can join?",
    starred: true,
  },
  {
    id: 4,
    from: "Northwind Billing",
    time: "Mon",
    subject: "Invoice RE-2026-0412",
    snippet: "Your invoice for April is attached.",
    attachments: true,
  },
];

function App() {
  const [open, setOpen] = React.useState<string | number>(1);
  const [items, setItems] = React.useState(MAILS);
  const [filters, setFilters] = React.useState<MailFilters>({});
  const [compose, setCompose] = React.useState(false);
  const [unsubscribed, setUnsubscribed] = React.useState(false);
  const shown = items.filter(
    (m) =>
      (!filters.unread || m.unread) &&
      (!filters.starred || m.starred) &&
      (!filters.attachments || m.attachments),
  );
  const current = items.find((m) => m.id === open);
  return (
    <AppShell
      brand="Halo"
      tag="Mail"
      user={{ name: "Mara Ellis", email: "mara@example.com" }}
      active="Inbox"
      dock={false}
    >
      <div className="tf-in">
        <PageHeader
          title="Inbox"
          subtitle="12 unread"
          actions={[
            <Button key="c" icon="edit" onClick={() => setCompose(true)}>
              Compose
            </Button>,
          ]}
        />
      </div>
      <div
        className="tf-grid tf-in"
        style={
          {
            "--cols": "248px minmax(0, 1fr)",
            alignItems: "start",
            "--d": "120ms",
          } as React.CSSProperties
        }
      >
        <div className="tf-panel" style={{ gap: 8 }}>
          <MailFolders
            folders={FOLDERS}
            defaultSelected="inbox"
            defaultOpen={["clients"]}
            onCreate={() => {}}
            onRename={() => {}}
            onDelete={() => {}}
            onEmpty={() => {}}
          />
        </div>
        <div className="tf-col" style={{ gap: 16 }}>
          <div className="tf-panel" style={{ gap: 12 }}>
            <MailFilterBar
              value={filters}
              onChange={setFilters}
              agents={[{ value: "support", label: "Support agent" }]}
            />
            <InboxList
              items={shown}
              selected={open}
              onOpen={(m) => {
                setOpen(m.id);
                setItems((l) => l.map((x) => (x.id === m.id ? { ...x, unread: false } : x)));
              }}
              selectable
              bulkActions={[
                {
                  label: "Archive",
                  icon: "archive",
                  onClick: (ids) => setItems((l) => l.filter((m) => !ids.includes(m.id))),
                },
                {
                  label: "Mark read",
                  icon: "check",
                  onClick: (ids) =>
                    setItems((l) =>
                      l.map((m) => (ids.includes(m.id) ? { ...m, unread: false } : m)),
                    ),
                },
              ]}
              onStar={(m, starred) =>
                setItems((l) => l.map((x) => (x.id === m.id ? { ...x, starred } : x)))
              }
            />
          </div>
          {current && (
            <div className="tf-panel" style={{ gap: 12 }}>
              <MailThread
                subject={current.subject}
                actions={
                  <>
                    <IconButton
                      icon="reply"
                      variant="ghost"
                      label="Reply"
                      onClick={() => setCompose(true)}
                    />
                    <IconButton icon="archive" variant="ghost" label="Archive" />
                  </>
                }
                unsubscribe={
                  current.id === 1
                    ? {
                        sender: "Example Weekly",
                        done: unsubscribed,
                        onUnsubscribe: () => {
                          setUnsubscribed(true);
                          toast("Unsubscribed from Example Weekly");
                        },
                      }
                    : undefined
                }
                messages={[
                  {
                    id: current.id,
                    from: current.from,
                    to: "to me",
                    time: current.time,
                    body:
                      current.id === 1 ? (
                        <MailHtml html={NEWSLETTER_HTML} title={current.subject} />
                      ) : (
                        current.snippet
                      ),
                  },
                ]}
              />
            </div>
          )}
        </div>
      </div>
      {compose && (
        <Drawer title="New message" onClose={() => setCompose(false)} width={640}>
          <MailComposer
            senders={[
              { address: "mara@example.com", name: "Mara Ellis" },
              { address: "support@example.com" },
            ]}
            suggestions={PEOPLE}
            signature="Mara Ellis · Example Inc."
            onSend={() => setCompose(false)}
            onUndoSend={() => setCompose(true)}
            onSchedule={() => setCompose(false)}
            onFiles={() => {}}
          />
        </Drawer>
      )}
      <Toaster />
    </AppShell>
  );
}

export default function Preview() {
  return <App />;
}
```

## Props

### AppShell

| Prop | Type | Notes |
| --- | --- | --- |
| `active?` | `string` | Id (or label) of the current page; or let `pathname` find it. |
| `pathname?` | `string` | The current path (`usePathname()` in Next.js): the page whose `href` matches it marks itself, the longest match winning, so `/settings/billing` marks "Billing" before "Settings". |
| `linkAs?` | `ElementType` | The element nav items with an `href` render as everywhere in the shell (top nav, sidebar, tab bar, rail, dock), e.g. Next.js `Link`; default `UIProvider linkAs`, else `a`. |
| `notifications?` | `NotificationCenterProps` | The bell in the top bar: unread count, a popover (a sheet on phones) with the list. |
| `appearance?` | `boolean \| AppearanceMenuProps` | The look menu (`AppearanceMenu`) in the top bar; `true` for the default one. |
| `tabBar?` | `boolean \| number` | On phones (up to 760px wide): a tab bar at the bottom with the first pages (default 4) and "More" for the rest. `true` or the number of tabs. |
| `skipLink?` | `boolean` | A "Skip to content" link before the navigation (default true). |
| `mainId?` | `string` | Id of the `<main>` element the skip link jumps to (default generated). |
| `brand?` | `ReactNode` | The product name, or a node (a logo mark with the name; collapsed sidebars show it whole). |
| `brandDot?` | `boolean` | The status dot after the brand (default `true`); turn it off next to a logo of your own. |
| `tag?` | `string` |  |
| `nav?` | `NavItem[]` |  |
| `user?` | `{ name: string; email?: string }` |  |
| `onNavigate?` | `(label: string) => void` |  |
| `topExtra?` | `ReactNode` |  |
| `sheetStyle?` | `CSSProperties` |  |
| `contentKey?` | `string \| number` |  |
| `side?` | `ReactNode` |  |
| `dock?` | `boolean` |  |
| `dockItems?` | `DockProps["items"]` |  |
| `railTop?` | `RailItem[]` |  |
| `railBottom?` | `RailItem[]` |  |
| `fill?` | `boolean` | The shell is the whole page: at least the viewport's height (100dvh), no outer radius, the sheet fills the rest; on desktop the sidebar stays in view while the page scrolls, on phones the sheet starts right under the sidebar's bar. |
| `navigation?` | `"top" \| "sidebar"` |  |
| `sidebarGroups?` | `SidebarGroup[]` | With `navigation="sidebar"`: groups instead of the flat `nav` list. |
| `sidebar?` | `Partial<Omit<SidebarProps, "variant" \| "groups">>` | With `navigation="sidebar"`: more sidebar props (collapsed, storageKey, shortcut, linkAs …). |
| `workspaces?` | `WorkspaceSwitcherProps` | With `navigation="sidebar"`: the workspace switcher at the top instead of the brand. |
| `userMenu?` | `(MenuItem \| "-")[]` | The account menu's entries (with `navigation="sidebar"` at the foot of the sidebar). |
| `topbar?` | `boolean \| ReactNode` | With `navigation="sidebar"`: a bar across the top of the frame. The brand (or `workspaces`) moves into its start, as wide as the sidebar below it (expanded or collapsed); `topStart` follows it, `topEnd` sits at the end. Frame, bar and sidebar read as one L around the sheet. Content given here goes between `topStart` and `topEnd`. On phones the bar is the sidebar's bar (menu button and brand) with `topEnd` on the right and `topStart` behind an icon button. |
| `topStart?` | `ReactNode` | With `topbar`: right after the brand, e.g. a search field or a command palette trigger. |
| `topEnd?` | `ReactNode` | With `topbar`: at the end of the bar (buttons, menus); `topExtra` goes there too. |
| `topStartCompact?` | `ReactNode` | With `topbar` on phones: what stands in for `topStart` (default: an icon button that opens `topStart` over the bar). |
| `topStartIcon?` | `IconName` | The icon of that button (default `search`). |
| `topStartLabel?` | `string` | The accessible name of that button (default "Search"). |
| `children?` | `ReactNode` |  |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### PageHeader

| Prop | Type | Notes |
| --- | --- | --- |
| `crumbs?` | `(string \| Crumb)[]` | A breadcrumb above the title (see `Breadcrumb`): labels, or items with `href`/`onClick`. |
| `crumbLinkAs?` | `ElementType` | The element crumb links render as, e.g. Next.js `Link`. |
| `title` | `string` | Required |
| `subtitle?` | `string` |  |
| `actions?` | `ReactNode[]` |  |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### MailFolders

| Prop | Type | Notes |
| --- | --- | --- |
| `folders` | `MailFolder[]` | Required |
| `selected?` | `string \| null` | The open folder (controlled) / initially / on pick. |
| `defaultSelected?` | `string \| null` |  |
| `onSelect?` | `(id: string \| null) => void` |  |
| `defaultOpen?` | `string[]` | Folders with children open at first. |
| `onCreate?` | `(name: string, parent: string \| null) => void` | New folder (at the top level or inside `parent`). |
| `onRename?` | `(id: string, name: string) => void` |  |
| `onDelete?` | `(id: string) => void` | Delete an own folder (after a confirmation). |
| `onEmpty?` | `(id: string) => void` | Empty trash or junk (after a confirmation). |
| `linkAs?` | `ElementType` |  |
| `label?` | `string` | Accessible name of the navigation (default "Folders"). |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### MailFilterBar

| Prop | Type | Notes |
| --- | --- | --- |
| `value?` | `MailFilters` |  |
| `defaultValue?` | `MailFilters` |  |
| `onChange?` | `(filters: MailFilters) => void` |  |
| `accounts?` | `Option[]` |  |
| `domains?` | `Option[]` |  |
| `agents?` | `Option[]` | Agents mail can be filtered by (mail an agent handled or drafted). |
| `count?` | `number` | Messages matching, shown at the end. |
| `label?` | `string` |  |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### InboxList

| Prop | Type | Notes |
| --- | --- | --- |
| `items` | `InboxListItem[]` | Required |
| `selected?` | `string \| number` | The open message. |
| `onOpen?` | `(m: InboxListItem) => void` |  |
| `selectable?` | `boolean` | A checkbox per row; the checked ids (controlled) / initially / on change. |
| `checked?` | `(string \| number)[]` |  |
| `defaultChecked?` | `(string \| number)[]` |  |
| `onCheckedChange?` | `(ids: (string \| number)[]) => void` |  |
| `bulkActions?` | `{ label: string; icon?: IconName; danger?: boolean; onClick: (ids: (string \| number)[]) => void; }[]` | Actions for the checked messages, in a `BulkActionBar` above the list. |
| `onStar?` | `(m: InboxListItem, starred: boolean) => void` | A star per row. |
| `linkAs?` | `ElementType` |  |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### BulkActionBar

| Prop | Type | Notes |
| --- | --- | --- |
| `count` | `number` | How many items are selected; the bar hides at 0 (unless `keepOpen`). |
| `actions?` | `BulkActionBarAction[]` |  |
| `onClear?` | `() => void` | Shows "Clear" and is called by it. |
| `label?` | `string` | Accessible name of the toolbar (default "Bulk actions"). |
| `keepOpen?` | `boolean` | Stays visible with 0 selected (e.g. while an exit animation runs in your list). |
| `floating?` | `boolean` | Default: the bar floats, sticky at the bottom of its scroll area (as in DataTable). `false` keeps it in the flow, e.g. at the top of a mail list. |
| `children?` | `ReactNode` | More controls after the actions (a menu, a select). |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### MailThread

| Prop | Type | Notes |
| --- | --- | --- |
| `subject` | `string` | Required |
| `messages` | `{ id: string \| number; from: string; to?: string; time?: string; snippet?: string; body: ReactNode; agent?: boolean; tint?: Tint; agentNote?: string; attachments?: { name: string; size?: string }[]; }[]` | Required |
| `reply?` | `ReactNode` |  |
| `unsubscribe?` | `{ sender?: string; onUnsubscribe: () => void; done?: boolean; busy?: boolean }` | A newsletter: one-click unsubscribe under the subject (RFC 8058 List-Unsubscribe-Post). |
| `actions?` | `ReactNode` | Buttons next to the subject (reply, archive …). |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### MailHtml

| Prop | Type | Notes |
| --- | --- | --- |
| `html` | `string` | The mail's HTML. Sanitise it on the server; the frame still runs nothing and loads nothing. |
| `title?` | `string` | The frame's accessible name (default "Message"). |
| `images?` | `boolean` | Remote images loaded (controlled) / initially / when the reader loads them. |
| `defaultImages?` | `boolean` |  |
| `onImagesChange?` | `(images: boolean) => void` |  |
| `onLoadImages?` | `() => void` | "Load images" was pressed (e.g. to remember the sender). |
| `blockedImages?` | `number` | How many remote images are blocked (default: counted in `html`). |
| `appearance?` | `"paper" \| "theme"` | `"paper"` (default): the mail keeps its own light paper in every theme, as senders design it. `"theme"`: the page's surface and text colours, dark in the dark theme (for plain mails). |
| `minHeight?` | `number` | Smallest height in px while it loads (default 120). |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### MailComposer

| Prop | Type | Notes |
| --- | --- | --- |
| `senders?` | `{ address: string; name?: string }[]` | Addresses you may send from; a select when there are several. |
| `value?` | `MailDraft` | The draft (controlled) / initially / on every change (save it as a draft). |
| `defaultValue?` | `Partial<MailDraft>` |  |
| `onChange?` | `(draft: MailDraft) => void` |  |
| `suggestions?` | `MailRecipient[]` |  |
| `suggest?` | `(typed: string) => MailRecipient[] \| Promise<MailRecipient[]>` |  |
| `signature?` | `ReactNode` | The signature shown under the text, with a switch to leave it out. |
| `onSend?` | `(draft: MailDraft) => void` | Send (also ⌘/Ctrl+Enter); on only with valid recipients and no upload running. |
| `onUndoSend?` | `(draft: MailDraft) => void` | Shows "Message sent" with Undo in a toast (needs a `<Toaster/>`). Hold the mail for `undoSeconds` and drop it when this is called. |
| `undoSeconds?` | `number` | How long Undo stays (default 10 s). |
| `onSchedule?` | `(draft: MailDraft, at: Date) => void` | "Send later" with a date and time. |
| `onFiles?` | `(files: File[]) => void` | Files picked on this device (add them to `attachments` and upload). |
| `attachSources?` | `{ label: string; icon?: IconName; onClick: () => void }[]` | More places to attach from, e.g. "From Drive" (opens your picker). |
| `onRemoveAttachment?` | `(id: string) => void` |  |
| `saved?` | `"saving" \| "saved" \| "error" \| null` | Draft state: saving, saved (at `savedAt`) or failed. |
| `savedAt?` | `Date` |  |
| `onDiscard?` | `() => void` |  |
| `sending?` | `boolean` |  |
| `title?` | `string` | Heading (default "New message"). |
| `placeholder?` | `string` |  |
| `minHeight?` | `number` |  |
| `autoFocus?` | `boolean` |  |
| `footer?` | `ReactNode` | More controls in the footer. |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### Drawer

| Prop | Type | Notes |
| --- | --- | --- |
| `title` | `string` | Required |
| `subtitle?` | `ReactNode` |  |
| `avatar?` | `string` |  |
| `onClose?` | `() => void` |  |
| `width?` | `number \| string` |  |
| `inline?` | `boolean` |  |
| `children?` | `ReactNode` |  |
| `open?` | `boolean` | Optional: with `open` the component stays mounted while it animates out; without it, render it only while open. |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### IconButton

| Prop | Type | Notes |
| --- | --- | --- |
| `icon` | `IconName` | Required |
| `label` | `string` | Accessible name and tooltip (`aria-label` and `title`); `aria-label` or `title` override them. |
| `variant?` | `"soft" \| "solid" \| "outline" \| "ghost"` |  |
| `size?` | `"sm" \| "md" \| "lg"` |  |
| `type?` | `"button" \| "submit" \| "reset"` |  |
| `onClick?` | `(e: MouseEvent<HTMLButtonElement>) => void` |  |
| `disabled?` | `boolean` |  |
| `asChild?` | `boolean` | Render the single child element (a link) with the button's look; the icon is placed inside it. |
| `href?` | `string` | Render a link instead of a button (middle-click, ⌘-click, prefetch): `label` stays its accessible name and tooltip. Use `linkAs` for a router link (e.g. Next.js `Link`). |
| `linkAs?` | `ElementType` | The link component for `href` (default `a`), e.g. Next.js `Link`. |
| `children?` | `ReactNode` |  |
| `id?` | `string` |  |
| `name?` | `string` | Form field name and value, sent with the form when this button submits it. |
| `value?` | `string` |  |
| `form?` | `string` | The id of the form this button belongs to, when it sits outside it. |
| `title?` | `string` |  |
| `tabIndex?` | `number` |  |
| `autoFocus?` | `boolean` |  |
| `aria-label?` | `string` |  |
| `aria-labelledby?` | `string` |  |
| `aria-describedby?` | `string` |  |
| `aria-expanded?` | `boolean \| "true" \| "false"` | For disclosure and menu triggers: whether what the button controls is open. |
| `aria-controls?` | `string` |  |
| `aria-haspopup?` | `boolean \| "true" \| "false" \| "menu" \| "listbox" \| "tree" \| "grid" \| "dialog"` |  |
| `aria-pressed?` | `boolean \| "true" \| "false" \| "mixed"` | For toggle buttons. |
| `aria-current?` | `boolean \| "true" \| "false" \| "page" \| "step" \| "location" \| "date" \| "time"` |  |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### Button

| Prop | Type | Notes |
| --- | --- | --- |
| `variant?` | `"primary" \| "secondary" \| "soft" \| "ghost" \| "danger" \| "danger-solid"` |  |
| `size?` | `"md" \| "sm"` |  |
| `icon?` | `IconName` |  |
| `iconRight?` | `IconName` |  |
| `disabled?` | `boolean` |  |
| `type?` | `"button" \| "submit" \| "reset"` |  |
| `onClick?` | `(e: MouseEvent<HTMLButtonElement>) => void` |  |
| `children?` | `ReactNode` |  |
| `asChild?` | `boolean` | Render the single child element (a link, a router Link) with the button's look instead of a <button>. |
| `id?` | `string` |  |
| `name?` | `string` | Form field name and value, sent with the form when this button submits it. |
| `value?` | `string` |  |
| `form?` | `string` | The id of the form this button belongs to, when it sits outside it. |
| `title?` | `string` |  |
| `tabIndex?` | `number` |  |
| `autoFocus?` | `boolean` |  |
| `aria-label?` | `string` |  |
| `aria-labelledby?` | `string` |  |
| `aria-describedby?` | `string` |  |
| `aria-expanded?` | `boolean \| "true" \| "false"` | For disclosure and menu triggers: whether what the button controls is open. |
| `aria-controls?` | `string` |  |
| `aria-haspopup?` | `boolean \| "true" \| "false" \| "menu" \| "listbox" \| "tree" \| "grid" \| "dialog"` |  |
| `aria-pressed?` | `boolean \| "true" \| "false" \| "mixed"` | For toggle buttons. |
| `aria-current?` | `boolean \| "true" \| "false" \| "page" \| "step" \| "location" \| "date" \| "time"` |  |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### Toaster

| Prop | Type | Notes |
| --- | --- | --- |
| `position?` | `"bottom" \| "top"` |  |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |
