react-table-craft 0.1.0
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/CHANGELOG.md +21 -0
- package/LICENSE +21 -0
- package/README.md +407 -0
- package/dist/index.d.mts +639 -0
- package/dist/index.d.ts +639 -0
- package/dist/index.js +3487 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +3431 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +76 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 (Initial Release)
|
|
4
|
+
|
|
5
|
+
- Core `DataTable` component with sorting, filtering, pagination
|
|
6
|
+
- `ClientSideTable` wrapper with auto-index column
|
|
7
|
+
- Advanced filter builder UI
|
|
8
|
+
- Card view and table view toggle
|
|
9
|
+
- CSV export support
|
|
10
|
+
- Full i18n support with configurable translation function
|
|
11
|
+
- Router adapter pattern for framework-agnostic URL sync
|
|
12
|
+
- 4-layer config system with `TableProvider`
|
|
13
|
+
- Plugin architecture for extending config
|
|
14
|
+
- RTL support
|
|
15
|
+
- Mobile-responsive toolbar with drawer
|
|
16
|
+
- Floating action bar for bulk operations
|
|
17
|
+
- Column visibility toggle
|
|
18
|
+
- Role-based filtering
|
|
19
|
+
- Faceted and single-select filters
|
|
20
|
+
- Loading skeleton
|
|
21
|
+
- Row actions with dropdown and individual button modes
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ahmed Elkhdrawy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
# table-craft
|
|
2
|
+
|
|
3
|
+
A production-ready, framework-agnostic React data table system built on [TanStack Table](https://tanstack.com/table). Fully typed, tree-shakeable, and feature-rich.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Framework-Agnostic** — Works with Next.js, React Router, Remix, or any React setup
|
|
8
|
+
- **Full TypeScript Support** — Generics, strict types, and exported type definitions
|
|
9
|
+
- **Tree-Shakeable** — ESM + CJS dual output with `sideEffects: false`
|
|
10
|
+
- **Built-in Pagination** — Client-side and server-side (backend) pagination with URL sync
|
|
11
|
+
- **Advanced Filtering** — Faceted filters, multi-filters, text search, date range, single-select
|
|
12
|
+
- **Sorting** — Column header sorting with multi-sort support
|
|
13
|
+
- **Column Visibility** — Toggle columns on/off with persistent state
|
|
14
|
+
- **Row Selection** — Checkbox-based row selection with bulk actions
|
|
15
|
+
- **Card View** — Switch between table and card layouts
|
|
16
|
+
- **Floating Action Bar** — Contextual actions for selected rows
|
|
17
|
+
- **CSV Export** — Export selected rows or all data to CSV
|
|
18
|
+
- **RTL Support** — Full right-to-left layout support
|
|
19
|
+
- **i18n Ready** — Plug in any translation system or use built-in English defaults
|
|
20
|
+
- **Responsive** — Desktop toolbar + mobile toolbar with drawer-based filters
|
|
21
|
+
- **Configurable** — 4-layer config system (defaults → provider → instance → plugins)
|
|
22
|
+
- **Plugin Architecture** — Extend behavior with priority-based plugins
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install table-craft
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Peer Dependencies
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install react react-dom
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Tailwind CSS
|
|
37
|
+
|
|
38
|
+
table-craft uses Tailwind CSS classes for styling. You must have Tailwind CSS configured in your project. Add the package to your Tailwind content paths:
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
// tailwind.config.js
|
|
42
|
+
module.exports = {
|
|
43
|
+
content: [
|
|
44
|
+
// ... your paths
|
|
45
|
+
'./node_modules/table-craft/dist/**/*.{js,mjs}',
|
|
46
|
+
],
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Quick Start
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
import { DataTable } from 'table-craft'
|
|
54
|
+
import type { ColumnDef } from '@tanstack/react-table'
|
|
55
|
+
|
|
56
|
+
interface User {
|
|
57
|
+
id: string
|
|
58
|
+
name: string
|
|
59
|
+
email: string
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const columns: ColumnDef<User>[] = [
|
|
63
|
+
{ accessorKey: 'name', header: 'Name' },
|
|
64
|
+
{ accessorKey: 'email', header: 'Email' },
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
function UsersTable({ data }: { data: User[] }) {
|
|
68
|
+
return (
|
|
69
|
+
<DataTable
|
|
70
|
+
columns={columns}
|
|
71
|
+
data={data}
|
|
72
|
+
pagination={{ pageCount: 1, page: 1, pageSize: 10 }}
|
|
73
|
+
/>
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Client-Side Table
|
|
79
|
+
|
|
80
|
+
For simpler use cases with client-side pagination, sorting, and filtering:
|
|
81
|
+
|
|
82
|
+
```tsx
|
|
83
|
+
import { ClientSideTable } from 'table-craft'
|
|
84
|
+
|
|
85
|
+
function UsersTable({ data }: { data: User[] }) {
|
|
86
|
+
return (
|
|
87
|
+
<ClientSideTable
|
|
88
|
+
columns={columns}
|
|
89
|
+
data={data}
|
|
90
|
+
searchableColumns={[{ id: 'name', title: 'Name' }]}
|
|
91
|
+
filterableColumns={[
|
|
92
|
+
{
|
|
93
|
+
id: 'role',
|
|
94
|
+
title: 'Role',
|
|
95
|
+
options: [
|
|
96
|
+
{ label: 'Admin', value: 'admin' },
|
|
97
|
+
{ label: 'User', value: 'user' },
|
|
98
|
+
],
|
|
99
|
+
},
|
|
100
|
+
]}
|
|
101
|
+
/>
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Configuration
|
|
107
|
+
|
|
108
|
+
### TableProvider
|
|
109
|
+
|
|
110
|
+
Wrap your app (or a subtree) with `TableProvider` to set global defaults:
|
|
111
|
+
|
|
112
|
+
```tsx
|
|
113
|
+
import { TableProvider, createTableConfig } from 'table-craft'
|
|
114
|
+
|
|
115
|
+
const config = createTableConfig({
|
|
116
|
+
features: {
|
|
117
|
+
enableColumnVisibility: true,
|
|
118
|
+
enableRowSelection: true,
|
|
119
|
+
enablePagination: true,
|
|
120
|
+
},
|
|
121
|
+
pagination: {
|
|
122
|
+
defaultPageSize: 25,
|
|
123
|
+
pageSizeOptions: [10, 25, 50, 100],
|
|
124
|
+
},
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
function App() {
|
|
128
|
+
return (
|
|
129
|
+
<TableProvider config={config}>
|
|
130
|
+
<YourApp />
|
|
131
|
+
</TableProvider>
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Per-Table Config
|
|
137
|
+
|
|
138
|
+
Override global config on individual tables:
|
|
139
|
+
|
|
140
|
+
```tsx
|
|
141
|
+
<DataTable
|
|
142
|
+
columns={columns}
|
|
143
|
+
data={data}
|
|
144
|
+
config={{
|
|
145
|
+
features: { enableRowSelection: false },
|
|
146
|
+
pagination: { defaultPageSize: 50 },
|
|
147
|
+
}}
|
|
148
|
+
/>
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Config Layers
|
|
152
|
+
|
|
153
|
+
Configuration is resolved in this order (later layers override earlier ones):
|
|
154
|
+
|
|
155
|
+
1. **Defaults** — Built-in `DEFAULT_TABLE_CONFIG`
|
|
156
|
+
2. **Provider** — Global config from `TableProvider`
|
|
157
|
+
3. **Instance** — Per-table `config` prop
|
|
158
|
+
4. **Plugins** — Plugin-provided config (priority-ordered)
|
|
159
|
+
|
|
160
|
+
## Router Adapter
|
|
161
|
+
|
|
162
|
+
table-craft does not depend on any specific router. To enable URL-synced pagination, sorting, and filtering, provide a router adapter:
|
|
163
|
+
|
|
164
|
+
### Next.js (App Router)
|
|
165
|
+
|
|
166
|
+
```tsx
|
|
167
|
+
'use client'
|
|
168
|
+
import { useRouter, useSearchParams, usePathname } from 'next/navigation'
|
|
169
|
+
import { TableProvider, createTableConfig } from 'table-craft'
|
|
170
|
+
|
|
171
|
+
function Providers({ children }: { children: React.ReactNode }) {
|
|
172
|
+
const router = useRouter()
|
|
173
|
+
const searchParams = useSearchParams()
|
|
174
|
+
const pathname = usePathname()
|
|
175
|
+
|
|
176
|
+
const config = createTableConfig({
|
|
177
|
+
router: {
|
|
178
|
+
push: (url) => router.push(url),
|
|
179
|
+
replace: (url) => router.replace(url),
|
|
180
|
+
getSearchParams: () => new URLSearchParams(searchParams.toString()),
|
|
181
|
+
getPathname: () => pathname,
|
|
182
|
+
},
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
return <TableProvider config={config}>{children}</TableProvider>
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### React Router
|
|
190
|
+
|
|
191
|
+
```tsx
|
|
192
|
+
import { useNavigate, useSearchParams, useLocation } from 'react-router-dom'
|
|
193
|
+
import { TableProvider, createTableConfig } from 'table-craft'
|
|
194
|
+
|
|
195
|
+
function Providers({ children }: { children: React.ReactNode }) {
|
|
196
|
+
const navigate = useNavigate()
|
|
197
|
+
const [searchParams] = useSearchParams()
|
|
198
|
+
const location = useLocation()
|
|
199
|
+
|
|
200
|
+
const config = createTableConfig({
|
|
201
|
+
router: {
|
|
202
|
+
push: (url) => navigate(url),
|
|
203
|
+
replace: (url) => navigate(url, { replace: true }),
|
|
204
|
+
getSearchParams: () => searchParams,
|
|
205
|
+
getPathname: () => location.pathname,
|
|
206
|
+
},
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
return <TableProvider config={config}>{children}</TableProvider>
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### No Router (Default)
|
|
214
|
+
|
|
215
|
+
If no router adapter is provided, URL sync is silently disabled. Pagination, sorting, and filtering still work — they just manage state internally without updating the URL.
|
|
216
|
+
|
|
217
|
+
## Internationalization (i18n)
|
|
218
|
+
|
|
219
|
+
### Built-in English
|
|
220
|
+
|
|
221
|
+
By default, table-craft uses built-in English strings. No configuration needed.
|
|
222
|
+
|
|
223
|
+
### Custom Translations
|
|
224
|
+
|
|
225
|
+
Provide a `translationFn` in the config to integrate your own i18n system:
|
|
226
|
+
|
|
227
|
+
```tsx
|
|
228
|
+
import { useTranslations } from 'next-intl' // or any i18n library
|
|
229
|
+
|
|
230
|
+
function Providers({ children }) {
|
|
231
|
+
const t = useTranslations('table')
|
|
232
|
+
|
|
233
|
+
const config = createTableConfig({
|
|
234
|
+
i18n: {
|
|
235
|
+
translationFn: (key) => t(key),
|
|
236
|
+
},
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
return <TableProvider config={config}>{children}</TableProvider>
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### Available Translation Keys
|
|
244
|
+
|
|
245
|
+
`Filter`, `filter-by`, `Reset`, `add`, `add-filter`, `columns`, `showing`, `rows`, `previous`, `next`, `first`, `last`, `no-records-found`, `records`, `selected`, `selected-count`, `delete`, `export`, `view`, `edit`, `actions`, `more-actions`, `search`, `clear`, `apply`, `cancel`, `confirm`, `close`, `open`, `save`, `loading`, `error`, `success`, `warning`, `info`, `page`, `of`, `per-page`, `go-to-page`, `sort-ascending`, `sort-descending`, `no-sorting`, `hide-column`, `show-all`, `toggle-columns`, `row-actions`, `bulk-actions`, `select-all`, `deselect-all`, `rows-per-page`, `card-view`, `table-view`
|
|
246
|
+
|
|
247
|
+
## Feature Flags
|
|
248
|
+
|
|
249
|
+
Control which features are enabled:
|
|
250
|
+
|
|
251
|
+
```tsx
|
|
252
|
+
const config = createTableConfig({
|
|
253
|
+
features: {
|
|
254
|
+
enablePagination: true,
|
|
255
|
+
enableSorting: true,
|
|
256
|
+
enableFiltering: true,
|
|
257
|
+
enableColumnVisibility: true,
|
|
258
|
+
enableRowSelection: true,
|
|
259
|
+
enableMultiSort: false,
|
|
260
|
+
enableGlobalFilter: false,
|
|
261
|
+
enableColumnResizing: false,
|
|
262
|
+
enableColumnReordering: false,
|
|
263
|
+
enableExport: true,
|
|
264
|
+
enableCardView: true,
|
|
265
|
+
enableFloatingBar: true,
|
|
266
|
+
enableAdvancedFilter: false,
|
|
267
|
+
},
|
|
268
|
+
})
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
## RTL Support
|
|
272
|
+
|
|
273
|
+
Enable RTL layout via config:
|
|
274
|
+
|
|
275
|
+
```tsx
|
|
276
|
+
const config = createTableConfig({
|
|
277
|
+
i18n: {
|
|
278
|
+
direction: 'rtl',
|
|
279
|
+
},
|
|
280
|
+
})
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
Components automatically adjust padding, alignment, and icon positioning for RTL layouts.
|
|
284
|
+
|
|
285
|
+
## Plugins
|
|
286
|
+
|
|
287
|
+
Extend table behavior with plugins:
|
|
288
|
+
|
|
289
|
+
```tsx
|
|
290
|
+
import type { TablePlugin } from 'table-craft'
|
|
291
|
+
|
|
292
|
+
const auditPlugin: TablePlugin = {
|
|
293
|
+
name: 'audit-logging',
|
|
294
|
+
priority: 10,
|
|
295
|
+
config: {
|
|
296
|
+
features: {
|
|
297
|
+
enableRowSelection: true,
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const config = createTableConfig({
|
|
303
|
+
plugins: [auditPlugin],
|
|
304
|
+
})
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
Plugins are merged in priority order (lower numbers merge first, higher numbers override).
|
|
308
|
+
|
|
309
|
+
## Exported Components
|
|
310
|
+
|
|
311
|
+
| Component | Description |
|
|
312
|
+
|-----------|-------------|
|
|
313
|
+
| `DataTable` | Core table with server-side pagination support |
|
|
314
|
+
| `ClientSideTable` | High-level wrapper with client-side pagination |
|
|
315
|
+
| `DataTableToolbar` | Desktop toolbar with search, filters, view options |
|
|
316
|
+
| `DataTableMobileToolbar` | Mobile-responsive toolbar with drawer |
|
|
317
|
+
| `DataTablePagination` | Pagination controls |
|
|
318
|
+
| `DataTableColumnHeader` | Sortable column header |
|
|
319
|
+
| `DataTableViewOptions` | Column visibility toggle |
|
|
320
|
+
| `DataTableCardView` | Card layout renderer |
|
|
321
|
+
| `DataTableFloatingBar` | Floating action bar for selections |
|
|
322
|
+
| `DataTableFacetedFilter` | Multi-select faceted filter |
|
|
323
|
+
| `DataTableSingleSelectFilter` | Single-select filter |
|
|
324
|
+
| `DataTableRoleFilter` | Role-based filter with URL sync |
|
|
325
|
+
| `DataTableLoading` | Loading skeleton |
|
|
326
|
+
| `TableActionsRow` | Row-level action buttons |
|
|
327
|
+
| `DataTableAdvancedToolbar` | Advanced toolbar with multi-filter |
|
|
328
|
+
| `DataTableAdvancedFilter` | Advanced filter command palette |
|
|
329
|
+
| `DataTableAdvancedFilterItem` | Individual advanced filter chip |
|
|
330
|
+
| `DataTableMultiFilter` | Multi-rule filter popover |
|
|
331
|
+
| `TableProvider` | Config context provider |
|
|
332
|
+
|
|
333
|
+
## Exported Types
|
|
334
|
+
|
|
335
|
+
```tsx
|
|
336
|
+
import type {
|
|
337
|
+
// Table types
|
|
338
|
+
Option,
|
|
339
|
+
DataTableSearchableColumn,
|
|
340
|
+
DataTableQuerySearchable,
|
|
341
|
+
DataTableFilterableColumn,
|
|
342
|
+
DataTableFilterOption,
|
|
343
|
+
FilterOptions,
|
|
344
|
+
|
|
345
|
+
// Config types
|
|
346
|
+
TableConfig,
|
|
347
|
+
TableConfigInput,
|
|
348
|
+
TableRouterAdapter,
|
|
349
|
+
TableFeatureFlags,
|
|
350
|
+
TablePaginationConfig,
|
|
351
|
+
TableSearchConfig,
|
|
352
|
+
TableI18nConfig,
|
|
353
|
+
TablePerformanceConfig,
|
|
354
|
+
TableEnterpriseConfig,
|
|
355
|
+
TableDevConfig,
|
|
356
|
+
TablePlugin,
|
|
357
|
+
DeepPartial,
|
|
358
|
+
|
|
359
|
+
// Pagination types
|
|
360
|
+
Pagination,
|
|
361
|
+
BackendPagination,
|
|
362
|
+
PaginationMeta,
|
|
363
|
+
PaginationLinks,
|
|
364
|
+
} from 'table-craft'
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
## TypeScript
|
|
368
|
+
|
|
369
|
+
table-craft is written in TypeScript and ships type declarations. All components are generic:
|
|
370
|
+
|
|
371
|
+
```tsx
|
|
372
|
+
// Column definitions are fully typed
|
|
373
|
+
const columns: ColumnDef<User>[] = [
|
|
374
|
+
{
|
|
375
|
+
accessorKey: 'name',
|
|
376
|
+
header: ({ column }) => (
|
|
377
|
+
<DataTableColumnHeader column={column} title="Name" />
|
|
378
|
+
),
|
|
379
|
+
},
|
|
380
|
+
]
|
|
381
|
+
|
|
382
|
+
// Table instance is typed
|
|
383
|
+
<DataTable<User>
|
|
384
|
+
columns={columns}
|
|
385
|
+
data={users}
|
|
386
|
+
pagination={pagination}
|
|
387
|
+
/>
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
## 🤝 Contributing
|
|
391
|
+
|
|
392
|
+
Contributions are welcome! If you have suggestions for improvements or encounter any issues, please open an issue or submit a pull request on the [GitHub repository](https://github.com/Ahmed-Elkhdrawy/table-craft).
|
|
393
|
+
|
|
394
|
+
Steps to Contribute:
|
|
395
|
+
|
|
396
|
+
1. Fork the repository. 🍴
|
|
397
|
+
2. Create a new branch for your feature or bugfix. 🌿
|
|
398
|
+
3. Commit your changes. 💾
|
|
399
|
+
4. Push your branch and submit a pull request. 🚀
|
|
400
|
+
|
|
401
|
+
## 📜 License
|
|
402
|
+
|
|
403
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
|
404
|
+
|
|
405
|
+
---
|
|
406
|
+
|
|
407
|
+
**Made with ❤️ by [Ahmed Elkhdrawy](https://github.com/Ahmed-Elkhdrawy).**
|