A mail client for a fictional team: folders with unread counts, a message list with sender, subject, snippet, time, unread weight and a star toggle, and a reading pane where you can reply or archive. The folders are a NavList laid out in a row, and Button, Badge, Heading, Field, Textarea and toast come from the system; the panes and rows are app-owned CSS on tokens.
Venue shortlist for the March offsite
MO
Maya Okaformaya@fieldnote.example · 9:41 AM
Hi team, three places made the cut after Friday’s calls.
The lake house has the best rooms but needs a bus from the airport. The mill in town is walkable and has a kitchen we can use. The vineyard is lovely and the most expensive by about 30%.
Can you reply with your first and second choice by Wednesday? I’ll hold all three until then.
'use client'import { Badge, Body, BodySmall, Button, Field, Heading, NavList, Stack, Text, Textarea, toast, toastSuccess } from'@blocks/design-system'import { Archive, ArrowLeft, Inbox,type LucideIcon, Reply, Send, Star } from'lucide-react'import { type FormEvent, useId, useRef, useState } from'react'import styles from'./email-inbox.module.css'typeFolderId='inbox'|'starred'|'sent'|'archive'interfaceMessage {
id:string folder:'inbox'|'sent'|'archive' name:string initials:string address:string subject:string snippet:string body:string[]
time:string unread:boolean starred:boolean}
constfolders: { id:FolderId; label:string; icon:LucideIcon }[] = [
{ id:'inbox', label:'Inbox', icon: Inbox }, { id:'starred', label:'Starred', icon: Star }, { id:'sent', label:'Sent', icon: Send }, { id:'archive', label:'Archive', icon: Archive },]
constinitialMessages:Message[] = [
{
id:'venues', folder:'inbox', name:'Maya Okafor', initials:'MO', address:'maya@fieldnote.example', subject:'Venue shortlist for the March offsite', snippet:'Three places made the cut. The lake house has the best rooms but', body: [
'Hi team, three places made the cut after Friday’s calls.','The lake house has the best rooms but needs a bus from the airport. The mill in town is walkable and has a kitchen we can use. The vineyard is lovely and the most expensive by about 30%.','Can you reply with your first and second choice by Wednesday? I’ll hold all three until then.', ], time:'9:41 AM', unread:true, starred:true, }, {
id:'invoice', folder:'inbox', name:'Ledgerline Billing', initials:'LB', address:'billing@ledgerline.example', subject:'Your November invoice is ready', snippet:'Invoice LL-20481 for $1,240.00 is available in your billing', body: [
'Invoice LL-20481 for $1,240.00 is available in your billing settings.','It will be charged to the card ending in 4417 on December 5. No action is needed.', ], time:'8:15 AM', unread:true, starred:false, }, {
id:'review', folder:'inbox', name:'Priya Natarajan', initials:'PN', address:'priya@fieldnote.example', subject:'Design review notes: search filters', snippet:'Thanks for walking us through it. Two things to settle before', body: [
'Thanks for walking us through it. Two things to settle before we build:','Do filters apply as you pick them, or on Apply? And does clearing the query also clear the filters? I lean towards live filters and keeping them.', ], time:'Yesterday', unread:true, starred:false, }, {
id:'checklist', folder:'inbox', name:'Tomás Reyes', initials:'TR', address:'tomas@fieldnote.example', subject:'Re: Onboarding checklist v2', snippet:'Merged your edits. I moved “Set up your laptop” to day one', body: ['Merged your edits. I moved “Set up your laptop” to day one and dropped the duplicate security quiz.'], time:'Yesterday', unread:false, starred:false, }, {
id:'lunch', folder:'inbox', name:'Jun Park', initials:'JP', address:'jun@fieldnote.example', subject:'Lunch Thursday?', snippet:'The noodle place on Alder reopened. 12:30 work for you?', body: ['The noodle place on Alder reopened. 12:30 work for you?'], time:'Nov 28', unread:false, starred:true, }, {
id:'agenda', folder:'sent', name:'Maya Okafor', initials:'MO', address:'maya@fieldnote.example', subject:'Offsite agenda, first draft', snippet:'Day one is planning, day two is workshops. Edit freely.', body: ['Day one is planning, day two is workshops. Edit freely; I’ll lock it on the 15th.'], time:'Nov 27', unread:false, starred:false, }, {
id:'welcome', folder:'archive', name:'Elena Vasquez', initials:'EV', address:'elena@fieldnote.example', subject:'Welcome to Fieldnote!', snippet:'We’re so glad you’re here. Your first week is mostly', body: ['We’re so glad you’re here. Your first week is mostly meeting people, so don’t worry about shipping anything yet.'], time:'Oct 2', unread:false, starred:false, },]
constinFolder= (message:Message, folder:FolderId) => (folder ==='starred'?message.starred :message.folder === folder)
// A two-pane mail client. Wide containers show the list and the message side// by side; narrow ones show one pane at a time, switched by `view`.exportdefaultfunctionEmailInbox() {
const [messages,setMessages] =useState(initialMessages)
const [folder,setFolder] =useState<FolderId>('inbox')
const [selectedId,setSelectedId] =useState<string|null>('venues')
const [view,setView] =useState<'list'|'message'>('list')
const [replying,setReplying] =useState(false)
const [replyError,setReplyError] =useState('')
constlistRef=useRef<HTMLDivElement>(null)
constsubjectRef=useRef<HTMLHeadingElement>(null)
constreplyRef=useRef<HTMLInputElement>(null)
constid=useId()
constvisible=messages.filter((message) =>inFolder(message, folder))
constselected=visible.find((message) =>message.id === selectedId)
constfolderLabel=folders.find((entry) =>entry.id === folder)?.label
constitemId= (messageId:string) =>`${id}-message-${messageId}`functionupdate(messageId:string, change:Partial<Message>) {
setMessages((current) =>current.map((message) => (message.id === messageId ? { ...message,...change } : message)))
}
functionopenFolder(next:FolderId) {
setFolder(next)
setSelectedId(messages.find((message) =>inFolder(message, next))?.id ??null)
setView('list')
setReplying(false)
}
// On a phone only one pane shows, so focus follows the pane that opens.constlistHidden= () =>listRef.current?.getClientRects().length===0constfocusItem= (messageId:string) =>requestAnimationFrame(() =>document.getElementById(itemId(messageId))?.focus())
functionopenMessage(messageId:string) {
update(messageId, { unread:false })
setSelectedId(messageId)
setView('message')
setReplying(false)
requestAnimationFrame(() => {
if (listHidden()) subjectRef.current?.focus()
})
}
functionbackToList() {
setView('list')
if (selectedId) focusItem(selectedId)
}
functionarchive(message:Message) {
constindex=visible.indexOf(message)
constnext= visible[index +1] ?? visible[index -1]
constdestination=message.folder ==='archive'?'inbox':'archive'update(message.id, { folder: destination })
setSelectedId(next?.id ??null)
if (next &&listHidden()) focusItem(next.id)
setView('list')
toast(destination ==='archive'?`Archived “${message.subject}”`:`Moved “${message.subject}” to Inbox`)
}
functionstartReply() {
setReplyError('')
setReplying(true)
requestAnimationFrame(() =>replyRef.current?.focus())
}
functionsendReply(event:FormEvent<HTMLFormElement>, message:Message) {
event.preventDefault()
constreply=String(newFormData(event.currentTarget).get('reply')).trim()
if (!reply) {
setReplyError('Write a reply before sending.')
return }
setReplying(false)
toastSuccess(`Reply sent to ${message.name}`)
}
return (
<sectionclassName={styles.root} aria-label="Mail">
<NavListaria-label="Mail folders"dangerouslySetClassName={styles.folders}>
{folders.map(({ id: folderId, label, icon: Icon }) => {
constunread=messages.filter((message) =>message.unread &&inFolder(message, folderId)).lengthreturn (
<NavList.Itemkey={folderId} as="button"type="button"active={folder === folderId} onClick={() =>openFolder(folderId)}>
<Iconaria-hiddensize={14} />
<spanclassName={styles.folderLabel}>{label}</span>
{unread >0&& (
<Badgetone="accent">
{unread}
<spanclassName={styles.srOnly}> unread</span>
</Badge>
)}
</NavList.Item>
)
})}
</NavList>
<divclassName={styles.panes} data-view={view}>
<divclassName={styles.list} ref={listRef}>
{visible.length===0? (
<BodySmallcolor="text-muted"margin="none"dangerouslySetClassName={styles.listEmpty}>
Nothing in {folderLabel}.
</BodySmall>
) : (
<ulclassName={styles.messages} aria-label={`${folderLabel} messages`}>
{visible.map((message) => (
<likey={message.id} className={styles.item} data-unread={message.unread ||undefined}>
<buttontype="button"id={itemId(message.id)}
className={styles.itemButton}
aria-current={message.id ===selected?.id ?'true':undefined}
onClick={() =>openMessage(message.id)}
>
<spanclassName={styles.avatar} aria-hidden>
{message.initials}
</span>
<spanclassName={styles.itemText}>
<spanclassName={styles.itemTop}>
<spanclassName={styles.sender}>
{message.unread && <spanclassName={styles.srOnly}>Unread, </span>}
{message.folder ==='sent'?`To ${message.name}`:message.name}
</span>
<spanclassName={styles.time}>{message.time}</span>
</span>
<spanclassName={styles.subject}>{message.subject}</span>
<spanclassName={styles.snippet}>{message.snippet}</span>
</span>
</button>
<buttontype="button"className={styles.star}
aria-pressed={message.starred}
aria-label={`Star “${message.subject}”`}
onClick={() =>update(message.id, { starred:!message.starred })}
>
<Stararia-hiddensize={16} />
</button>
</li>
))}
</ul>
)}
</div>
<articleclassName={styles.reader} aria-label="Message">
<Buttontype="button"size="sm"variant="ghost"dangerouslySetClassName={styles.back} onClick={backToList}>
<ArrowLeftaria-hiddensize={14} />
Back to {folderLabel}
</Button>
{selected ? (
<Stackgap="lg">
<Stackgap="md">
<Headingas="h3"fontSize="lg"ref={subjectRef} tabIndex={-1} dangerouslySetClassName={styles.subjectHeading}>
{selected.subject}
</Heading>
<Stackdirection="row"gap="md"align="center">
<spanclassName={styles.avatar} aria-hidden>
{selected.initials}
</span>
<Stackgap="none"flex="1">
<TextfontSize="sm"fontWeight="semibold">
{selected.folder ==='sent'?`To ${selected.name}`:selected.name}
</Text>
<TextfontSize="xs"color="text-muted">
{selected.address} · {selected.time}
</Text>
</Stack>
</Stack>
</Stack>
<Stackgap="md">
{selected.body.map((paragraph) => (
<Bodykey={paragraph} fontSize="sm"margin="none">
{paragraph}
</Body>
))}
</Stack>
{replying ? (
<Stackas="form"gap="sm"noValidateonSubmit={(event:FormEvent<HTMLFormElement>) =>sendReply(event, selected)}>
<Fieldname="reply"invalid={Boolean(replyError)}>
<Field.Label>Reply to {selected.name}</Field.Label>
<Field.Controlref={replyRef} render={<Textarearows={4} />} onValueChange={() =>setReplyError('')} />
{replyError && <Field.Errormatch>{replyError}</Field.Error>}
</Field>
<Stackdirection="row"gap="sm">
<Buttontype="submit"variant="primary"size="sm">
<Sendaria-hiddensize={14} />
Send
</Button>
<Buttontype="button"variant="ghost"size="sm"onClick={() =>setReplying(false)}>
Discard
</Button>
</Stack>
</Stack>
) : (
<Stackdirection="row"gap="sm"wrap="wrap">
<Buttontype="button"size="sm"onClick={startReply}
>
<Replyaria-hiddensize={14} />
Reply
</Button>
<Buttontype="button"size="sm"onClick={() =>archive(selected)}>
<Archivearia-hiddensize={14} />
{selected.folder ==='archive'?'Move to Inbox':'Archive'}
</Button>
</Stack>
)}
</Stack>
) : (
<BodySmallcolor="text-muted"margin="none">
Select a message to read it here.
</BodySmall>
)}
</article>
</div>
</section>
)
}
Each row is two real buttons side by side: the message itself (aria-current marks the open one) and the star (aria-pressed). Unread rows are heavier and carry a dot, and a visually hidden “Unread,” says the same thing to a screen reader. Opening a message marks it read, and the folder counts follow.
The layout responds to its own width with a container query, not the viewport. Above 34rem the list and the message sit side by side and scroll on their own; below it one pane shows at a time, view decides which, and a Back button returns to the list. On a phone the folders stay on one row: only the current folder shows its name, and the others keep theirs visually hidden for screen readers.
On a phone focus follows the pane that opens: the subject heading when a message opens, the same row on Back, and the next row after Archive. The check is whether the list is still rendered, so the same code does nothing on a wide screen.
Reply opens an inline form. Sending an empty reply sets invalid on the Field and shows a Field.Error; a real reply closes the form with a success toast.