luxtable 0.3.4 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/EXAMPLE.md +348 -348
- package/README.md +178 -40
- package/USAGE.md +823 -631
- package/dist/index.d.mts +156 -23
- package/dist/index.d.ts +156 -23
- package/dist/index.js +1608 -729
- package/dist/index.mjs +1528 -652
- package/package.json +5 -2
- package/src/styles/README.md +141 -0
- package/src/styles/variables.css +283 -0
package/EXAMPLE.md
CHANGED
|
@@ -1,348 +1,348 @@
|
|
|
1
|
-
# 🚀 LuxTable - Quick Start Guide
|
|
2
|
-
|
|
3
|
-
This guide shows you how to install and use LuxTable with the shadcn CLI.
|
|
4
|
-
|
|
5
|
-
## Prerequisites
|
|
6
|
-
|
|
7
|
-
Before installing LuxTable, make sure you have:
|
|
8
|
-
|
|
9
|
-
- **Node.js** 18+ installed
|
|
10
|
-
- **A Next.js project** (or any React project with Tailwind CSS)
|
|
11
|
-
- **shadcn/ui** initialized in your project
|
|
12
|
-
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
## Step 1: Create a New Next.js Project (Optional)
|
|
16
|
-
|
|
17
|
-
If you don't have a project yet:
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
npx create-next-app@latest my-app --typescript --tailwind --eslint
|
|
21
|
-
cd my-app
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
---
|
|
25
|
-
|
|
26
|
-
## Step 2: Initialize shadcn/ui
|
|
27
|
-
|
|
28
|
-
```bash
|
|
29
|
-
pnpm dlx shadcn@latest init
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
When prompted, select your preferences:
|
|
33
|
-
- Style: **New York** (recommended)
|
|
34
|
-
- Base color: **Slate** (or your preference)
|
|
35
|
-
- CSS variables: **Yes**
|
|
36
|
-
|
|
37
|
-
---
|
|
38
|
-
|
|
39
|
-
## Step 3: Install LuxTable
|
|
40
|
-
|
|
41
|
-
### Option A: Using unpkg CDN (Recommended)
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
# Install the main LuxTable component
|
|
45
|
-
pnpm dlx shadcn@latest add "https://unpkg.com/luxtable/registry/lux-table.json"
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
This command will:
|
|
49
|
-
- ✅ Install required dependencies (`@tanstack/react-table`, `lucide-react`, etc.)
|
|
50
|
-
- ✅ Install required shadcn/ui components (button, checkbox, dropdown-menu, input, select)
|
|
51
|
-
- ✅ Copy LuxTable files to your `components/` folder
|
|
52
|
-
|
|
53
|
-
### Option B: Install additional components (Optional)
|
|
54
|
-
|
|
55
|
-
```bash
|
|
56
|
-
# Cell renderers for status badges, progress bars, dates, etc.
|
|
57
|
-
pnpm dlx shadcn@latest add "https://unpkg.com/luxtable/registry/lux-table-cell-renderers.json"
|
|
58
|
-
|
|
59
|
-
# Column helper for type-safe column definitions
|
|
60
|
-
pnpm dlx shadcn@latest add "https://unpkg.com/luxtable/registry/lux-table-column-helper.json"
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
---
|
|
64
|
-
|
|
65
|
-
## Step 4: Create Your First Table
|
|
66
|
-
|
|
67
|
-
Create a new file `app/page.tsx` (or modify the existing one):
|
|
68
|
-
|
|
69
|
-
```tsx
|
|
70
|
-
"use client";
|
|
71
|
-
|
|
72
|
-
import { LuxTable } from "@/components/lux-table/lux-table";
|
|
73
|
-
import { ColumnDef } from "@tanstack/react-table";
|
|
74
|
-
|
|
75
|
-
// 1. Define your data type
|
|
76
|
-
type User = {
|
|
77
|
-
id: number;
|
|
78
|
-
name: string;
|
|
79
|
-
email: string;
|
|
80
|
-
status: "active" | "inactive" | "pending";
|
|
81
|
-
role: string;
|
|
82
|
-
createdAt: string;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
// 2. Define your columns
|
|
86
|
-
const columns: ColumnDef<User>[] = [
|
|
87
|
-
{
|
|
88
|
-
accessorKey: "id",
|
|
89
|
-
header: "ID",
|
|
90
|
-
size: 80,
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
accessorKey: "name",
|
|
94
|
-
header: "Name",
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
accessorKey: "email",
|
|
98
|
-
header: "Email",
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
accessorKey: "status",
|
|
102
|
-
header: "Status",
|
|
103
|
-
cell: ({ row }) => {
|
|
104
|
-
const status = row.getValue("status") as string;
|
|
105
|
-
const colors: Record<string, string> = {
|
|
106
|
-
active: "bg-green-100 text-green-800",
|
|
107
|
-
inactive: "bg-gray-100 text-gray-800",
|
|
108
|
-
pending: "bg-yellow-100 text-yellow-800",
|
|
109
|
-
};
|
|
110
|
-
return (
|
|
111
|
-
<span className={`px-2 py-1 rounded-full text-xs font-medium ${colors[status]}`}>
|
|
112
|
-
{status}
|
|
113
|
-
</span>
|
|
114
|
-
);
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
accessorKey: "role",
|
|
119
|
-
header: "Role",
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
accessorKey: "createdAt",
|
|
123
|
-
header: "Created At",
|
|
124
|
-
cell: ({ row }) => {
|
|
125
|
-
const date = new Date(row.getValue("createdAt"));
|
|
126
|
-
return date.toLocaleDateString();
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
];
|
|
130
|
-
|
|
131
|
-
// 3. Sample data
|
|
132
|
-
const users: User[] = [
|
|
133
|
-
{ id: 1, name: "John Doe", email: "john@example.com", status: "active", role: "Admin", createdAt: "2024-01-15" },
|
|
134
|
-
{ id: 2, name: "Jane Smith", email: "jane@example.com", status: "active", role: "User", createdAt: "2024-02-20" },
|
|
135
|
-
{ id: 3, name: "Bob Johnson", email: "bob@example.com", status: "inactive", role: "User", createdAt: "2024-03-10" },
|
|
136
|
-
{ id: 4, name: "Alice Brown", email: "alice@example.com", status: "pending", role: "Moderator", createdAt: "2024-04-05" },
|
|
137
|
-
{ id: 5, name: "Charlie Wilson", email: "charlie@example.com", status: "active", role: "User", createdAt: "2024-05-12" },
|
|
138
|
-
{ id: 6, name: "Diana Miller", email: "diana@example.com", status: "active", role: "Admin", createdAt: "2024-06-01" },
|
|
139
|
-
{ id: 7, name: "Edward Davis", email: "edward@example.com", status: "inactive", role: "User", createdAt: "2024-07-18" },
|
|
140
|
-
{ id: 8, name: "Fiona Garcia", email: "fiona@example.com", status: "pending", role: "User", createdAt: "2024-08-25" },
|
|
141
|
-
{ id: 9, name: "George Martinez", email: "george@example.com", status: "active", role: "Moderator", createdAt: "2024-09-30" },
|
|
142
|
-
{ id: 10, name: "Hannah Anderson", email: "hannah@example.com", status: "active", role: "User", createdAt: "2024-10-14" },
|
|
143
|
-
{ id: 11, name: "Ivan Thomas", email: "ivan@example.com", status: "inactive", role: "User", createdAt: "2024-11-22" },
|
|
144
|
-
{ id: 12, name: "Julia Jackson", email: "julia@example.com", status: "active", role: "Admin", createdAt: "2024-12-01" },
|
|
145
|
-
];
|
|
146
|
-
|
|
147
|
-
// 4. Render the table
|
|
148
|
-
export default function HomePage() {
|
|
149
|
-
return (
|
|
150
|
-
<div className="container mx-auto py-10">
|
|
151
|
-
<h1 className="text-3xl font-bold mb-6">Users</h1>
|
|
152
|
-
|
|
153
|
-
<LuxTable
|
|
154
|
-
data={users}
|
|
155
|
-
columns={columns}
|
|
156
|
-
options={{
|
|
157
|
-
pagination: true,
|
|
158
|
-
pageSize: 5,
|
|
159
|
-
filtering: true,
|
|
160
|
-
selection: "multiple",
|
|
161
|
-
showToolbar: true,
|
|
162
|
-
showGlobalSearch: true,
|
|
163
|
-
showColumnVisibility: true,
|
|
164
|
-
}}
|
|
165
|
-
onSelectedRowsChange={(selectedRows) => {
|
|
166
|
-
console.log("Selected:", selectedRows);
|
|
167
|
-
}}
|
|
168
|
-
/>
|
|
169
|
-
</div>
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
---
|
|
175
|
-
|
|
176
|
-
## Step 5: Run Your App
|
|
177
|
-
|
|
178
|
-
```bash
|
|
179
|
-
pnpm dev
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
Open [http://localhost:3000](http://localhost:3000) to see your table!
|
|
183
|
-
|
|
184
|
-
---
|
|
185
|
-
|
|
186
|
-
## 🎨 Features Demonstrated
|
|
187
|
-
|
|
188
|
-
The example above showcases:
|
|
189
|
-
|
|
190
|
-
| Feature | How to Enable |
|
|
191
|
-
|---------|---------------|
|
|
192
|
-
| **Pagination** | `options={{ pagination: true }}` |
|
|
193
|
-
| **Column Filtering** | `options={{ filtering: true }}` |
|
|
194
|
-
| **Global Search** | `options={{ showToolbar: true, showGlobalSearch: true }}` |
|
|
195
|
-
| **Row Selection** | `options={{ selection: "multiple" }}` |
|
|
196
|
-
| **Column Visibility** | `options={{ showColumnVisibility: true }}` |
|
|
197
|
-
| **Custom Cell Rendering** | Use `cell` property in column definition |
|
|
198
|
-
|
|
199
|
-
---
|
|
200
|
-
|
|
201
|
-
## 📁 Project Structure After Installation
|
|
202
|
-
|
|
203
|
-
```
|
|
204
|
-
my-app/
|
|
205
|
-
├── components/
|
|
206
|
-
│ ├── lux-table/
|
|
207
|
-
│ │ ├── lux-table.tsx # Main table component
|
|
208
|
-
│ │ ├── types.ts # TypeScript types
|
|
209
|
-
│ │ ├── column-filter.tsx # Column filter component
|
|
210
|
-
│ │ ├── column-header.tsx # Column header with actions
|
|
211
|
-
│ │ ├── pagination.tsx # Pagination controls
|
|
212
|
-
│ │ └── table-toolbar.tsx # Toolbar with search
|
|
213
|
-
│ ├── table/
|
|
214
|
-
│ │ └── table.tsx # Base table primitives
|
|
215
|
-
│ └── ui/
|
|
216
|
-
│ ├── button.tsx # shadcn button
|
|
217
|
-
│ ├── checkbox.tsx # shadcn checkbox
|
|
218
|
-
│ ├── dropdown-menu.tsx # shadcn dropdown
|
|
219
|
-
│ ├── input.tsx # shadcn input
|
|
220
|
-
│ └── select.tsx # shadcn select
|
|
221
|
-
├── lib/
|
|
222
|
-
│ └── utils.ts # cn() utility function
|
|
223
|
-
└── app/
|
|
224
|
-
└── page.tsx # Your page with LuxTable
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
---
|
|
228
|
-
|
|
229
|
-
## 🔧 Advanced Usage
|
|
230
|
-
|
|
231
|
-
### Using Cell Renderers
|
|
232
|
-
|
|
233
|
-
If you installed `lux-table-cell-renderers`:
|
|
234
|
-
|
|
235
|
-
```tsx
|
|
236
|
-
import { StatusCell, ProgressCell, DateCell, CopyableCell } from "@/components/lux-table/cell-renderers";
|
|
237
|
-
|
|
238
|
-
const columns = [
|
|
239
|
-
{
|
|
240
|
-
accessorKey: "status",
|
|
241
|
-
header: "Status",
|
|
242
|
-
cell: ({ row }) => <StatusCell value={row.getValue("status")} />,
|
|
243
|
-
},
|
|
244
|
-
{
|
|
245
|
-
accessorKey: "progress",
|
|
246
|
-
header: "Progress",
|
|
247
|
-
cell: ({ row }) => <ProgressCell value={row.getValue("progress")} />,
|
|
248
|
-
},
|
|
249
|
-
{
|
|
250
|
-
accessorKey: "createdAt",
|
|
251
|
-
header: "Created",
|
|
252
|
-
cell: ({ row }) => <DateCell value={row.getValue("createdAt")} />,
|
|
253
|
-
},
|
|
254
|
-
{
|
|
255
|
-
accessorKey: "id",
|
|
256
|
-
header: "ID",
|
|
257
|
-
cell: ({ row }) => <CopyableCell value={row.getValue("id")} />,
|
|
258
|
-
},
|
|
259
|
-
];
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
### Controlled Sorting
|
|
263
|
-
|
|
264
|
-
```tsx
|
|
265
|
-
import { useState } from "react";
|
|
266
|
-
import { SortingState } from "@tanstack/react-table";
|
|
267
|
-
|
|
268
|
-
export default function Page() {
|
|
269
|
-
const [sorting, setSorting] = useState<SortingState>([]);
|
|
270
|
-
|
|
271
|
-
return (
|
|
272
|
-
<LuxTable
|
|
273
|
-
data={data}
|
|
274
|
-
columns={columns}
|
|
275
|
-
sorting={sorting}
|
|
276
|
-
onSortingChange={setSorting}
|
|
277
|
-
/>
|
|
278
|
-
);
|
|
279
|
-
}
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
### Controlled Row Selection
|
|
283
|
-
|
|
284
|
-
```tsx
|
|
285
|
-
import { useState } from "react";
|
|
286
|
-
import { RowSelectionState } from "@tanstack/react-table";
|
|
287
|
-
|
|
288
|
-
export default function Page() {
|
|
289
|
-
const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
|
|
290
|
-
|
|
291
|
-
return (
|
|
292
|
-
<LuxTable
|
|
293
|
-
data={data}
|
|
294
|
-
columns={columns}
|
|
295
|
-
options={{ selection: "multiple" }}
|
|
296
|
-
rowSelection={rowSelection}
|
|
297
|
-
onRowSelectionChange={setRowSelection}
|
|
298
|
-
/>
|
|
299
|
-
);
|
|
300
|
-
}
|
|
301
|
-
```
|
|
302
|
-
|
|
303
|
-
---
|
|
304
|
-
|
|
305
|
-
## 📚 Full Documentation
|
|
306
|
-
|
|
307
|
-
For more examples and API reference, visit: [https://luxtable.dev/docs](https://luxtable.dev/docs)
|
|
308
|
-
|
|
309
|
-
---
|
|
310
|
-
|
|
311
|
-
## 🆘 Troubleshooting
|
|
312
|
-
|
|
313
|
-
### "Module not found" errors
|
|
314
|
-
|
|
315
|
-
Make sure you have the required path aliases in your `tsconfig.json`:
|
|
316
|
-
|
|
317
|
-
```json
|
|
318
|
-
{
|
|
319
|
-
"compilerOptions": {
|
|
320
|
-
"paths": {
|
|
321
|
-
"@/*": ["./*"]
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
```
|
|
326
|
-
|
|
327
|
-
### Styles not applied
|
|
328
|
-
|
|
329
|
-
Ensure Tailwind is scanning your components:
|
|
330
|
-
|
|
331
|
-
```js
|
|
332
|
-
// tailwind.config.js
|
|
333
|
-
module.exports = {
|
|
334
|
-
content: [
|
|
335
|
-
"./components/**/*.{js,ts,jsx,tsx}",
|
|
336
|
-
"./app/**/*.{js,ts,jsx,tsx}",
|
|
337
|
-
],
|
|
338
|
-
};
|
|
339
|
-
```
|
|
340
|
-
|
|
341
|
-
---
|
|
342
|
-
|
|
343
|
-
## 💡 Need Help?
|
|
344
|
-
|
|
345
|
-
- GitHub Issues: [github.com/
|
|
346
|
-
- Documentation: [luxtable.dev/docs](https://luxtable.dev/docs)
|
|
347
|
-
|
|
348
|
-
Happy coding! 🎉
|
|
1
|
+
# 🚀 LuxTable - Quick Start Guide
|
|
2
|
+
|
|
3
|
+
This guide shows you how to install and use LuxTable with the shadcn CLI.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
Before installing LuxTable, make sure you have:
|
|
8
|
+
|
|
9
|
+
- **Node.js** 18+ installed
|
|
10
|
+
- **A Next.js project** (or any React project with Tailwind CSS)
|
|
11
|
+
- **shadcn/ui** initialized in your project
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Step 1: Create a New Next.js Project (Optional)
|
|
16
|
+
|
|
17
|
+
If you don't have a project yet:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npx create-next-app@latest my-app --typescript --tailwind --eslint
|
|
21
|
+
cd my-app
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Step 2: Initialize shadcn/ui
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pnpm dlx shadcn@latest init
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
When prompted, select your preferences:
|
|
33
|
+
- Style: **New York** (recommended)
|
|
34
|
+
- Base color: **Slate** (or your preference)
|
|
35
|
+
- CSS variables: **Yes**
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Step 3: Install LuxTable
|
|
40
|
+
|
|
41
|
+
### Option A: Using unpkg CDN (Recommended)
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
# Install the main LuxTable component
|
|
45
|
+
pnpm dlx shadcn@latest add "https://unpkg.com/luxtable/registry/lux-table.json"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
This command will:
|
|
49
|
+
- ✅ Install required dependencies (`@tanstack/react-table`, `lucide-react`, etc.)
|
|
50
|
+
- ✅ Install required shadcn/ui components (button, checkbox, dropdown-menu, input, select)
|
|
51
|
+
- ✅ Copy LuxTable files to your `components/` folder
|
|
52
|
+
|
|
53
|
+
### Option B: Install additional components (Optional)
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
# Cell renderers for status badges, progress bars, dates, etc.
|
|
57
|
+
pnpm dlx shadcn@latest add "https://unpkg.com/luxtable/registry/lux-table-cell-renderers.json"
|
|
58
|
+
|
|
59
|
+
# Column helper for type-safe column definitions
|
|
60
|
+
pnpm dlx shadcn@latest add "https://unpkg.com/luxtable/registry/lux-table-column-helper.json"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Step 4: Create Your First Table
|
|
66
|
+
|
|
67
|
+
Create a new file `app/page.tsx` (or modify the existing one):
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
"use client";
|
|
71
|
+
|
|
72
|
+
import { LuxTable } from "@/components/lux-table/lux-table";
|
|
73
|
+
import { ColumnDef } from "@tanstack/react-table";
|
|
74
|
+
|
|
75
|
+
// 1. Define your data type
|
|
76
|
+
type User = {
|
|
77
|
+
id: number;
|
|
78
|
+
name: string;
|
|
79
|
+
email: string;
|
|
80
|
+
status: "active" | "inactive" | "pending";
|
|
81
|
+
role: string;
|
|
82
|
+
createdAt: string;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// 2. Define your columns
|
|
86
|
+
const columns: ColumnDef<User>[] = [
|
|
87
|
+
{
|
|
88
|
+
accessorKey: "id",
|
|
89
|
+
header: "ID",
|
|
90
|
+
size: 80,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
accessorKey: "name",
|
|
94
|
+
header: "Name",
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
accessorKey: "email",
|
|
98
|
+
header: "Email",
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
accessorKey: "status",
|
|
102
|
+
header: "Status",
|
|
103
|
+
cell: ({ row }) => {
|
|
104
|
+
const status = row.getValue("status") as string;
|
|
105
|
+
const colors: Record<string, string> = {
|
|
106
|
+
active: "bg-green-100 text-green-800",
|
|
107
|
+
inactive: "bg-gray-100 text-gray-800",
|
|
108
|
+
pending: "bg-yellow-100 text-yellow-800",
|
|
109
|
+
};
|
|
110
|
+
return (
|
|
111
|
+
<span className={`px-2 py-1 rounded-full text-xs font-medium ${colors[status]}`}>
|
|
112
|
+
{status}
|
|
113
|
+
</span>
|
|
114
|
+
);
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
accessorKey: "role",
|
|
119
|
+
header: "Role",
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
accessorKey: "createdAt",
|
|
123
|
+
header: "Created At",
|
|
124
|
+
cell: ({ row }) => {
|
|
125
|
+
const date = new Date(row.getValue("createdAt"));
|
|
126
|
+
return date.toLocaleDateString();
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
];
|
|
130
|
+
|
|
131
|
+
// 3. Sample data
|
|
132
|
+
const users: User[] = [
|
|
133
|
+
{ id: 1, name: "John Doe", email: "john@example.com", status: "active", role: "Admin", createdAt: "2024-01-15" },
|
|
134
|
+
{ id: 2, name: "Jane Smith", email: "jane@example.com", status: "active", role: "User", createdAt: "2024-02-20" },
|
|
135
|
+
{ id: 3, name: "Bob Johnson", email: "bob@example.com", status: "inactive", role: "User", createdAt: "2024-03-10" },
|
|
136
|
+
{ id: 4, name: "Alice Brown", email: "alice@example.com", status: "pending", role: "Moderator", createdAt: "2024-04-05" },
|
|
137
|
+
{ id: 5, name: "Charlie Wilson", email: "charlie@example.com", status: "active", role: "User", createdAt: "2024-05-12" },
|
|
138
|
+
{ id: 6, name: "Diana Miller", email: "diana@example.com", status: "active", role: "Admin", createdAt: "2024-06-01" },
|
|
139
|
+
{ id: 7, name: "Edward Davis", email: "edward@example.com", status: "inactive", role: "User", createdAt: "2024-07-18" },
|
|
140
|
+
{ id: 8, name: "Fiona Garcia", email: "fiona@example.com", status: "pending", role: "User", createdAt: "2024-08-25" },
|
|
141
|
+
{ id: 9, name: "George Martinez", email: "george@example.com", status: "active", role: "Moderator", createdAt: "2024-09-30" },
|
|
142
|
+
{ id: 10, name: "Hannah Anderson", email: "hannah@example.com", status: "active", role: "User", createdAt: "2024-10-14" },
|
|
143
|
+
{ id: 11, name: "Ivan Thomas", email: "ivan@example.com", status: "inactive", role: "User", createdAt: "2024-11-22" },
|
|
144
|
+
{ id: 12, name: "Julia Jackson", email: "julia@example.com", status: "active", role: "Admin", createdAt: "2024-12-01" },
|
|
145
|
+
];
|
|
146
|
+
|
|
147
|
+
// 4. Render the table
|
|
148
|
+
export default function HomePage() {
|
|
149
|
+
return (
|
|
150
|
+
<div className="container mx-auto py-10">
|
|
151
|
+
<h1 className="text-3xl font-bold mb-6">Users</h1>
|
|
152
|
+
|
|
153
|
+
<LuxTable
|
|
154
|
+
data={users}
|
|
155
|
+
columns={columns}
|
|
156
|
+
options={{
|
|
157
|
+
pagination: true,
|
|
158
|
+
pageSize: 5,
|
|
159
|
+
filtering: true,
|
|
160
|
+
selection: "multiple",
|
|
161
|
+
showToolbar: true,
|
|
162
|
+
showGlobalSearch: true,
|
|
163
|
+
showColumnVisibility: true,
|
|
164
|
+
}}
|
|
165
|
+
onSelectedRowsChange={(selectedRows) => {
|
|
166
|
+
console.log("Selected:", selectedRows);
|
|
167
|
+
}}
|
|
168
|
+
/>
|
|
169
|
+
</div>
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## Step 5: Run Your App
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
pnpm dev
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Open [http://localhost:3000](http://localhost:3000) to see your table!
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## 🎨 Features Demonstrated
|
|
187
|
+
|
|
188
|
+
The example above showcases:
|
|
189
|
+
|
|
190
|
+
| Feature | How to Enable |
|
|
191
|
+
|---------|---------------|
|
|
192
|
+
| **Pagination** | `options={{ pagination: true }}` |
|
|
193
|
+
| **Column Filtering** | `options={{ filtering: true }}` |
|
|
194
|
+
| **Global Search** | `options={{ showToolbar: true, showGlobalSearch: true }}` |
|
|
195
|
+
| **Row Selection** | `options={{ selection: "multiple" }}` |
|
|
196
|
+
| **Column Visibility** | `options={{ showColumnVisibility: true }}` |
|
|
197
|
+
| **Custom Cell Rendering** | Use `cell` property in column definition |
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## 📁 Project Structure After Installation
|
|
202
|
+
|
|
203
|
+
```
|
|
204
|
+
my-app/
|
|
205
|
+
├── components/
|
|
206
|
+
│ ├── lux-table/
|
|
207
|
+
│ │ ├── lux-table.tsx # Main table component
|
|
208
|
+
│ │ ├── types.ts # TypeScript types
|
|
209
|
+
│ │ ├── column-filter.tsx # Column filter component
|
|
210
|
+
│ │ ├── column-header.tsx # Column header with actions
|
|
211
|
+
│ │ ├── pagination.tsx # Pagination controls
|
|
212
|
+
│ │ └── table-toolbar.tsx # Toolbar with search
|
|
213
|
+
│ ├── table/
|
|
214
|
+
│ │ └── table.tsx # Base table primitives
|
|
215
|
+
│ └── ui/
|
|
216
|
+
│ ├── button.tsx # shadcn button
|
|
217
|
+
│ ├── checkbox.tsx # shadcn checkbox
|
|
218
|
+
│ ├── dropdown-menu.tsx # shadcn dropdown
|
|
219
|
+
│ ├── input.tsx # shadcn input
|
|
220
|
+
│ └── select.tsx # shadcn select
|
|
221
|
+
├── lib/
|
|
222
|
+
│ └── utils.ts # cn() utility function
|
|
223
|
+
└── app/
|
|
224
|
+
└── page.tsx # Your page with LuxTable
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## 🔧 Advanced Usage
|
|
230
|
+
|
|
231
|
+
### Using Cell Renderers
|
|
232
|
+
|
|
233
|
+
If you installed `lux-table-cell-renderers`:
|
|
234
|
+
|
|
235
|
+
```tsx
|
|
236
|
+
import { StatusCell, ProgressCell, DateCell, CopyableCell } from "@/components/lux-table/cell-renderers";
|
|
237
|
+
|
|
238
|
+
const columns = [
|
|
239
|
+
{
|
|
240
|
+
accessorKey: "status",
|
|
241
|
+
header: "Status",
|
|
242
|
+
cell: ({ row }) => <StatusCell value={row.getValue("status")} />,
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
accessorKey: "progress",
|
|
246
|
+
header: "Progress",
|
|
247
|
+
cell: ({ row }) => <ProgressCell value={row.getValue("progress")} />,
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
accessorKey: "createdAt",
|
|
251
|
+
header: "Created",
|
|
252
|
+
cell: ({ row }) => <DateCell value={row.getValue("createdAt")} />,
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
accessorKey: "id",
|
|
256
|
+
header: "ID",
|
|
257
|
+
cell: ({ row }) => <CopyableCell value={row.getValue("id")} />,
|
|
258
|
+
},
|
|
259
|
+
];
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### Controlled Sorting
|
|
263
|
+
|
|
264
|
+
```tsx
|
|
265
|
+
import { useState } from "react";
|
|
266
|
+
import { SortingState } from "@tanstack/react-table";
|
|
267
|
+
|
|
268
|
+
export default function Page() {
|
|
269
|
+
const [sorting, setSorting] = useState<SortingState>([]);
|
|
270
|
+
|
|
271
|
+
return (
|
|
272
|
+
<LuxTable
|
|
273
|
+
data={data}
|
|
274
|
+
columns={columns}
|
|
275
|
+
sorting={sorting}
|
|
276
|
+
onSortingChange={setSorting}
|
|
277
|
+
/>
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### Controlled Row Selection
|
|
283
|
+
|
|
284
|
+
```tsx
|
|
285
|
+
import { useState } from "react";
|
|
286
|
+
import { RowSelectionState } from "@tanstack/react-table";
|
|
287
|
+
|
|
288
|
+
export default function Page() {
|
|
289
|
+
const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
|
|
290
|
+
|
|
291
|
+
return (
|
|
292
|
+
<LuxTable
|
|
293
|
+
data={data}
|
|
294
|
+
columns={columns}
|
|
295
|
+
options={{ selection: "multiple" }}
|
|
296
|
+
rowSelection={rowSelection}
|
|
297
|
+
onRowSelectionChange={setRowSelection}
|
|
298
|
+
/>
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
## 📚 Full Documentation
|
|
306
|
+
|
|
307
|
+
For more examples and API reference, visit: [https://luxtable.dev/docs](https://luxtable.dev/docs)
|
|
308
|
+
|
|
309
|
+
---
|
|
310
|
+
|
|
311
|
+
## 🆘 Troubleshooting
|
|
312
|
+
|
|
313
|
+
### "Module not found" errors
|
|
314
|
+
|
|
315
|
+
Make sure you have the required path aliases in your `tsconfig.json`:
|
|
316
|
+
|
|
317
|
+
```json
|
|
318
|
+
{
|
|
319
|
+
"compilerOptions": {
|
|
320
|
+
"paths": {
|
|
321
|
+
"@/*": ["./*"]
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### Styles not applied
|
|
328
|
+
|
|
329
|
+
Ensure Tailwind is scanning your components:
|
|
330
|
+
|
|
331
|
+
```js
|
|
332
|
+
// tailwind.config.js
|
|
333
|
+
module.exports = {
|
|
334
|
+
content: [
|
|
335
|
+
"./components/**/*.{js,ts,jsx,tsx}",
|
|
336
|
+
"./app/**/*.{js,ts,jsx,tsx}",
|
|
337
|
+
],
|
|
338
|
+
};
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
---
|
|
342
|
+
|
|
343
|
+
## 💡 Need Help?
|
|
344
|
+
|
|
345
|
+
- GitHub Issues: [github.com/Huseyin-altun/luxtable/issues](https://github.com/Huseyin-altun/luxtable/issues)
|
|
346
|
+
- Documentation: [luxtable.dev/docs](https://luxtable.dev/docs)
|
|
347
|
+
|
|
348
|
+
Happy coding! 🎉
|