User Admin Table
User admin table for React: avatars, inline role menu, status pills, filter chips and a hover actions menu.
- Tables
- SaaS
- React only · 0 deps
- 1 file
Install. One command, or copy the file.
$
npx shadcn@latest add https://freedesignmd.com/r/user-admin-table.json- Byte-identical to the preview
- No Tailwind or config needed
- SSR-safe · keyboard accessible
- Respects reduced motion & transparency
components/tables/user-admin-table.tsx
1/**2 * UserAdminTable, a team-admin table: photo avatars (initials fallback) with a presence dot,3 * an inline role dropdown, status pills, search plus filter chips, and a row4 * actions menu that appears on hover or focus.5 *6 * Props: users, roles, onRoleChange(id, role), onAction(id, action),7 * theme. Actions: "edit" | "resend" | "suspend" | "reactivate" | "remove".8 * Controlled data: pass `users` and update it from the callbacks.9 *10 * Browser support: all evergreen browsers. Popovers use position: fixed so they11 * escape the scroll container; they close on scroll and resize.12 * Accessibility: native table semantics; the role trigger is a menu button13 * (aria-haspopup="menu", aria-expanded) opening a menuitemradio group; the14 * actions trigger is a labelled menu button. Arrow keys / Home / End move,15 * Enter or Space selects, Escape closes and returns focus, Tab closes.16 * Filter chips are toggle buttons (aria-pressed) with counts; results are17 * announced in a polite live region. Row actions stay visible on touch and18 * whenever focus is inside the row.19 * Reduced motion: popovers fade without movement.20 * Demo images: /img/people/pN.webp (in the repo's public/img/people, copy next to your page or swap in your own).21 * Set `avatar` on a user to show a photo; without it the initials badge shows.22 */23import { useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";24 25export type UserStatus = "active" | "invited" | "suspended";26export interface AdminUser {27 id: string;28 name: string;29 email: string;30 role: string;31 status: UserStatus;32 lastActive: string;33 /** Optional photo URL; falls back to initials. */34 avatar?: string;35}36export type UserAction = "edit" | "resend" | "suspend" | "reactivate" | "remove";37 38export interface UserAdminTableProps {39 users: AdminUser[];40 roles?: { id: string; label: string; hint: string }[];41 onRoleChange?: (id: string, role: string) => void;42 onAction?: (id: string, action: UserAction) => void;43 theme?: "light" | "dark";44 className?: string;45}46 47const DEFAULT_ROLES = [48 { id: "owner", label: "Owner", hint: "Full access, billing and deletion" },49 { id: "admin", label: "Admin", hint: "Manage members and settings" },50 { id: "member", label: "Member", hint: "Create and edit projects" },51 { id: "viewer", label: "Viewer", hint: "Read-only access" },52];53 54const hue = (s: string) => {55 let h = 0;56 for (const c of s) h = (h * 31 + c.charCodeAt(0)) % 360;57 return h;58};59const initials = (n: string) => n.split(/\s+/).map((p) => p[0]).slice(0, 2).join("").toUpperCase();60const STATUS = { active: "Active", invited: "Invited", suspended: "Suspended" } as const;61 62type Pop = { id: string; kind: "role" | "actions"; x: number; y: number; w: number; up: boolean } | null;63 64/** Tracks whether the table's own container is narrow, so hidden columns are not rendered at all (keeps colSpan rows correct). */65function useNarrow(max: number) {66 const ref = useRef<HTMLDivElement>(null);67 const [narrow, setNarrow] = useState(false);68 useEffect(() => {69 const el = ref.current;70 if (!el || typeof ResizeObserver === "undefined") return;71 const f = () => setNarrow(el.clientWidth <= max);72 f();73 const ro = new ResizeObserver(f);74 ro.observe(el);75 return () => ro.disconnect();76 }, [max]);77 return [ref, narrow] as const;78}79export function UserAdminTable({ users, roles = DEFAULT_ROLES, onRoleChange, onAction, theme, className }: UserAdminTableProps) {80 const uid = useId();81 const [cardRef, narrow] = useNarrow(640);82 const [q, setQ] = useState("");83 const [filter, setFilter] = useState<"all" | UserStatus | "admins">("all");84 const [pop, setPop] = useState<Pop>(null);85 const trigger = useRef<HTMLElement | null>(null);86 const menu = useRef<HTMLDivElement>(null);87 88 const counts = useMemo(89 () => ({90 all: users.length,91 admins: users.filter((u) => u.role === "owner" || u.role === "admin").length,92 active: users.filter((u) => u.status === "active").length,93 invited: users.filter((u) => u.status === "invited").length,94 suspended: users.filter((u) => u.status === "suspended").length,95 }),96 [users],97 );98 99 const rows = useMemo(() => {100 const t = q.trim().toLowerCase();101 return users.filter((u) => {102 if (filter === "admins" ? !(u.role === "owner" || u.role === "admin") : filter !== "all" && u.status !== filter) return false;103 return !t || (u.name + " " + u.email).toLowerCase().includes(t);104 });105 }, [users, q, filter]);106 107 const close = useCallback((restore = true) => {108 setPop(null);109 if (restore) requestAnimationFrame(() => trigger.current?.focus());110 }, []);111 112 const open = (e: React.MouseEvent<HTMLButtonElement> | React.KeyboardEvent<HTMLButtonElement>, id: string, kind: "role" | "actions", h: number) => {113 const el = e.currentTarget;114 trigger.current = el;115 if (pop && pop.id === id && pop.kind === kind) return close();116 const r = el.getBoundingClientRect();117 const w = kind === "role" ? 264 : 232;118 const up = window.innerHeight - r.bottom < h + 16 && r.top > h + 16;119 const x = Math.max(8, Math.min(kind === "role" ? r.left : r.right - w, window.innerWidth - w - 8));120 setPop({ id, kind, x, y: up ? r.top - 6 : r.bottom + 6, w, up });121 };122 123 useEffect(() => {124 if (!pop) return;125 const items = () => [...(menu.current?.querySelectorAll<HTMLElement>("[role^=menuitem]") ?? [])];126 const cur = items().find((i) => i.getAttribute("aria-checked") === "true") ?? items()[0];127 cur?.focus();128 const dismiss = (e: Event) => {129 if (!menu.current?.contains(e.target as Node) && !trigger.current?.contains(e.target as Node)) setPop(null);130 };131 const away = () => setPop(null);132 document.addEventListener("pointerdown", dismiss);133 window.addEventListener("resize", away);134 window.addEventListener("scroll", away, true);135 return () => {136 document.removeEventListener("pointerdown", dismiss);137 window.removeEventListener("resize", away);138 window.removeEventListener("scroll", away, true);139 };140 }, [pop?.id, pop?.kind]); // eslint-disable-line react-hooks/exhaustive-deps141 142 useLayoutEffect(() => {143 // the menu measures after mount: if it would overflow the bottom, nudge up144 const m = menu.current;145 if (!m || !pop || pop.up) return;146 const r = m.getBoundingClientRect();147 if (r.bottom > window.innerHeight - 8) m.style.top = `${Math.max(8, window.innerHeight - r.height - 8)}px`;148 }, [pop]);149 150 const onMenuKey = (e: React.KeyboardEvent) => {151 const list = [...(menu.current?.querySelectorAll<HTMLElement>("[role^=menuitem]:not([disabled])") ?? [])];152 const i = list.indexOf(document.activeElement as HTMLElement);153 const go = (n: number) => (list[(n + list.length) % list.length] as HTMLElement).focus();154 if (e.key === "ArrowDown") { e.preventDefault(); go(i + 1); }155 else if (e.key === "ArrowUp") { e.preventDefault(); go(i - 1); }156 else if (e.key === "Home") { e.preventDefault(); go(0); }157 else if (e.key === "End") { e.preventDefault(); go(list.length - 1); }158 else if (e.key === "Escape") { e.preventDefault(); e.stopPropagation(); close(); }159 else if (e.key === "Tab") close(false);160 };161 162 const target = pop ? users.find((u) => u.id === pop.id) : undefined;163 const run = (a: UserAction) => {164 if (!target) return;165 onAction?.(target.id, a);166 close(a !== "remove");167 };168 169 const chips: { id: typeof filter; label: string }[] = [170 { id: "all", label: "All" },171 { id: "admins", label: "Admins" },172 { id: "active", label: "Active" },173 { id: "invited", label: "Invited" },174 { id: "suspended", label: "Suspended" },175 ];176 177 return (178 <div className={`fd-ua${className ? " " + className : ""}`} data-fd-theme={theme}>179 <style>{css}</style>180 <div className="fd-ua-tools">181 <label className="fd-ua-search">182 <svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" aria-hidden="true"><circle cx="7" cy="7" r="4.5" /><path d="M10.5 10.5L14 14" /></svg>183 <input type="search" value={q} onChange={(e) => setQ(e.target.value)} placeholder="Search by name or email" aria-label="Search members" />184 </label>185 <div className="fd-ua-chips" role="group" aria-label="Filter members">186 {chips.map((c) => (187 <button key={c.id} type="button" className="fd-ua-chip" aria-pressed={filter === c.id} onClick={() => setFilter(c.id)}>188 {c.label}<span>{counts[c.id]}</span>189 </button>190 ))}191 </div>192 </div>193 194 <div className="fd-ua-card" ref={cardRef}>195 <div className="fd-ua-scroll" role="region" aria-label="Team members, scrollable" tabIndex={0}>196 <table className="fd-ua-table">197 <caption className="fd-ua-sr">Team members</caption>198 <thead>199 <tr>200 <th scope="col" className="fd-ua-th">Member</th>201 <th scope="col" className="fd-ua-th" style={{ width: 176 }}>Role</th>202 {!narrow && <th scope="col" className="fd-ua-th" style={{ width: 128 }}>Status</th>}203 {!narrow && <th scope="col" className="fd-ua-th" style={{ width: 128 }}>Last active</th>}204 <th scope="col" className="fd-ua-th" style={{ width: 56 }}><span className="fd-ua-sr">Actions</span></th>205 </tr>206 </thead>207 <tbody>208 {rows.map((u) => {209 const rl = roles.find((r) => r.id === u.role);210 const isOpen = pop?.id === u.id;211 return (212 <tr key={u.id} className="fd-ua-row" data-open={isOpen ? "" : undefined} data-s={u.status}>213 <td className="fd-ua-td">214 <div className="fd-ua-who">215 <span className="fd-ua-av" style={{ ["--h" as string]: hue(u.name) }} aria-hidden="true">216 {u.avatar ? <img src={u.avatar} alt="" width={36} height={36} loading="lazy" decoding="async" /> : initials(u.name)}217 <i className="fd-ua-dot" data-s={u.status} />218 </span>219 <span className="fd-ua-nm"><b>{u.name}</b><small>{u.email}</small></span>220 </div>221 </td>222 <td className="fd-ua-td">223 <button224 type="button"225 className="fd-ua-role"226 aria-haspopup="menu"227 aria-expanded={isOpen && pop?.kind === "role"}228 aria-label={`Role for ${u.name}: ${rl?.label}. Change role`}229 disabled={u.role === "owner"}230 onClick={(e) => open(e, u.id, "role", roles.length * 52 + 12)}231 onKeyDown={(e) => { if (e.key === "ArrowDown") { e.preventDefault(); open(e, u.id, "role", roles.length * 52 + 12); } }}232 >233 <span>{rl?.label ?? u.role}</span>234 {u.role !== "owner" && <svg width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M3 4.5l3 3 3-3" /></svg>}235 </button>236 </td>237 {!narrow && <td className="fd-ua-td"><span className="fd-ua-pill" data-s={u.status}><i />{STATUS[u.status]}</span></td>}238 {!narrow && <td className="fd-ua-td fd-ua-mut">{u.lastActive}</td>}239 <td className="fd-ua-td fd-ua-end">240 <button241 type="button"242 className="fd-ua-more"243 aria-haspopup="menu"244 aria-expanded={isOpen && pop?.kind === "actions"}245 aria-label={`Actions for ${u.name}`}246 onClick={(e) => open(e, u.id, "actions", 5 * 40 + 16)}247 onKeyDown={(e) => { if (e.key === "ArrowDown") { e.preventDefault(); open(e, u.id, "actions", 5 * 40 + 16); } }}248 >249 <svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true"><circle cx="3.5" cy="8" r="1.3" /><circle cx="8" cy="8" r="1.3" /><circle cx="12.5" cy="8" r="1.3" /></svg>250 </button>251 </td>252 </tr>253 );254 })}255 {rows.length === 0 && (256 <tr>257 <td className="fd-ua-empty" colSpan={narrow ? 3 : 5}>258 <svg width="36" height="36" viewBox="0 0 36 36" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><circle cx="14" cy="13" r="5" /><path d="M5 29c1-5 5-8 9-8s8 3 9 8M24 10c3 0 5 2 5 5M26 21c3 .8 5 3 6 6" /></svg>259 <b>No members found</b>260 <span>{q ? `Nobody matches “${q}”.` : "No one has this status yet."}</span>261 <button type="button" className="fd-ua-reset" onClick={() => { setQ(""); setFilter("all"); }}>Reset filters</button>262 </td>263 </tr>264 )}265 </tbody>266 </table>267 </div>268 <div className="fd-ua-foot"><span>Showing <b>{rows.length}</b> of {users.length} members</span></div>269 </div>270 <div className="fd-ua-sr" role="status" aria-live="polite">{`${rows.length} ${rows.length === 1 ? "member" : "members"} shown`}</div>271 272 {pop && target && (273 <div274 ref={menu}275 id={`${uid}-menu`}276 role="menu"277 aria-label={pop.kind === "role" ? `Role for ${target.name}` : `Actions for ${target.name}`}278 className="fd-ua-menu"279 data-fd-theme={theme}280 data-up={pop.up ? "" : undefined}281 style={{ left: pop.x, top: pop.up ? undefined : pop.y, bottom: pop.up ? window.innerHeight - pop.y : undefined, width: pop.w }}282 onKeyDown={onMenuKey}283 >284 {pop.kind === "role" ? (285 roles.map((r) => (286 <button287 key={r.id}288 type="button"289 role="menuitemradio"290 aria-checked={r.id === target.role}291 className="fd-ua-mi fd-ua-mi-role"292 disabled={r.id === "owner"}293 onClick={() => { onRoleChange?.(target.id, r.id); close(); }}294 >295 <span className="fd-ua-mt"><b>{r.label}</b><small>{r.hint}</small></span>296 <svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M3.5 8.5l3 3 6-7" /></svg>297 </button>298 ))299 ) : (300 <>301 <button type="button" role="menuitem" className="fd-ua-mi" onClick={() => run("edit")}>302 <svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M2.5 13.5l.7-3L10.8 3a1.4 1.4 0 012 2l-7.6 7.6z" /></svg>Edit profile303 </button>304 {target.status === "invited" && (305 <button type="button" role="menuitem" className="fd-ua-mi" onClick={() => run("resend")}>306 <svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><rect x="2" y="3.5" width="12" height="9" rx="2" /><path d="M2.5 5l5.5 4 5.5-4" /></svg>Resend invite307 </button>308 )}309 {target.status !== "invited" && target.role !== "owner" && (310 <button type="button" role="menuitem" className="fd-ua-mi" onClick={() => run(target.status === "suspended" ? "reactivate" : "suspend")}>311 <svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><circle cx="8" cy="8" r="5.5" /><path d={target.status === "suspended" ? "M6.5 5.5v5l4-2.5z" : "M4.2 11.8l7.6-7.6"} /></svg>312 {target.status === "suspended" ? "Reactivate" : "Suspend access"}313 </button>314 )}315 {target.role !== "owner" && (316 <>317 <div className="fd-ua-sep" role="separator" />318 <button type="button" role="menuitem" className="fd-ua-mi" data-danger="" onClick={() => run("remove")}>319 <svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M2.5 4.5h11M6 4.5V3a1 1 0 011-1h2a1 1 0 011 1v1.5M4 4.5l.6 8a1 1 0 001 .9h4.8a1 1 0 001-.9l.6-8" /></svg>Remove from workspace320 </button>321 </>322 )}323 </>324 )}325 </div>326 )}327 </div>328 );329}330 331const css = `332:where(.fd-ua,.fd-ua *,.fd-ua-menu,.fd-ua-menu *){box-sizing:border-box;margin:0;padding:0;font:inherit;letter-spacing:inherit;color:inherit;text-decoration:none;list-style:none;border:0;background:none}333:where(.fd-ua,.fd-ua *,.fd-ua-menu,.fd-ua-menu *)::before,:where(.fd-ua,.fd-ua *,.fd-ua-menu,.fd-ua-menu *)::after{box-sizing:border-box}334:where(.fd-ua svg,.fd-ua-menu svg){display:block;flex-shrink:0}335:where(.fd-ua button,.fd-ua input,.fd-ua-menu button){appearance:none;-webkit-appearance:none;outline:0;border-radius:0;cursor:pointer}336:where(.fd-ua table){border-collapse:separate;border-spacing:0}337.fd-ua,.fd-ua-menu{338 --fd-ease-out:cubic-bezier(.22,1,.36,1);--fd-spring:cubic-bezier(.34,1.56,.64,1);--fd-dur-1:120ms;--fd-dur-2:240ms;--fd-dur-3:420ms;339 --u-bg:#fff;--u-head:#FAFAF9;--u-fg:#16151A;--u-mut:#6E6B78;--u-line:rgba(22,21,26,.08);--u-line2:rgba(22,21,26,.16);--u-hover:rgba(22,21,26,.03);--u-accent:#0F766E;--u-ring:rgba(15,118,110,.5);--u-pop:#fff;340 font:400 14px/20px ui-sans-serif,-apple-system,BlinkMacSystemFont,"SF Pro Text","Inter","Segoe UI",Roboto,sans-serif;letter-spacing:-.006em;color:var(--u-fg);-webkit-font-smoothing:antialiased}341[data-fd-theme="dark"].fd-ua,[data-fd-theme="dark"] .fd-ua,.fd-ua-menu[data-fd-theme="dark"]{--u-bg:#131217;--u-head:#17161C;--u-fg:#F3F2F6;--u-mut:#9F9CAB;--u-line:rgba(255,255,255,.07);--u-line2:rgba(255,255,255,.16);--u-hover:rgba(255,255,255,.035);--u-accent:#2DD4BF;--u-ring:rgba(45,212,191,.55);--u-pop:#1D1C23}342.fd-ua{width:100%}343.fd-ua-tools{display:flex;align-items:center;justify-content:space-between;gap:12px 16px;flex-wrap:wrap;margin-bottom:12px}344.fd-ua-search{position:relative;display:block;flex:1 1 240px;max-width:320px}345.fd-ua-search svg{position:absolute;left:12px;top:10px;color:var(--u-mut);pointer-events:none}346.fd-ua-search input{width:100%;height:36px;padding:0 12px 0 36px;border-radius:10px;background:var(--u-bg);box-shadow:0 0 0 1px var(--u-line2),0 1px 2px rgba(22,21,26,.04);font-size:14px;color:var(--u-fg);cursor:text;transition:box-shadow var(--fd-dur-1)}347.fd-ua-search input::placeholder{color:var(--u-mut)}348.fd-ua-search input:focus-visible{box-shadow:0 0 0 1.5px var(--u-accent),0 0 0 4px var(--u-ring)}349.fd-ua-chips{display:flex;gap:6px;flex-wrap:wrap}350.fd-ua-chip{display:inline-flex;align-items:center;gap:6px;height:32px;padding:0 12px;border-radius:9999px;font-size:13px;font-weight:500;line-height:1;color:var(--u-mut);box-shadow:inset 0 0 0 1px var(--u-line2);transition:background-color var(--fd-dur-1),color var(--fd-dur-1),box-shadow var(--fd-dur-1),transform var(--fd-dur-2) var(--fd-spring)}351.fd-ua-chip span{font-size:12px;font-variant-numeric:tabular-nums;opacity:.65}352@media (hover:hover){.fd-ua-chip:hover:not([aria-pressed=true]){color:var(--u-fg);background:var(--u-hover)}}353.fd-ua-chip:active{transform:scale(.96)}354.fd-ua-chip[aria-pressed=true]{background:var(--u-fg);color:var(--u-bg);box-shadow:none}355.fd-ua-chip:focus-visible,.fd-ua-role:focus-visible,.fd-ua-more:focus-visible,.fd-ua-reset:focus-visible{box-shadow:0 0 0 2px var(--u-bg),0 0 0 4px var(--u-ring)}356.fd-ua-card{border-radius:16px;background:var(--u-bg);overflow:hidden;box-shadow:0 0 0 1px var(--u-line),0 1px 2px rgba(22,21,26,.04),0 12px 32px -16px rgba(22,21,26,.12);container-type:inline-size}357.fd-ua-scroll{overflow-x:auto}.fd-ua-scroll:focus-visible{outline:2px solid var(--u-ring);outline-offset:-2px}358.fd-ua-table{width:100%;table-layout:fixed;min-width:520px}359.fd-ua-th{height:40px;padding:0 16px;background:var(--u-head);font-size:12px;line-height:16px;font-weight:500;color:var(--u-mut);text-align:left;box-shadow:inset 0 -1px 0 var(--u-line);white-space:nowrap}360.fd-ua-td{height:64px;padding:0 16px;border-bottom:1px solid var(--u-line);vertical-align:middle;white-space:nowrap;overflow:visible;transition:background-color var(--fd-dur-1)}361.fd-ua-row:last-child .fd-ua-td{border-bottom-color:transparent}362@media (hover:hover){.fd-ua-row:hover .fd-ua-td{background:var(--u-hover)}}363.fd-ua-row[data-open] .fd-ua-td{background:var(--u-hover)}364.fd-ua-row[data-s="suspended"] .fd-ua-nm,.fd-ua-row[data-s="suspended"] .fd-ua-av{opacity:.55}365.fd-ua-mut{color:var(--u-mut);font-variant-numeric:tabular-nums}366.fd-ua-who{display:flex;align-items:center;gap:12px;min-width:0}367.fd-ua-av img{position:absolute;inset:0;width:100%;height:100%;border-radius:50%;object-fit:cover;object-position:center top}368.fd-ua-av{position:relative;display:grid;place-items:center;flex:none;width:36px;height:36px;border-radius:50%;font-size:13px;font-weight:600;letter-spacing:0;color:hsl(var(--h) 50% 28%);background:hsl(var(--h) 70% 90%);box-shadow:inset 0 0 0 1px hsl(var(--h) 50% 40% / .12)}369[data-fd-theme="dark"] .fd-ua-av,[data-fd-theme="dark"].fd-ua .fd-ua-av{color:hsl(var(--h) 80% 85%);background:hsl(var(--h) 35% 24%)}370.fd-ua-dot{position:absolute;right:-1px;bottom:-1px;width:11px;height:11px;border-radius:50%;background:#16A34A;box-shadow:0 0 0 2px var(--u-bg)}371.fd-ua-dot[data-s="invited"]{background:#D97706}.fd-ua-dot[data-s="suspended"]{background:#9CA3AF}372.fd-ua-nm{display:flex;flex-direction:column;min-width:0}373.fd-ua-nm b{font-weight:500;overflow:hidden;text-overflow:ellipsis}374.fd-ua-nm small{font-size:13px;line-height:18px;color:var(--u-mut);overflow:hidden;text-overflow:ellipsis}375.fd-ua-role{display:inline-flex;align-items:center;gap:6px;height:32px;margin-left:-10px;padding:0 10px;border-radius:9px;font-size:14px;line-height:1;font-weight:500;transition:background-color var(--fd-dur-1),box-shadow var(--fd-dur-1)}376.fd-ua-role svg{color:var(--u-mut);transition:transform var(--fd-dur-2) var(--fd-ease-out)}377.fd-ua-role[aria-expanded=true] svg{transform:rotate(180deg)}378@media (hover:hover){.fd-ua-role:hover:not(:disabled){box-shadow:inset 0 0 0 1px var(--u-line2);background:var(--u-bg)}}379.fd-ua-role[aria-expanded=true]{box-shadow:inset 0 0 0 1px var(--u-line2);background:var(--u-bg)}380.fd-ua-role:disabled{cursor:default;color:var(--u-mut)}381.fd-ua-pill{display:inline-flex;align-items:center;gap:6px;height:24px;padding:0 10px 0 8px;border-radius:9999px;font-size:12px;font-weight:500;line-height:1;--c:#15803D;color:var(--c);background:color-mix(in srgb,var(--c) 11%,transparent)}382.fd-ua-pill i{width:6px;height:6px;border-radius:50%;background:currentColor}383.fd-ua-pill[data-s="invited"]{--c:#B45309}.fd-ua-pill[data-s="suspended"]{--c:#6B7280}384[data-fd-theme="dark"] .fd-ua-pill{--c:#4ADE80}[data-fd-theme="dark"] .fd-ua-pill[data-s="invited"]{--c:#FBBF24}[data-fd-theme="dark"] .fd-ua-pill[data-s="suspended"]{--c:#A1A1AA}385.fd-ua-end{text-align:right}386.fd-ua-more{display:inline-grid;place-items:center;width:32px;height:32px;border-radius:9px;color:var(--u-mut);opacity:0;transform:scale(.92);transition:opacity var(--fd-dur-2) var(--fd-ease-out),transform var(--fd-dur-3) var(--fd-spring),background-color var(--fd-dur-1),color var(--fd-dur-1)}387.fd-ua-row:hover .fd-ua-more,.fd-ua-row:focus-within .fd-ua-more,.fd-ua-more[aria-expanded=true]{opacity:1;transform:none}388.fd-ua-more:hover{background:var(--u-line);color:var(--u-fg)}389.fd-ua-more[aria-expanded=true]{background:var(--u-line);color:var(--u-fg)}390@media (hover:none){.fd-ua-more{opacity:1;transform:none}}391.fd-ua-empty{height:280px;text-align:center;color:var(--u-mut);padding:0}392.fd-ua-empty svg{margin:0 auto 12px;opacity:.7}393.fd-ua-empty b{display:block;font-size:15px;line-height:20px;font-weight:600;color:var(--u-fg)}394.fd-ua-empty span{display:block;margin-top:4px;font-size:13px}395.fd-ua-reset{margin-top:16px;height:32px;padding:0 12px;border-radius:9px;font-size:13px;font-weight:500;line-height:1;color:var(--u-fg);box-shadow:inset 0 0 0 1px var(--u-line2)}396.fd-ua-foot{display:flex;align-items:center;min-height:48px;padding:0 16px;border-top:1px solid var(--u-line);font-size:13px;color:var(--u-mut);font-variant-numeric:tabular-nums}.fd-ua-foot b{font-weight:500;color:var(--u-fg)}397.fd-ua-sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}398.fd-ua-menu{position:fixed;z-index:1000;padding:6px;border-radius:14px;background:var(--u-pop);box-shadow:0 0 0 1px var(--u-line2),0 2px 4px rgba(22,21,26,.06),0 16px 40px -8px rgba(22,21,26,.28);animation:fd-ua-in var(--fd-dur-2) var(--fd-ease-out);transform-origin:top left}399.fd-ua-menu[data-up]{transform-origin:bottom left}400.fd-ua-mi{white-space:nowrap;display:flex;align-items:center;gap:10px;width:100%;min-height:36px;padding:0 10px;border-radius:9px;text-align:left;font-size:14px;line-height:20px;font-weight:450;color:var(--u-fg);transition:background-color 80ms}401.fd-ua-mi svg{color:var(--u-mut)}402.fd-ua-mi:hover:not(:disabled),.fd-ua-mi:focus{background:var(--u-hover);background:color-mix(in srgb,var(--u-fg) 6%,transparent);outline:0}403.fd-ua-mi:disabled{opacity:.45;cursor:default}404.fd-ua-mi[data-danger],.fd-ua-mi[data-danger] svg{color:#C2271B}405[data-fd-theme="dark"].fd-ua-menu .fd-ua-mi[data-danger],[data-fd-theme="dark"].fd-ua-menu .fd-ua-mi[data-danger] svg{color:#FF8A7A}406.fd-ua-mi-role{min-height:52px;padding:6px 10px}407.fd-ua-mt{display:flex;flex-direction:column;flex:1;min-width:0}.fd-ua-mt b{font-weight:500}.fd-ua-mt small{font-size:12px;line-height:16px;color:var(--u-mut)}408.fd-ua-mi-role>svg{color:var(--u-accent);opacity:0;transform:scale(.6);transition:opacity var(--fd-dur-1),transform var(--fd-dur-2) var(--fd-spring)}409.fd-ua-mi-role[aria-checked=true]>svg{opacity:1;transform:none}410.fd-ua-sep{height:1px;margin:6px -6px;background:var(--u-line)}411@keyframes fd-ua-in{from{opacity:0;transform:translateY(-4px) scale(.97)}}412.fd-ua-menu[data-up]{animation-name:fd-ua-in-up}@keyframes fd-ua-in-up{from{opacity:0;transform:translateY(4px) scale(.97)}}413@container (max-width:640px){[data-nh]{display:none}.fd-ua-table{min-width:0}.fd-ua-th,.fd-ua-td{padding:0 12px}.fd-ua-th:nth-child(2){width:116px!important}.fd-ua-th:last-child{width:48px!important}.fd-ua-more{margin-right:-4px}}414@media (prefers-reduced-motion:reduce){.fd-ua *,.fd-ua-menu{transition-duration:1ms!important;animation:none!important}.fd-ua-more{transform:none}}415@media (prefers-contrast:more){.fd-ua-card{box-shadow:0 0 0 1px currentColor}}416`;417 418/* ───────────────────────────── demo ───────────────────────────── */419 420const SEED: AdminUser[] = [421 { id: "u1", name: "Priya Raman", email: "priya@parcelhq.com", role: "owner", status: "active", lastActive: "Just now", avatar: "/img/people/p6.webp" },422 { id: "u2", name: "Mateo Alvarez", email: "mateo@parcelhq.com", role: "admin", status: "active", lastActive: "12 min ago", avatar: "/img/people/p4.webp" },423 { id: "u3", name: "Hannah Okafor", email: "hannah.okafor@parcelhq.com", role: "member", status: "active", lastActive: "2 hours ago", avatar: "/img/people/p3.webp" },424 { id: "u4", name: "Jonas Lindqvist", email: "jonas@lindqvist.studio", role: "member", status: "invited", lastActive: "Never", avatar: "/img/people/p5.webp" },425 { id: "u5", name: "Kenji Tanabe", email: "kenji@parcelhq.com", role: "admin", status: "active", lastActive: "Yesterday", avatar: "/img/people/p8.webp" },426 { id: "u6", name: "Samira Haddad", email: "samira.haddad@parcelhq.com", role: "member", status: "active", lastActive: "Yesterday", avatar: "/img/people/p9.webp" },427 { id: "u7", name: "Devon Whitaker", email: "devon@whitakerlogistics.co", role: "viewer", status: "active", lastActive: "3 days ago", avatar: "/img/people/p2.webp" },428 { id: "u8", name: "Lucía Fernández", email: "lucia@parcelhq.com", role: "member", status: "suspended", lastActive: "Sep 14", avatar: "/img/people/p1.webp" },429 { id: "u9", name: "Tobias Reuter", email: "t.reuter@parcelhq.com", role: "viewer", status: "invited", lastActive: "Never", avatar: "/img/people/p7.webp" },430 { id: "u10", name: "Naledi Dlamini", email: "naledi@parcelhq.com", role: "member", status: "active", lastActive: "5 days ago", avatar: "/img/people/p6.webp" },431];432 433export function Demo() {434 const [theme, setTheme] = useState<"light" | "dark">("light");435 const [users, setUsers] = useState(SEED);436 const [note, setNote] = useState<{ text: string; undo?: () => void } | null>(null);437 const timer = useRef<number>(0);438 const say = (text: string, undo?: () => void) => {439 setNote({ text, undo });440 window.clearTimeout(timer.current);441 timer.current = window.setTimeout(() => setNote(null), 6000);442 };443 const seats = users.filter((u) => u.status !== "suspended").length;444 445 return (446 <div className="fd-uad" data-fd-theme={theme}>447 <style>{demoCss}</style>448 <aside className="fd-uad-side" aria-label="Workspace">449 <div className="fd-uad-ws"><span className="fd-uad-mark" aria-hidden="true">P</span><span><b>Parcel</b><small>Workspace</small></span></div>450 <nav aria-label="Settings">451 <a href="#general">General</a>452 <a href="#members" aria-current="page">Members</a>453 <a href="#billing">Billing</a>454 <a href="#integrations">Integrations</a>455 <a href="#security">Security</a>456 </nav>457 <button type="button" className="fd-uad-theme" aria-label={theme === "dark" ? "Switch to light theme" : "Switch to dark theme"} onClick={() => setTheme(theme === "dark" ? "light" : "dark")}>{theme === "dark" ? "Light" : "Dark"} theme</button>458 </aside>459 <main className="fd-uad-main">460 <header className="fd-uad-head">461 <div><h1>Members</h1><p>Control who can access Parcel and what they can do.</p></div>462 <button type="button" className="fd-uad-invite" onClick={() => say("Invite link copied to your clipboard.")}>463 <svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" aria-hidden="true"><path d="M8 3v10M3 8h10" /></svg>Invite member464 </button>465 </header>466 <div className="fd-uad-seats" role="group" aria-label="Seat usage">467 <div><b>{seats}</b> of 12 seats in use<small>Suspended members don’t use a seat.</small></div>468 <div className="fd-uad-meter" role="meter" aria-valuemin={0} aria-valuemax={12} aria-valuenow={seats} aria-label="Seats used"><i style={{ width: `${(seats / 12) * 100}%` }} /></div>469 </div>470 <UserAdminTable471 theme={theme}472 users={users}473 onRoleChange={(id, role) => {474 const u = users.find((x) => x.id === id)!;475 setUsers((p) => p.map((x) => (x.id === id ? { ...x, role } : x)));476 say(`${u.name} is now ${role === "admin" ? "an" : "a"} ${role}.`);477 }}478 onAction={(id, a) => {479 const u = users.find((x) => x.id === id)!;480 if (a === "remove") {481 const idx = users.findIndex((x) => x.id === id);482 setUsers((p) => p.filter((x) => x.id !== id));483 say(`Removed ${u.name} from Parcel.`, () => { setUsers((p) => { const n = [...p]; n.splice(idx, 0, u); return n; }); setNote(null); });484 } else if (a === "suspend" || a === "reactivate") {485 setUsers((p) => p.map((x) => (x.id === id ? { ...x, status: a === "suspend" ? "suspended" : "active" } : x)));486 say(`${u.name} was ${a === "suspend" ? "suspended" : "reactivated"}.`);487 } else if (a === "resend") say(`Invite re-sent to ${u.email}.`);488 else say(`Opened ${u.name}’s profile.`);489 }}490 />491 <div className="fd-uad-toast" data-open={note ? "" : undefined} role="status" aria-live="polite">492 {note && (<><span>{note.text}</span>{note.undo && <button type="button" onClick={note.undo}>Undo</button>}</>)}493 </div>494 </main>495 </div>496 );497}498 499const demoCss = `500:where(.fd-uad,.fd-uad *){box-sizing:border-box;margin:0;padding:0;font:inherit;letter-spacing:inherit;color:inherit;text-decoration:none;list-style:none;border:0;background:none}501:where(.fd-uad,.fd-uad *)::before,:where(.fd-uad,.fd-uad *)::after{box-sizing:border-box}502:where(.fd-uad svg){display:block;flex-shrink:0}503:where(.fd-uad button){appearance:none;-webkit-appearance:none;outline:0;border-radius:0;cursor:pointer}504.fd-uad{--fd-ease-out:cubic-bezier(.22,1,.36,1);--fd-spring:cubic-bezier(.34,1.56,.64,1);505 --d-bg:#F7F6F4;--d-side:#FBFAF9;--d-fg:#16151A;--d-mut:#6E6B78;--d-line:rgba(22,21,26,.08);--d-accent:#0F766E;--d-ring:rgba(15,118,110,.5);--d-card:#fff;506 display:grid;grid-template-columns:232px minmax(0,1fr);min-height:100vh;background:var(--d-bg);color:var(--d-fg);font:400 14px/20px ui-sans-serif,-apple-system,BlinkMacSystemFont,"SF Pro Text","Inter","Segoe UI",Roboto,sans-serif;letter-spacing:-.006em;-webkit-font-smoothing:antialiased}507.fd-uad[data-fd-theme="dark"]{--d-bg:#0D0C10;--d-side:#111015;--d-fg:#F3F2F6;--d-mut:#9F9CAB;--d-line:rgba(255,255,255,.07);--d-accent:#2DD4BF;--d-ring:rgba(45,212,191,.55);--d-card:#131217}508.fd-uad-side{display:flex;flex-direction:column;gap:20px;padding:16px 12px;background:var(--d-side);box-shadow:inset -1px 0 0 var(--d-line)}509.fd-uad-ws{display:flex;align-items:center;gap:10px;padding:4px 8px}510.fd-uad-mark{display:grid;place-items:center;width:28px;height:28px;border-radius:8px;background:var(--d-accent);color:var(--d-card);font-weight:700;font-size:14px}511.fd-uad-ws b{display:block;font-weight:600;line-height:16px}.fd-uad-ws small{display:block;font-size:12px;line-height:16px;color:var(--d-mut)}512.fd-uad-side nav{display:flex;flex-direction:column;gap:2px}513.fd-uad-side nav a{display:flex;align-items:center;height:32px;padding:0 10px;border-radius:8px;font-weight:500;color:var(--d-mut);transition:background-color 120ms,color 120ms}514.fd-uad-side nav a:hover{background:var(--d-line);color:var(--d-fg)}.fd-uad-side nav a[aria-current]{background:var(--d-line);color:var(--d-fg)}515.fd-uad a:focus-visible,.fd-uad-theme:focus-visible,.fd-uad-invite:focus-visible,.fd-uad-toast button:focus-visible{outline:2px solid var(--d-ring);outline-offset:2px}516.fd-uad-theme{margin-top:auto;height:32px;padding:0 10px;border-radius:8px;text-align:left;font-size:13px;font-weight:500;color:var(--d-mut)}.fd-uad-theme:hover{background:var(--d-line);color:var(--d-fg)}517.fd-uad-main{min-width:0;padding:32px clamp(16px,3vw,40px) 80px;max-width:1040px;width:100%}518.fd-uad-head{display:flex;align-items:flex-end;justify-content:space-between;gap:16px;flex-wrap:wrap}519.fd-uad-head h1{font-size:24px;line-height:32px;font-weight:600;letter-spacing:-.025em}.fd-uad-head p{margin-top:4px;color:var(--d-mut)}520.fd-uad-invite{display:inline-flex;align-items:center;gap:8px;height:36px;padding:0 14px;border-radius:10px;background:var(--d-accent);color:#fff;font-size:13px;font-weight:500;line-height:1;box-shadow:0 1px 2px rgba(15,118,110,.4),inset 0 1px 0 rgba(255,255,255,.18);transition:transform 240ms var(--fd-spring),filter 120ms}521.fd-uad[data-fd-theme="dark"] .fd-uad-invite{color:#042F2B}522.fd-uad-invite:hover{filter:brightness(1.08)}.fd-uad-invite:active{transform:scale(.97)}523.fd-uad-seats{display:flex;align-items:center;justify-content:space-between;gap:24px;margin:24px 0;padding:16px 20px;border-radius:14px;background:var(--d-card);box-shadow:0 0 0 1px var(--d-line)}524.fd-uad-seats b{font-weight:600;font-variant-numeric:tabular-nums}.fd-uad-seats small{display:block;font-size:13px;color:var(--d-mut)}525.fd-uad-meter{flex:0 1 220px;width:220px;height:8px;border-radius:9999px;background:var(--d-line);overflow:hidden}526.fd-uad-meter i{display:block;height:100%;border-radius:inherit;background:var(--d-accent);transition:width 420ms var(--fd-ease-out)}527.fd-uad-toast{position:fixed;left:50%;bottom:24px;z-index:900;display:flex;align-items:center;gap:16px;min-height:44px;padding:0 8px 0 16px;border-radius:12px;background:var(--d-fg);color:var(--d-bg);font-size:13px;font-weight:500;box-shadow:0 12px 32px -8px rgba(0,0,0,.4);opacity:0;visibility:hidden;transform:translate(-50%,12px);transition:opacity 240ms var(--fd-ease-out),transform 420ms var(--fd-ease-out),visibility 0s linear 420ms}528.fd-uad-toast[data-open]{opacity:1;visibility:visible;transform:translate(-50%,0);transition-delay:0s}529.fd-uad-toast button{height:28px;padding:0 10px;border-radius:8px;font-weight:600;color:inherit;background:rgba(127,127,127,.25)}530@media (max-width:820px){.fd-uad{grid-template-columns:1fr}.fd-uad-side{flex-direction:row;align-items:center;gap:12px;padding:10px 16px;box-shadow:inset 0 -1px 0 var(--d-line)}.fd-uad-side nav{display:none}.fd-uad-theme{margin:0 0 0 auto}.fd-uad-meter{display:none}.fd-uad-main{padding-top:24px}}531@media (prefers-reduced-motion:reduce){.fd-uad *{transition-duration:1ms!important}}532`;More Tables. Same file contract.
Questions about User Admin Table
Run npx shadcn@latest add https://freedesignmd.com/r/user-admin-table.json, or open the page and copy the file into your project. It has zero dependencies besides React. What you copy is the exact file that renders the live demo.
User admin table for React: avatars, inline role menu, status pills, filter chips and a hover actions menu. It is a free, MIT-licensed React tables component from the freedesignmd library.
Yes. It is free and MIT-licensed, use, modify and ship it in personal and commercial projects without attribution.
All evergreen browsers. Menus use position: fixed and close on scroll.
Yes. It is a plain React component with its own styles, so it runs in Next.js, Vite, Remix and Lovable projects, and it needs no Tailwind setup. It has zero dependencies besides React.


