Library MCP Setup About Template Factory ↗
← Library / Dashboard & Data UI SDK Agentic

Key-Value Detail Inspector Drawer

Slide-over UI SDK Drawer inspector: semantic <dl> metadata grid, editable status Select and notes Textarea, and a sticky footer with a tactile Copy ID button and a high-contrast Archive record button that confirms in an AlertDialog, then shows the archived state with Restore.

Install UI SDK & packages

npm install @ui-sdk/react @ui-sdk/core lucide-react

Give your agent the UI SDK skill

npx skills add vercel-labs/ui --skill ui-sdk

UI SDK entries: @ui-sdk/react/drawer @ui-sdk/react/field @ui-sdk/react/select @ui-sdk/react/textarea @ui-sdk/react/alert-dialog @ui-sdk/react/button
"use client";

import * as React from "react";
import { Archive, Check, ChevronDown, Copy, PanelRight, RotateCcw, TriangleAlert, X } from "lucide-react";
import {
  AlertDialog,
  AlertDialogBackdrop,
  AlertDialogClose,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@ui-sdk/react/alert-dialog";
import { Button } from "@ui-sdk/react/button";
import {
  Drawer,
  DrawerBackdrop,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerTitle,
  DrawerTrigger,
} from "@ui-sdk/react/drawer";
import { Field, FieldDescription, FieldLabel } from "@ui-sdk/react/field";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@ui-sdk/react/select";
import { Textarea } from "@ui-sdk/react/textarea";

const labelCls = "block text-[13px] font-semibold leading-snug text-slate-800 dark:text-slate-200";
const hintCls = "text-xs leading-relaxed text-slate-600 dark:text-slate-400";
const fieldBase =
  "w-full min-w-0 rounded-[10px] border-[1.5px] border-slate-300 bg-white text-sm font-medium text-slate-900 shadow-[0_1px_2px_rgba(15,23,42,0.06)] outline-none transition-[border-color,box-shadow] hover:border-slate-400 focus:border-sky-600 focus:ring-[3px] focus:ring-sky-600/25 dark:border-slate-400/35 dark:bg-[#182234] dark:text-slate-50 dark:shadow-[inset_0_1px_2px_rgba(0,0,0,0.35)] dark:hover:border-slate-400/55 dark:focus:border-sky-400 dark:focus:ring-sky-400/30";
const textareaCls = `${fieldBase} min-h-[124px] resize-y px-3.5 py-3 leading-relaxed`;
const btnBase =
  "inline-flex cursor-pointer items-center justify-center gap-2 whitespace-nowrap rounded-[10px] font-bold transition hover:-translate-y-px active:translate-y-px disabled:pointer-events-none disabled:opacity-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-500";
const btnMd = "h-11 px-4 text-sm";
const btnSm = "h-9 px-3 text-[13px]";
const btnGhost = `${btnBase} border border-slate-300 bg-linear-to-b from-white to-slate-100 text-slate-900 shadow-[inset_0_1px_0_rgba(255,255,255,0.95),inset_0_-1.5px_0_rgba(15,23,42,0.08),0_1px_2px_rgba(15,23,42,0.06)] hover:border-slate-400 dark:border-slate-400/35 dark:from-[#243047] dark:to-[#182234] dark:text-slate-50 dark:shadow-[inset_0_1px_0_rgba(255,255,255,0.09),inset_0_-1.5px_0_rgba(0,0,0,0.35)] dark:hover:border-slate-400/55`;
const btnDanger = `${btnBase} border border-red-200/45 bg-linear-to-b from-red-500 via-red-600 to-red-700 text-white shadow-[inset_0_1px_0_rgba(255,255,255,0.3),inset_0_-2px_0_rgba(127,29,29,0.55),0_8px_20px_rgba(220,38,38,0.32)] hover:brightness-110 focus-visible:outline-red-400`;
const btnDangerSoft = `${btnBase} border-[1.5px] border-red-300 bg-red-50 text-red-800 hover:border-red-700 hover:bg-red-600 hover:text-white dark:border-red-400/65 dark:bg-linear-to-b dark:from-red-600/30 dark:to-red-800/40 dark:text-rose-50 dark:hover:border-red-400 dark:hover:from-red-600 dark:hover:to-red-600 dark:hover:text-white focus-visible:outline-red-400`;

const hairline = "border-[#d8e0ea] dark:border-slate-400/20";
const mutedText = "text-slate-600 dark:text-slate-400";
const optionCls =
  "cursor-pointer rounded-lg px-3 py-2 text-sm font-medium text-slate-900 data-highlighted:bg-slate-100 dark:text-slate-50 dark:data-highlighted:bg-slate-400/15";

export interface DetailField {
  label: string;
  value: string;
  /** Monospace for IDs and codes only. */
  mono?: boolean;
}

export interface DetailRecord {
  id: string;
  title: string;
  status: string;
  notes?: string;
  fields: DetailField[];
}

export interface StatusOption {
  value: string;
  label: string;
  tone?: "info" | "good" | "warn" | "neutral";
}

const TONE_CLS: Record<NonNullable<StatusOption["tone"]>, string> = {
  info: "border-sky-600/35 bg-sky-50 text-sky-800 dark:border-sky-400/40 dark:bg-sky-400/15 dark:text-sky-300",
  good: "border-emerald-600/30 bg-emerald-50 text-emerald-800 dark:border-emerald-400/40 dark:bg-emerald-400/15 dark:text-emerald-300",
  warn: "border-amber-600/35 bg-amber-50 text-amber-800 dark:border-amber-400/45 dark:bg-amber-400/15 dark:text-amber-300",
  neutral: "border-slate-300 bg-slate-50 text-slate-700 dark:border-slate-400/35 dark:bg-[#162033] dark:text-slate-200",
};

const DEFAULT_STATUSES: StatusOption[] = [
  { value: "open", label: "Open", tone: "info" },
  { value: "planned", label: "Planned", tone: "warn" },
  { value: "in-progress", label: "In progress", tone: "info" },
  { value: "shipped", label: "Shipped", tone: "good" },
];

const DEFAULT_RECORD: DetailRecord = {
  id: "FB-418",
  title: "Add a keyboard shortcut to the preview",
  status: "open",
  notes: "",
  fields: [
    { label: "Product", value: "Template Factory" },
    { label: "Type", value: "Feature request" },
    { label: "Reported by", value: "Wynter Jones" },
    { label: "Source", value: "In-app feedback widget" },
    { label: "Received", value: "Dec 2, 2026" },
    { label: "Votes", value: "12" },
  ],
};

export function StructuredDetailPanel({
  record = DEFAULT_RECORD,
  statusOptions = DEFAULT_STATUSES,
  triggerLabel = "Inspect record",
  open,
  onOpenChange,
  onStatusChange,
  onNotesChange,
  onArchive,
  onRestore,
}: {
  record?: DetailRecord;
  statusOptions?: StatusOption[];
  triggerLabel?: string;
  /** Pass both to control the drawer yourself. */
  open?: boolean;
  onOpenChange?: (open: boolean) => void;
  onStatusChange?: (id: string, status: string) => void;
  onNotesChange?: (id: string, notes: string) => void;
  onArchive?: (id: string) => Promise<void> | void;
  onRestore?: (id: string) => void;
}) {
  const [status, setStatus] = React.useState(record.status);
  const [notes, setNotes] = React.useState(record.notes ?? "");
  const [archived, setArchived] = React.useState(false);
  const [copied, setCopied] = React.useState(false);
  const activeStatus = statusOptions.find((option) => option.value === status);

  const copyId = async () => {
    await navigator.clipboard?.writeText(record.id);
    setCopied(true);
    window.setTimeout(() => setCopied(false), 1600);
  };

  const restore = () => {
    setArchived(false);
    onRestore?.(record.id);
  };

  return (
    <Drawer side="right" open={open} onOpenChange={onOpenChange}>
      <DrawerTrigger className={`${btnGhost} ${btnMd}`}>
        <PanelRight className="size-4" aria-hidden="true" />
        <span>{triggerLabel}</span>
      </DrawerTrigger>
      <DrawerBackdrop className="fixed inset-0 bg-slate-900/40 dark:bg-black/65" />
      <DrawerContent className="flex h-dvh w-full max-w-md flex-col border-l border-slate-300 bg-white shadow-[0_24px_60px_rgba(15,23,42,0.2)] outline-none dark:border-slate-400/35 dark:bg-[#111827] dark:shadow-[0_28px_70px_rgba(0,0,0,0.62)]">
        <div className={`flex items-start justify-between gap-3 border-b px-5 py-4 ${hairline}`}>
          <div className="min-w-0">
            <div className="flex flex-wrap items-center gap-2">
              <span className="font-mono text-xs font-semibold text-slate-700 dark:text-slate-200">{record.id}</span>
              <span
                className={`inline-flex h-[22px] items-center whitespace-nowrap rounded-full border px-2 text-[11.5px] font-bold ${
                  archived ? TONE_CLS.neutral : TONE_CLS[activeStatus?.tone ?? "neutral"]
                }`}
              >
                {archived ? "Archived" : (activeStatus?.label ?? status)}
              </span>
            </div>
            <DrawerTitle className="mt-1.5 text-lg leading-snug font-bold tracking-tight text-balance text-slate-900 dark:text-slate-50">
              {record.title}
            </DrawerTitle>
            <DrawerDescription className="sr-only">Record details, status and internal notes.</DrawerDescription>
          </div>
          <DrawerClose aria-label="Close inspector" className={`${btnGhost} size-9 shrink-0`}>
            <X className="size-4" aria-hidden="true" />
          </DrawerClose>
        </div>

        <div className="flex min-h-0 flex-1 flex-col gap-5 overflow-y-auto px-5 py-5">
          {archived && (
            <div className="flex flex-wrap items-center justify-between gap-2.5 rounded-xl border border-amber-600/35 bg-amber-50 px-3.5 py-3 dark:border-amber-400/45 dark:bg-amber-400/15">
              <p className="flex min-w-0 items-center gap-2 text-[13px] font-semibold text-amber-900 dark:text-amber-200">
                <Archive className="size-4 shrink-0" aria-hidden="true" />
                <span>Archived. It's out of the open list.</span>
              </p>
              <Button aria-label="Restore record" onClick={restore} className={`${btnGhost} ${btnSm}`}>
                <RotateCcw className="size-3.5" aria-hidden="true" />
                <span>Restore</span>
              </Button>
            </div>
          )}

          <dl className="m-0 grid grid-cols-1 gap-x-5 gap-y-0.5 text-[13.5px] sm:grid-cols-[max-content_minmax(0,1fr)] sm:gap-y-2.5">
            {record.fields.map((field) => (
              <React.Fragment key={field.label}>
                <dt className={`text-[13px] ${mutedText}`}>{field.label}</dt>
                <dd
                  className={`m-0 min-w-0 font-semibold wrap-anywhere text-slate-900 max-sm:mb-2.5 dark:text-slate-50 ${
                    field.mono ? "font-mono text-[13px]" : ""
                  }`}
                >
                  {field.value}
                </dd>
              </React.Fragment>
            ))}
          </dl>

          <Field name="status" disabled={archived} className="flex flex-col gap-1.5">
            <FieldLabel className={labelCls}>Status</FieldLabel>
            <Select
              value={status}
              onValueChange={(next) => {
                if (!next) return;
                setStatus(next);
                onStatusChange?.(record.id, next);
              }}
            >
              <SelectTrigger
                className={`${fieldBase} flex h-11 cursor-pointer items-center justify-between gap-2 px-3.5 data-disabled:cursor-not-allowed data-disabled:opacity-50`}
              >
                <SelectValue />
                <ChevronDown className={`size-4 shrink-0 ${mutedText}`} aria-hidden="true" />
              </SelectTrigger>
              <SelectContent
                sideOffset={6}
                className="rounded-xl border border-[#d8e0ea] bg-white p-1 shadow-[0_18px_44px_rgba(15,23,42,0.18)] dark:border-slate-400/30 dark:bg-[#162033] dark:shadow-[0_24px_60px_rgba(0,0,0,0.6)]"
              >
                {statusOptions.map((option) => (
                  <SelectItem key={option.value} value={option.value} className={optionCls}>
                    {option.label}
                  </SelectItem>
                ))}
              </SelectContent>
            </Select>
          </Field>

          <Field name="notes" disabled={archived} className="flex flex-col gap-1.5">
            <FieldLabel className={labelCls}>Internal notes</FieldLabel>
            <FieldDescription className={hintCls}>Only your team sees these.</FieldDescription>
            <Textarea
              value={notes}
              onValueChange={(next) => {
                setNotes(next);
                onNotesChange?.(record.id, next);
              }}
              className={`${textareaCls} disabled:cursor-not-allowed disabled:opacity-50`}
            />
          </Field>
        </div>

        <div className={`flex items-center justify-between gap-2.5 border-t bg-slate-50 px-5 py-3.5 dark:bg-[#162033] ${hairline}`}>
          <Button onClick={copyId} className={`${btnGhost} ${btnMd} max-sm:flex-1`}>
            {copied ? <Check className="size-4" aria-hidden="true" /> : <Copy className="size-4" aria-hidden="true" />}
            <span>{copied ? "Copied" : "Copy ID"}</span>
          </Button>

          {archived ? (
            <Button onClick={restore} className={`${btnGhost} ${btnMd} max-sm:flex-1`}>
              <RotateCcw className="size-4" aria-hidden="true" />
              <span>Restore record</span>
            </Button>
          ) : (
            <AlertDialog>
              <AlertDialogTrigger className={`${btnDangerSoft} ${btnMd} max-sm:flex-1`}>
                <Archive className="size-4" aria-hidden="true" />
                <span>Archive record</span>
              </AlertDialogTrigger>
              <AlertDialogBackdrop className="fixed inset-0 bg-slate-900/40 backdrop-blur-xs dark:bg-black/65" />
              <AlertDialogContent className="fixed inset-0 m-auto h-fit w-[calc(100%-1.75rem)] max-w-md overflow-hidden rounded-2xl border border-slate-300 bg-white p-0 shadow-[0_24px_60px_rgba(15,23,42,0.2)] dark:border-slate-400/35 dark:bg-[#111827] dark:shadow-[0_28px_70px_rgba(0,0,0,0.62)]">
                <div className="flex gap-3.5 p-5">
                  <span className="grid size-10 shrink-0 place-items-center rounded-xl border border-red-300 bg-red-50 text-red-700 dark:border-red-400/45 dark:bg-red-400/15 dark:text-red-300">
                    <TriangleAlert className="size-5" aria-hidden="true" />
                  </span>
                  <div className="min-w-0">
                    <AlertDialogTitle className="text-[17px] font-bold tracking-tight text-slate-900 dark:text-slate-50">
                      Archive {record.id}?
                    </AlertDialogTitle>
                    <AlertDialogDescription className={`mt-1.5 text-[13.5px] leading-relaxed ${mutedText}`}>
                      It leaves the open list right away. You can restore it from Archived any time.
                    </AlertDialogDescription>
                  </div>
                </div>
                <div className={`flex flex-col-reverse gap-2.5 border-t bg-slate-50 px-5 py-3.5 sm:flex-row sm:justify-end dark:bg-[#162033] ${hairline}`}>
                  <AlertDialogClose className={`${btnGhost} ${btnMd}`}>Cancel</AlertDialogClose>
                  <AlertDialogClose
                    value="confirm"
                    data-agent-confirm="Moves this record out of the open list"
                    onClick={async () => {
                      await onArchive?.(record.id);
                      setArchived(true);
                    }}
                    className={`${btnDanger} ${btnMd}`}
                  >
                    <Archive className="size-4" aria-hidden="true" />
                    <span>Archive record</span>
                  </AlertDialogClose>
                </div>
              </AlertDialogContent>
            </AlertDialog>
          )}
        </div>
      </DrawerContent>
    </Drawer>
  );
}

export default StructuredDetailPanel;