@snowpact/react-tanstack-query-table 1.5.3 → 1.5.5
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/README.md +34 -52
- package/dist/index.cjs +20 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +26 -73
- package/dist/index.js +2950 -5826
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +2 -6
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Ultra-light, registry-based data table for React + TanStack Table + TanStack Que
|
|
|
10
10
|
- **Registry-based**: Inject your own i18n and Link component
|
|
11
11
|
- **TypeScript**: Full type support with generics
|
|
12
12
|
- **Two modes**: Client-side and Server-side pagination/filtering/sorting
|
|
13
|
-
- **Customizable**: Override styles via CSS variables
|
|
13
|
+
- **Customizable**: Override styles via CSS variables
|
|
14
14
|
|
|
15
15
|
## Quick Setup
|
|
16
16
|
|
|
@@ -34,13 +34,36 @@ import '@snowpact/react-tanstack-query-table/styles.css';
|
|
|
34
34
|
// In your app entry point (main.tsx or App.tsx)
|
|
35
35
|
import { setupSnowTable } from '@snowpact/react-tanstack-query-table';
|
|
36
36
|
import { Link } from 'react-router-dom';
|
|
37
|
+
import { t } from './i18n'; // Your translation function
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
setupSnowTable({
|
|
40
|
+
translate: (key) => t(key),
|
|
41
|
+
LinkComponent: Link,
|
|
42
|
+
});
|
|
43
|
+
```
|
|
40
44
|
|
|
45
|
+
**Translation keys:**
|
|
46
|
+
- **Dynamic keys** (column labels, etc.) - Your `translate` function handles these
|
|
47
|
+
- **Static UI keys** (`dataTable.*`) - Built-in English defaults if `translate` returns the key unchanged
|
|
48
|
+
|
|
49
|
+
| Key | Default |
|
|
50
|
+
|-----|---------|
|
|
51
|
+
| `dataTable.search` | "Search..." |
|
|
52
|
+
| `dataTable.elements` | "elements" |
|
|
53
|
+
| `dataTable.paginationSize` | "per page" |
|
|
54
|
+
| `dataTable.columnsConfiguration` | "Columns" |
|
|
55
|
+
| `dataTable.resetFilters` | "Reset filters" |
|
|
56
|
+
| `dataTable.resetColumns` | "Reset" |
|
|
57
|
+
| `dataTable.searchFilters` | "Search..." |
|
|
58
|
+
| `dataTable.searchEmpty` | "No results found" |
|
|
59
|
+
| `dataTable.selectFilter` | "Select..." |
|
|
60
|
+
|
|
61
|
+
Override static keys without i18n:
|
|
62
|
+
```tsx
|
|
41
63
|
setupSnowTable({
|
|
42
|
-
|
|
64
|
+
translate: (key) => key,
|
|
43
65
|
LinkComponent: Link,
|
|
66
|
+
translations: { 'dataTable.search': 'Rechercher...' },
|
|
44
67
|
});
|
|
45
68
|
```
|
|
46
69
|
|
|
@@ -104,51 +127,6 @@ Override CSS variables to match your design:
|
|
|
104
127
|
}
|
|
105
128
|
```
|
|
106
129
|
|
|
107
|
-
### Setup with i18n (react-i18next)
|
|
108
|
-
|
|
109
|
-
```tsx
|
|
110
|
-
import { useTranslation } from 'react-i18next';
|
|
111
|
-
|
|
112
|
-
// Get t function at module level or use a hook wrapper
|
|
113
|
-
const { t } = i18n;
|
|
114
|
-
|
|
115
|
-
setupSnowTable({
|
|
116
|
-
t: (key) => t(key),
|
|
117
|
-
LinkComponent: Link,
|
|
118
|
-
});
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
The `t` function is automatically called with:
|
|
122
|
-
- All column `key` values from your `columnConfig` (e.g., `t('name')`, `t('email')`, `t('status')`)
|
|
123
|
-
- Internal UI keys:
|
|
124
|
-
- `dataTable.search` - Search placeholder
|
|
125
|
-
- `dataTable.elements` - "elements" label
|
|
126
|
-
- `dataTable.searchEmpty` - Empty state text
|
|
127
|
-
- `dataTable.resetFilters` - Reset button tooltip
|
|
128
|
-
- `dataTable.columns` - Columns button label
|
|
129
|
-
|
|
130
|
-
### Override component styles (rare)
|
|
131
|
-
|
|
132
|
-
For deep customization, override internal Tailwind classes:
|
|
133
|
-
|
|
134
|
-
```tsx
|
|
135
|
-
setupSnowTable({
|
|
136
|
-
t,
|
|
137
|
-
LinkComponent: Link,
|
|
138
|
-
styles: {
|
|
139
|
-
button: {
|
|
140
|
-
visual: 'rounded-full bg-primary text-primary-foreground',
|
|
141
|
-
hover: 'hover:bg-primary/90',
|
|
142
|
-
},
|
|
143
|
-
table: {
|
|
144
|
-
header: 'bg-slate-100 dark:bg-slate-800',
|
|
145
|
-
rowHover: 'hover:bg-slate-50',
|
|
146
|
-
},
|
|
147
|
-
input: 'rounded-full border-2 border-primary',
|
|
148
|
-
},
|
|
149
|
-
});
|
|
150
|
-
```
|
|
151
|
-
|
|
152
130
|
---
|
|
153
131
|
|
|
154
132
|
## Client vs Server Mode
|
|
@@ -243,7 +221,7 @@ For API calls with built-in mutation handling:
|
|
|
243
221
|
|
|
244
222
|
### Endpoint with Confirmation
|
|
245
223
|
|
|
246
|
-
Use `withConfirm`
|
|
224
|
+
Use `withConfirm` to show a confirmation dialog before the endpoint is called:
|
|
247
225
|
|
|
248
226
|
```tsx
|
|
249
227
|
{
|
|
@@ -252,12 +230,16 @@ Use `withConfirm` for optional confirmation before the endpoint is called:
|
|
|
252
230
|
label: 'Delete',
|
|
253
231
|
variant: 'danger',
|
|
254
232
|
endpoint: (item) => api.deleteUser(item.id),
|
|
255
|
-
withConfirm: (item) =>
|
|
233
|
+
withConfirm: async (item) => {
|
|
234
|
+
// Return true to proceed, false to cancel
|
|
235
|
+
return window.confirm(`Delete ${item.name}?`);
|
|
236
|
+
// Or use your own dialog library (e.g., sweetalert2, radix-ui/dialog)
|
|
237
|
+
},
|
|
256
238
|
onSuccess: () => queryClient.invalidateQueries(['users']),
|
|
257
239
|
}
|
|
258
240
|
```
|
|
259
241
|
|
|
260
|
-
|
|
242
|
+
The endpoint is only called if `withConfirm` returns `true` (or a truthy Promise).
|
|
261
243
|
|
|
262
244
|
### Dynamic Actions
|
|
263
245
|
|