opensourceui
GitHubTwitter/X
  1. Home
  2. Components
  3. Table
  4. Users Select Table
Back to Table

Components / Table

Users Select Table

Free Table React component — UsersSelectTable. MIT licensed, copy-paste ready for Next.js and Tailwind CSS.

Bulk-select users table with header checkbox and live selection count. Clean white admin pattern for permissions or exports.

Preview

Users

1 selected
NameEmailRole
Bidyut KunduBidyut Kundu
bidyut@studio.devAdmin
Rupam SenRupam Sen
rupam@studio.devEditor
Ava ChenAva Chen
ava@studio.devViewer
Sofia OrtizSofia Ortiz
sofia@studio.devEditor

Setup

How to use

Free for personal and commercial use. No UI attribution required. Include the MIT copyright notice when copying component source into your project. Read the MIT license.

  1. 1

    Run in your terminal:

    $npm install clsx tailwind-merge lucide-react
  2. 2

    Copy lib/cn.ts below. Skip if you already have cn().

  3. 3

    Copy the code below and create components/table/users-select-table.tsx in your project.

  4. 4

    Import and render:

    Example

    import { UsersSelectTable } from "@/components/table/users-select-table";

    <UsersSelectTable />

lib/cn.ts

1
2
3
4
5
6
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
 
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

components/table/users-select-table.tsx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
"use client";
 
import Image from "next/image";
import { forwardRef, useMemo, useState, type ComponentPropsWithoutRef } from "react";
 
import { cn } from "@/lib/cn";
import { Check, Minus } from "lucide-react";
 
type User = Readonly<{
id: string;
name: string;
email: string;
role: string;
avatar: string;
}>;
 
const USERS: User[] = [
{
id: "u1",
name: "Bidyut Kundu",
email: "bidyut@studio.dev",
role: "Admin",
avatar: "/profile-picture.png",
},
{
id: "u2",
name: "Rupam Sen",
email: "rupam@studio.dev",
role: "Editor",
avatar: "/woman.png",
},
{
id: "u3",
name: "Ava Chen",
email: "ava@studio.dev",
role: "Viewer",
avatar: "/profile-picture.png",
},
{
id: "u4",
name: "Sofia Ortiz",
email: "sofia@studio.dev",
role: "Editor",
avatar: "/woman.png",
},
];
 
type UsersSelectTableProps = ComponentPropsWithoutRef<"div">;
 
// Bulk-select users table — header checkbox, row selection, and live count. White admin pattern.
export const UsersSelectTable = forwardRef<HTMLDivElement, UsersSelectTableProps>(
function UsersSelectTable({ className, ...props }, ref) {
const [selected, setSelected] = useState<Set<string>>(() => new Set(["u1"]));
 
const allIds = useMemo(() => USERS.map((u) => u.id), []);
const allSelected = selected.size === USERS.length;
const someSelected = selected.size > 0 && !allSelected;
 
function toggleRow(id: string) {
setSelected((prev) => {
const next = new Set(prev);
if (next.has(id)) next.delete(id);
else next.add(id);
return next;
});
}
 
function toggleAll() {
setSelected(allSelected ? new Set() : new Set(allIds));
}
 
return (
<div
ref={ref}
className={cn(
"w-full max-w-lg overflow-hidden rounded-xl border border-neutral-200 bg-white",
className,
)}
{...props}
>
<div className="flex items-center justify-between border-b border-neutral-100 px-4 py-3">
<p className="text-sm font-semibold text-neutral-900">Users</p>
<span className="text-xs text-neutral-500">
{selected.size > 0 ? `${selected.size} selected` : `${USERS.length} total`}
</span>
</div>
 
<div className="overflow-x-auto">
<table className="w-full min-w-[300px] border-collapse text-left text-sm">
<thead>
<tr className="text-xs text-neutral-500">
<th className="w-10 px-4 py-2.5">
<button
type="button"
onClick={toggleAll}
aria-label={allSelected ? "Deselect all" : "Select all"}
className={cn(
"flex size-4 items-center justify-center rounded border transition-colors",
allSelected || someSelected
? "border-neutral-900 bg-neutral-900"
: "border-neutral-300 bg-white",
)}
>
{allSelected ? (
<Check className="size-2.5 text-white" strokeWidth={3} />
) : someSelected ? (
<Minus className="size-2.5 text-white" strokeWidth={3} />
) : null}
</button>
</th>
<th className="px-2 py-2.5 font-medium">Name</th>
<th className="hidden px-3 py-2.5 font-medium md:table-cell">Email</th>
<th className="px-4 py-2.5 font-medium">Role</th>
</tr>
</thead>
<tbody>
{USERS.map((user) => {
const isOn = selected.has(user.id);
return (
<tr
key={user.id}
onClick={() => toggleRow(user.id)}
className={cn(
"cursor-pointer border-t border-neutral-100 transition-colors",
isOn ? "bg-neutral-50" : "hover:bg-neutral-50/80",
)}
>
<td className="px-4 py-3">
<span
className={cn(
"flex size-4 items-center justify-center rounded border transition-colors",
isOn ? "border-neutral-900 bg-neutral-900" : "border-neutral-300",
)}
>
{isOn ? <Check className="size-2.5 text-white" strokeWidth={3} /> : null}
</span>
</td>
<td className="px-2 py-3">
<div className="flex items-center gap-2.5">
<Image
src={user.avatar}
alt={user.name}
width={28}
height={28}
className="size-7 shrink-0 rounded-full object-cover"
/>
<span className="font-medium text-neutral-900">{user.name}</span>
</div>
</td>
<td className="hidden px-3 py-3 text-neutral-500 md:table-cell">{user.email}</td>
<td className="px-4 py-3 text-neutral-600">{user.role}</td>
</tr>
);
})}
</tbody>
</table>
</div>
</div>
);
},
);
 
UsersSelectTable.displayName = "UsersSelectTable";
PreviousNext

On this

page

Jump to a section on this page.

  • lib/cn.ts
  • components/table/users-select-table.tsx

Sponsor spot · demo preview

Logo

Your brand name

Your tagline or category

A short pitch about your product or service goes here. This is a preview of how sponsor cards will look in this sidebar.

Your call to action

This slot is available. Sponsor Opensource UI and reach developers browsing components every day.