UI Library
Overlaydrawerpaneldetailinboxcrmnotesradix
Record drawer
A detail panel that slides in beside a list: the record's name and step at the top, its fields and message in a scrolling middle, a notes box over the activity trail, and Reply and Move-to-next-step pinned to the bottom. The step is a menu in the header and a split button in the footer.
Preview
Enquiries
- Nov 16Ravi MenonQuote request: on-site fire warden trainingWaiting on them
Open the first row to see the drawer.
apps/site/blocks/components/RecordDrawer.tsx
'use client';
/**
* A record drawer — standalone.
*
* The detail panel an inbox or a CRM list opens beside the table: one record's
* name and step at the top, its fields and message in a scrolling middle, a
* notes box with the activity trail under it, and the two next actions pinned
* to the bottom. It slides in from the right and floats with a margin, so the
* list behind it stays in view.
*
* ── Dependencies ────────────────────────────────────────────────────────────
* npm i @radix-ui/react-dialog lucide-react
*
* Tailwind is assumed and nothing else: no shadcn, no `cn()`, no animation
* plugin (the slide-in keyframes are injected with the panel). Radii are
* explicit pixels so a host that remaps `rounded-*` from its own `--radius`
* still renders the same shape.
*
* ── What it does ────────────────────────────────────────────────────────────
* - The step pill in the header is a menu; the split button at the bottom
* moves the record to the next step in one click, its chevron to any step.
* - "Add label" opens an inline field; labels show as removable chips.
* - Notes are saved into the activity trail, newest first; Save stays
* disabled until there is text. Ctrl/⌘ + Enter saves.
* - Radix handles the dialog work: focus moves in and back to the trigger,
* Escape and an outside click close it, Tab is trapped, the page behind
* does not scroll.
*
* ── Usage ───────────────────────────────────────────────────────────────────
* <RecordDrawer
* open={open}
* onOpenChange={setOpen}
* record={selected}
* steps={STEPS}
* onStepChange={(step) => save({ step })}
* onAddNote={(text) => save({ note: text })}
* onReply={() => (window.location.href = `mailto:${selected.email}`)}
* />
*
* Everything is controlled through props, so the drawer holds no copy of the
* record. `RecordDrawerDemo` below shows the wiring and is what /ui renders.
*/
import * as React from 'react';
import * as Dialog from '@radix-ui/react-dialog';
import { Check, ChevronDown, Mail, Plus, Tag, X } from 'lucide-react';
// ── Types ───────────────────────────────────────────────────────────────────
export type DrawerStep = {
id: string;
label: string;
/** Tailwind classes for the pill, e.g. 'bg-sky-50 text-sky-700'. */
tone: string;
};
export type DrawerField = {
label: string;
value: React.ReactNode;
};
export type DrawerActivity = {
id: string;
text: string;
/** Shown as written; format dates before passing them in. */
when: string;
/** A note the team wrote, as opposed to an event the system logged. */
isNote?: boolean;
};
export type DrawerRecord = {
title: string;
stepId: string;
/** e.g. "since today". */
stepSince?: string;
/** e.g. "Received Nov 17, 2026, 9:12 AM · via the contact form". */
subtitle?: string;
labels: string[];
fields: DrawerField[];
message?: string;
activity: DrawerActivity[];
};
// ── The drawer ──────────────────────────────────────────────────────────────
export function RecordDrawer({
open,
onOpenChange,
record,
steps,
onStepChange,
onAddLabel,
onRemoveLabel,
onAddNote,
onReply,
replyLabel = 'Reply by email',
messageLabel = 'Message',
notesLabel = 'Notes & activity',
notePlaceholder = 'Add a note… only the team sees it',
}: {
open: boolean;
onOpenChange: (open: boolean) => void;
record: DrawerRecord;
/** In order: the split button moves the record to the step after its own. */
steps: DrawerStep[];
onStepChange: (stepId: string) => void;
onAddLabel?: (label: string) => void;
onRemoveLabel?: (label: string) => void;
onAddNote?: (text: string) => void;
onReply?: () => void;
replyLabel?: string;
messageLabel?: string;
notesLabel?: string;
notePlaceholder?: string;
}) {
const index = Math.max(
0,
steps.findIndex((s) => s.id === record.stepId),
);
const step = steps[index];
const next = steps[index + 1];
return (
<Dialog.Root open={open} onOpenChange={onOpenChange}>
<Dialog.Portal>
<style>{DRAWER_KEYFRAMES}</style>
<Dialog.Overlay
className="fixed inset-0 z-50 bg-slate-900/30 backdrop-blur-[2px]"
style={{ animation: 'recordDrawerFade 200ms ease-out' }}
/>
{/*
* `top` and `bottom` together set the height, so it stays `auto`; the
* width is the viewport less both margins, capped on large screens.
* `overflow-hidden` keeps the header and footer rules inside the
* rounded corners.
*/}
<Dialog.Content
className={
'fixed inset-y-3 right-3 z-50 flex h-auto w-[calc(100%-1.5rem)] flex-col overflow-hidden ' +
'rounded-[18px] border border-slate-200 bg-white shadow-2xl outline-none sm:max-w-[440px]'
}
style={{ animation: 'recordDrawerIn 260ms cubic-bezier(0.32, 0.72, 0, 1)' }}
>
<header className="relative border-b border-slate-200 px-5 pb-3 pt-5">
<div className="flex flex-wrap items-center gap-2 pr-8">
<Dialog.Title className="text-xl font-extrabold tracking-tight text-slate-900">
{record.title}
</Dialog.Title>
<StepMenu steps={steps} current={step} onPick={onStepChange} />
{record.stepSince ? (
<span className="text-xs text-slate-500">{record.stepSince}</span>
) : null}
</div>
{record.subtitle ? (
<Dialog.Description className="mt-1 text-sm text-slate-500">
{record.subtitle}
</Dialog.Description>
) : (
<Dialog.Description className="sr-only">Record details</Dialog.Description>
)}
<Labels labels={record.labels} onAdd={onAddLabel} onRemove={onRemoveLabel} />
<Dialog.Close
className="absolute right-4 top-4 rounded-[8px] p-1.5 text-slate-500 transition hover:bg-slate-100 hover:text-slate-900"
aria-label="Close"
>
<X className="h-4 w-4" aria-hidden />
</Dialog.Close>
</header>
<div className="min-h-0 flex-1 overflow-y-auto px-5 py-4">
<dl className="flex flex-col gap-4">
{record.fields.map((field) => (
<div key={field.label}>
<SectionLabel as="dt">{field.label}</SectionLabel>
<dd className="mt-1 text-sm font-semibold text-slate-900">{field.value}</dd>
</div>
))}
{record.message ? (
<div>
<SectionLabel as="dt">{messageLabel}</SectionLabel>
<dd className="mt-1 whitespace-pre-line text-sm leading-relaxed text-slate-800">
{record.message}
</dd>
</div>
) : null}
</dl>
<section className="mt-6" aria-label={notesLabel}>
<SectionLabel as="h3">{notesLabel}</SectionLabel>
<NoteBox placeholder={notePlaceholder} onSave={onAddNote} />
<ActivityTrail items={record.activity} />
</section>
</div>
<footer className="flex items-center justify-between gap-3 border-t border-slate-200 px-5 py-4">
<button
type="button"
onClick={onReply}
className="inline-flex h-10 shrink-0 items-center gap-2 whitespace-nowrap rounded-[12px] border border-slate-200 bg-white px-4 text-sm font-semibold text-slate-900 shadow-sm transition hover:bg-slate-50"
>
<Mail className="h-4 w-4" aria-hidden />
{replyLabel}
</button>
<NextStepButton steps={steps} current={step} next={next} onPick={onStepChange} />
</footer>
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>
);
}
// ── Pieces ──────────────────────────────────────────────────────────────────
function SectionLabel({ as: As, children }: { as: 'dt' | 'h3'; children: React.ReactNode }) {
return (
<As className="text-[11px] font-bold uppercase tracking-[0.06em] text-slate-500">{children}</As>
);
}
/** A small menu anchored to its trigger; closes on outside click and Escape. */
function useMenu() {
const [open, setOpen] = React.useState(false);
const ref = React.useRef<HTMLDivElement>(null);
React.useEffect(() => {
if (!open) return;
function onDown(e: MouseEvent) {
if (!ref.current?.contains(e.target as Node)) setOpen(false);
}
function onKey(e: KeyboardEvent) {
// Stop here so Escape closes the menu, not the whole drawer.
if (e.key === 'Escape') {
e.stopPropagation();
setOpen(false);
}
}
document.addEventListener('mousedown', onDown);
document.addEventListener('keydown', onKey, true);
return () => {
document.removeEventListener('mousedown', onDown);
document.removeEventListener('keydown', onKey, true);
};
}, [open]);
return { open, setOpen, ref };
}
function StepList({
steps,
currentId,
onPick,
className,
}: {
steps: DrawerStep[];
currentId: string;
onPick: (id: string) => void;
className: string;
}) {
return (
<div role="menu" className={className}>
{steps.map((s) => (
<button
key={s.id}
type="button"
role="menuitemradio"
aria-checked={s.id === currentId}
onClick={() => onPick(s.id)}
className="flex w-full items-center gap-2 rounded-[8px] px-2.5 py-2 text-left text-sm text-slate-800 hover:bg-slate-100"
>
<span className={`h-2 w-2 shrink-0 rounded-full ${s.tone.split(' ')[0]}`} aria-hidden />
<span className="flex-1">{s.label}</span>
{s.id === currentId ? <Check className="h-4 w-4 text-slate-500" aria-hidden /> : null}
</button>
))}
</div>
);
}
function StepMenu({
steps,
current,
onPick,
}: {
steps: DrawerStep[];
current: DrawerStep;
onPick: (id: string) => void;
}) {
const { open, setOpen, ref } = useMenu();
return (
<div ref={ref} className="relative">
<button
type="button"
aria-haspopup="menu"
aria-expanded={open}
aria-label={`Step: ${current.label}. Change step`}
onClick={() => setOpen((v) => !v)}
className={`inline-flex items-center gap-1 rounded-full px-2.5 py-0.5 text-xs font-bold ${current.tone}`}
>
{current.label}
<ChevronDown className="h-3 w-3" aria-hidden />
</button>
{open ? (
<StepList
steps={steps}
currentId={current.id}
onPick={(id) => {
onPick(id);
setOpen(false);
}}
className="absolute left-0 top-full z-10 mt-1 w-48 rounded-[12px] border border-slate-200 bg-white p-1 shadow-lg"
/>
) : null}
</div>
);
}
function NextStepButton({
steps,
current,
next,
onPick,
}: {
steps: DrawerStep[];
current: DrawerStep;
next?: DrawerStep;
onPick: (id: string) => void;
}) {
const { open, setOpen, ref } = useMenu();
return (
<div ref={ref} className="relative flex min-w-0">
<button
type="button"
disabled={!next}
onClick={() => next && onPick(next.id)}
className="inline-flex h-10 min-w-0 items-center gap-2 whitespace-nowrap rounded-l-[12px] bg-slate-900 pl-4 pr-3.5 text-sm font-semibold text-white transition hover:bg-slate-800 disabled:opacity-60"
>
<Check className="h-4 w-4 shrink-0" aria-hidden />
<span className="truncate">{next ? `Move to ${next.label}` : current.label}</span>
</button>
<button
type="button"
aria-haspopup="menu"
aria-expanded={open}
aria-label="Move to another step"
onClick={() => setOpen((v) => !v)}
className="inline-flex h-10 w-10 shrink-0 items-center justify-center rounded-r-[12px] border-l border-white/20 bg-slate-900 text-white transition hover:bg-slate-800"
>
<ChevronDown className="h-4 w-4" aria-hidden />
</button>
{open ? (
<StepList
steps={steps}
currentId={current.id}
onPick={(id) => {
onPick(id);
setOpen(false);
}}
className="absolute bottom-full right-0 z-10 mb-1 w-52 rounded-[12px] border border-slate-200 bg-white p-1 shadow-lg"
/>
) : null}
</div>
);
}
function Labels({
labels,
onAdd,
onRemove,
}: {
labels: string[];
onAdd?: (label: string) => void;
onRemove?: (label: string) => void;
}) {
const [adding, setAdding] = React.useState(false);
const [value, setValue] = React.useState('');
function commit() {
const label = value.trim();
if (label && !labels.includes(label)) onAdd?.(label);
setValue('');
setAdding(false);
}
return (
<div className="mt-2.5 flex flex-wrap items-center gap-1.5">
{labels.map((label) => (
<span
key={label}
className="inline-flex items-center gap-1 rounded-full bg-slate-100 py-0.5 pl-2.5 pr-1 text-xs font-semibold text-slate-700"
>
<Tag className="h-3 w-3 text-slate-400" aria-hidden />
{label}
{onRemove ? (
<button
type="button"
onClick={() => onRemove(label)}
aria-label={`Remove label ${label}`}
className="rounded-full p-0.5 hover:bg-slate-300/60"
>
<X className="h-3 w-3" aria-hidden />
</button>
) : null}
</span>
))}
{onAdd ? (
adding ? (
<input
autoFocus
value={value}
onChange={(e) => setValue(e.target.value)}
onBlur={commit}
onKeyDown={(e) => {
if (e.key === 'Enter') commit();
if (e.key === 'Escape') {
// Close the field, not the drawer.
e.stopPropagation();
setValue('');
setAdding(false);
}
}}
placeholder="Label name"
aria-label="New label"
className="h-7 w-32 rounded-full border border-slate-300 px-2.5 text-xs outline-none focus:border-lime-500 focus:ring-2 focus:ring-lime-500/30"
/>
) : (
<button
type="button"
onClick={() => setAdding(true)}
className="inline-flex h-7 items-center gap-1 rounded-full px-2 text-xs font-semibold text-slate-700 hover:bg-slate-100"
>
<Plus className="h-3.5 w-3.5" aria-hidden />
Add label
</button>
)
) : null}
</div>
);
}
function NoteBox({ placeholder, onSave }: { placeholder: string; onSave?: (text: string) => void }) {
const [text, setText] = React.useState('');
const id = React.useId();
if (!onSave) return null;
function save() {
const note = text.trim();
if (!note) return;
onSave?.(note);
setText('');
}
return (
<div className="mt-2">
<label htmlFor={id} className="sr-only">
{placeholder}
</label>
<textarea
id={id}
value={text}
onChange={(e) => setText(e.target.value)}
onKeyDown={(e) => {
if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) {
e.preventDefault();
save();
}
}}
rows={3}
placeholder={placeholder}
className="block w-full resize-y rounded-[12px] border border-slate-200 px-3 py-2.5 text-sm text-slate-900 outline-none transition placeholder:text-slate-400 focus:border-lime-500 focus:ring-2 focus:ring-lime-500/30"
/>
<div className="mt-2 flex justify-end">
<button
type="button"
onClick={save}
disabled={!text.trim()}
className="inline-flex h-9 items-center gap-1.5 rounded-[10px] bg-slate-900 px-3.5 text-sm font-semibold text-white transition hover:bg-slate-800 disabled:bg-slate-400"
>
<Check className="h-4 w-4" aria-hidden />
Save note
</button>
</div>
</div>
);
}
function ActivityTrail({ items }: { items: DrawerActivity[] }) {
if (items.length === 0) return null;
return (
<ol className="mt-3 border-l border-slate-200 pl-3">
{items.map((item) => (
<li key={item.id} className="py-1.5">
{item.isNote ? (
<div className="rounded-[10px] bg-slate-50 px-3 py-2">
<p className="whitespace-pre-line text-sm text-slate-800">{item.text}</p>
<p className="mt-1 text-xs text-slate-500">{item.when}</p>
</div>
) : (
<p className="text-xs text-slate-500">
{item.text} · {item.when}
</p>
)}
</li>
))}
</ol>
);
}
const DRAWER_KEYFRAMES = `
@keyframes recordDrawerIn {
from { opacity: 0; transform: translateX(16px) scale(0.98); }
to { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes recordDrawerFade {
from { opacity: 0; }
to { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
@keyframes recordDrawerIn { from { opacity: 1; } to { opacity: 1; } }
@keyframes recordDrawerFade { from { opacity: 1; } to { opacity: 1; } }
}
`;
// ── Demo ────────────────────────────────────────────────────────────────────
const DEMO_STEPS: DrawerStep[] = [
{ id: 'new', label: 'New', tone: 'bg-sky-100 text-sky-800' },
{ id: 'progress', label: 'In progress', tone: 'bg-amber-100 text-amber-800' },
{ id: 'waiting', label: 'Waiting on them', tone: 'bg-violet-100 text-violet-800' },
{ id: 'done', label: 'Done', tone: 'bg-emerald-100 text-emerald-800' },
];
const DEMO_RECORD: DrawerRecord = {
title: 'Dana Whitfield',
stepId: 'new',
stepSince: 'since today',
subtitle: 'Received Nov 17, 2026, 9:12 AM · via the contact form',
labels: [],
fields: [{ label: 'Topic', value: 'Training and courses' }],
message:
'Hello,\n\nI would like to enrol in the free Workplace First Aid online course.\n\nCould you confirm:\n\n1. Is the certificate of completion free?\n2. Does the certificate show the course length?\n3. Can you send the syllabus for my employer?\n\nThank you.',
activity: [
{ id: 'a2', text: 'First opened by the team', when: 'Nov 17, 2026, 10:04 AM' },
{ id: 'a1', text: 'Received from the contact form', when: 'Nov 17, 2026, 9:12 AM' },
],
};
/**
* A self-contained harness: a two-row inbox list that opens the drawer. It is
* what the /ui preview shows and doubles as the wiring the header describes.
*/
export function RecordDrawerDemo() {
const [open, setOpen] = React.useState(false);
const [record, setRecord] = React.useState<DrawerRecord>(DEMO_RECORD);
const step = DEMO_STEPS.find((s) => s.id === record.stepId) ?? DEMO_STEPS[0];
function now() {
return new Date().toLocaleString('en-US', {
month: 'short',
day: 'numeric',
year: 'numeric',
hour: 'numeric',
minute: '2-digit',
});
}
return (
<div className="mx-auto w-full max-w-2xl">
<h3 className="mb-3 text-base font-bold text-slate-900">Enquiries</h3>
<ul className="divide-y divide-slate-200 overflow-hidden rounded-[12px] border border-slate-200 bg-white">
<li>
<button
type="button"
onClick={() => setOpen(true)}
className="flex w-full items-center gap-4 px-4 py-3 text-left hover:bg-slate-50"
>
<span className="w-16 shrink-0 text-xs text-slate-500">Nov 17</span>
<span className="min-w-0 flex-1">
<span className="block truncate text-sm font-semibold text-slate-900">{record.title}</span>
<span className="block truncate text-xs text-slate-500">
I would like to enrol in the free Workplace First Aid online course.
</span>
</span>
<span className={`shrink-0 rounded-full px-2.5 py-0.5 text-xs font-bold ${step.tone}`}>
{step.label}
</span>
</button>
</li>
<li className="flex items-center gap-4 px-4 py-3">
<span className="w-16 shrink-0 text-xs text-slate-500">Nov 16</span>
<span className="min-w-0 flex-1">
<span className="block truncate text-sm font-semibold text-slate-900">Ravi Menon</span>
<span className="block truncate text-xs text-slate-500">Quote request: on-site fire warden training</span>
</span>
<span className="shrink-0 rounded-full bg-violet-100 px-2.5 py-0.5 text-xs font-bold text-violet-800">
Waiting on them
</span>
</li>
</ul>
<p className="mt-2 text-xs text-slate-500">Open the first row to see the drawer.</p>
<RecordDrawer
open={open}
onOpenChange={setOpen}
record={record}
steps={DEMO_STEPS}
onStepChange={(stepId) => {
const label = DEMO_STEPS.find((s) => s.id === stepId)?.label ?? stepId;
setRecord((r) => ({
...r,
stepId,
stepSince: 'since just now',
activity: [{ id: crypto.randomUUID(), text: `Moved to ${label}`, when: now() }, ...r.activity],
}));
}}
onAddLabel={(label) => setRecord((r) => ({ ...r, labels: [...r.labels, label] }))}
onRemoveLabel={(label) => setRecord((r) => ({ ...r, labels: r.labels.filter((l) => l !== label) }))}
onAddNote={(text) =>
setRecord((r) => ({
...r,
activity: [{ id: crypto.randomUUID(), text, when: now(), isNote: true }, ...r.activity],
}))
}
onReply={() => {
window.location.href = 'mailto:dana@example.com';
}}
/>
</div>
);
}
Dependencies
@radix-ui/react-dialog— npm packagelucide-react— npm package
Colours
Colours come from CSS variables (--background, --primary, --border) using the shadcn/ui token names, so the block adopts your palette rather than importing ours.
21 more blocks.
Headers, footers, dialogs, pickers and toasts, all in the same style.