munza-x-data-grid 1.4.1 → 1.4.2

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/dist/README.md CHANGED
@@ -1,288 +1,288 @@
1
- # munza-x-data-grid
2
-
3
- A flexible, feature-rich React data grid component built on top of [@tanstack/react-table](https://tanstack.com/table), with Tailwind CSS v4 styling and shadcn/ui primitives.
4
-
5
- ---
6
-
7
- ## Installation
8
-
9
- ```bash
10
- npm install munza-x-data-grid
11
- ```
12
-
13
- Import the stylesheet in your app entry point:
14
-
15
- ```js
16
- import 'munza-x-data-grid/style.css';
17
- ```
18
-
19
- ### Peer Dependencies
20
-
21
- ```bash
22
- npm install react react-dom
23
- ```
24
-
25
- Requires **React 18 or 19**.
26
-
27
- ---
28
-
29
- ## Basic Usage
30
-
31
- ```tsx
32
- import { Grid, useGridState, type ColumnDef } from 'munza-x-data-grid';
33
- import 'munza-x-data-grid/style.css';
34
-
35
- type Person = {
36
- firstName: string;
37
- lastName: string;
38
- age: number;
39
- };
40
-
41
- const columns: ColumnDef<Person>[] = [
42
- { accessorKey: 'firstName', header: 'First Name' },
43
- { accessorKey: 'lastName', header: 'Last Name' },
44
- { accessorKey: 'age', header: 'Age' },
45
- ];
46
-
47
- const data: Person[] = [{ firstName: 'Alice', lastName: 'Smith', age: 30 }];
48
-
49
- export default function App() {
50
- const { state, handlers } = useGridState();
51
-
52
- return (
53
- <Grid
54
- columns={columns}
55
- payload={{ data, total: data.length }}
56
- state={state}
57
- {...handlers}
58
- />
59
- );
60
- }
61
- ```
62
-
63
- ---
64
-
65
- ## API Reference
66
-
67
- ### `<Grid />`
68
-
69
- The top-level component that renders the full data grid.
70
-
71
- | Prop | Type | Required | Description |
72
- | ----------------------- | ------------------------------------------ | -------- | -------------------------------------------------------- |
73
- | `columns` | `ColumnDef<T>[]` | ✅ | Column definitions (TanStack Table format) |
74
- | `payload` | `{ data: T[], total: number }` | ✅ | Row data and total count for pagination |
75
- | `state` | `Partial<TableState>` | ✅ | Controlled table state (from `useGridState`) |
76
- | `onColumnFiltersChange` | `OnChangeFn<ColumnFiltersState>` | — | Callback for column filter changes |
77
- | `onPaginationChange` | `OnChangeFn<PaginationState>` | — | Callback for pagination changes |
78
- | `onSortingChange` | `OnChangeFn<SortingState>` | — | Callback for sort changes |
79
- | `setGlobalFilter` | `Dispatch<SetStateAction<string>>` | — | Callback to update the global search filter |
80
- | `isLoading` | `boolean` | — | Displays a loading state |
81
- | `isError` | `boolean` | — | Displays an error state |
82
- | `manualPagination` | `boolean` | — | Set `true` for server-side pagination (default: `false`) |
83
- | `getRowCanExpand` | `(row: Row<T>) => boolean` | — | Controls which rows are expandable |
84
- | `renderSubComponent` | `(props: { row: Row<T> }) => ReactElement` | — | Renders expanded row content |
85
-
86
- ---
87
-
88
- ### `useGridState()`
89
-
90
- Hook that provides controlled state and event handlers to pass into `<Grid />`.
91
-
92
- ```tsx
93
- const { state, handlers } = useGridState();
94
- ```
95
-
96
- **Returns:**
97
-
98
- | Key | Description |
99
- | ---------- | ----------------------------------------------------------------------------------------------------- |
100
- | `state` | Partial `TableState` object (sorting, pagination, filters, etc.) |
101
- | `handlers` | Object containing `onSortingChange`, `onPaginationChange`, `onColumnFiltersChange`, `setGlobalFilter` |
102
-
103
- Spread `handlers` directly onto `<Grid />`:
104
-
105
- ```tsx
106
- <Grid state={state} {...handlers} columns={columns} payload={payload} />
107
- ```
108
-
109
- ### Tailwind v4 Setup
110
-
111
- If you're using Tailwind v4, add this to your `app.css` so Tailwind scans the grid's classes:
112
-
113
- ```css
114
- @source "../node_modules/munza-x-data-grid/**/*.{js,ts,jsx,tsx}";
115
- @theme inline {
116
- --color-background: var(--background);
117
- --color-foreground: var(--foreground);
118
- --color-border: var(--border);
119
- --color-muted: var(--muted);
120
- --color-accent: var(--accent);
121
- }
122
-
123
- :root {
124
- --background: oklch(1 0 0);
125
- --foreground: oklch(0.145 0 0);
126
- --border: oklch(0.922 0 0);
127
- --muted: oklch(0.97 0 0);
128
- --accent: oklch(0.97 0 0);
129
- }
130
-
131
- .dark {
132
- --background: oklch(0.145 0 0);
133
- --foreground: oklch(0.985 0 0);
134
- --border: oklch(1 0 0 / 10%);
135
- --muted: oklch(0.269 0 0);
136
- --accent: oklch(0.269 0 0);
137
- }
138
- ```
139
-
140
- ---
141
-
142
- ## Column Definitions
143
-
144
- Columns follow the standard [TanStack Table `ColumnDef`](https://tanstack.com/table/latest/docs/api/core/column-def) format with an additional `meta` field for filter configuration.
145
-
146
- ### Filter Variants
147
-
148
- Set `meta.filterVariant` on a column to control its filter UI:
149
-
150
- ```tsx
151
- {
152
- accessorKey: 'status',
153
- header: 'Status',
154
- meta: {
155
- filterVariant: 'select', // dropdown filter
156
- },
157
- }
158
-
159
- {
160
- accessorKey: 'age',
161
- header: 'Age',
162
- meta: {
163
- filterVariant: 'text', // text input filter
164
- },
165
- }
166
- ```
167
-
168
- ### Row Number Column
169
-
170
- ```tsx
171
- {
172
- accessorFn: (_row, index) => index + 1,
173
- cell: ({ row }) => row.index + 1,
174
- id: 'rowNumber',
175
- header: '',
176
- size: 54,
177
- maxSize: 54,
178
- enableColumnFilter: false,
179
- }
180
- ```
181
-
182
- ### Checkbox Selection Column
183
-
184
- ```tsx
185
- {
186
- id: 'select',
187
- header: ({ table }) => (
188
- <Checkbox
189
- checked={
190
- table.getIsAllPageRowsSelected() ||
191
- (table.getIsSomePageRowsSelected() && 'indeterminate')
192
- }
193
- onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
194
- aria-label="Select all"
195
- />
196
- ),
197
- cell: ({ row }) => (
198
- <Checkbox
199
- checked={row.getIsSelected()}
200
- onCheckedChange={(value) => row.toggleSelected(!!value)}
201
- aria-label="Select row"
202
- />
203
- ),
204
- size: 40,
205
- maxSize: 40,
206
- enableColumnFilter: false,
207
- }
208
- ```
209
-
210
- ---
211
-
212
- ## Server-Side Pagination
213
-
214
- Set `manualPagination` to `true` and pass `payload.total` as the full server-side count.
215
-
216
- ```tsx
217
- <Grid
218
- columns={columns}
219
- payload={{ data: serverData, total: serverTotal }}
220
- state={state}
221
- {...handlers}
222
- manualPagination={true}
223
- />
224
- ```
225
-
226
- The built-in pagination UI supports the following page sizes:
227
-
228
- ```
229
- 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000
230
- ```
231
-
232
- ---
233
-
234
- ## Expandable Rows
235
-
236
- ```tsx
237
- <Grid
238
- columns={columns}
239
- payload={payload}
240
- state={state}
241
- {...handlers}
242
- getRowCanExpand={(row) => !!row.original.subRows?.length}
243
- renderSubComponent={({ row }) => (
244
- <div className="p-4">
245
- <pre>{JSON.stringify(row.original, null, 2)}</pre>
246
- </div>
247
- )}
248
- />
249
- ```
250
-
251
- ---
252
-
253
- ## Column Pinning
254
-
255
- Column pinning is managed internally by the grid. No additional configuration is required — use the built-in toolbar UI to pin columns left or right.
256
-
257
- ---
258
-
259
- ## Default Column Sizing
260
-
261
- | Property | Default |
262
- | --------- | ------- |
263
- | `size` | `180px` |
264
- | `minSize` | `180px` |
265
- | `maxSize` | `180px` |
266
-
267
- Override per-column:
268
-
269
- ```tsx
270
- {
271
- accessorKey: 'id',
272
- size: 60,
273
- minSize: 60,
274
- maxSize: 60,
275
- }
276
- ```
277
-
278
- ---
279
-
280
- ## TypeScript
281
-
282
- All props and hooks are fully typed. Import types directly from the package:
283
-
284
- ```ts
285
- import type { ColumnDef } from 'munza-x-data-grid';
286
- ```
287
-
288
- TanStack Table types (`Row`, `TableState`, `PaginationState`, etc.) are re-exported and available from `@tanstack/react-table`.
1
+ # munza-x-data-grid
2
+
3
+ A flexible, feature-rich React data grid component built on top of [@tanstack/react-table](https://tanstack.com/table), with Tailwind CSS v4 styling and shadcn/ui primitives.
4
+
5
+ ---
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install munza-x-data-grid
11
+ ```
12
+
13
+ Import the stylesheet in your app entry point:
14
+
15
+ ```js
16
+ import 'munza-x-data-grid/style.css';
17
+ ```
18
+
19
+ ### Peer Dependencies
20
+
21
+ ```bash
22
+ npm install react react-dom
23
+ ```
24
+
25
+ Requires **React 18 or 19**.
26
+
27
+ ---
28
+
29
+ ## Basic Usage
30
+
31
+ ```tsx
32
+ import { Grid, useGridState, type ColumnDef } from 'munza-x-data-grid';
33
+ import 'munza-x-data-grid/style.css';
34
+
35
+ type Person = {
36
+ firstName: string;
37
+ lastName: string;
38
+ age: number;
39
+ };
40
+
41
+ const columns: ColumnDef<Person>[] = [
42
+ { accessorKey: 'firstName', header: 'First Name' },
43
+ { accessorKey: 'lastName', header: 'Last Name' },
44
+ { accessorKey: 'age', header: 'Age' },
45
+ ];
46
+
47
+ const data: Person[] = [{ firstName: 'Alice', lastName: 'Smith', age: 30 }];
48
+
49
+ export default function App() {
50
+ const { state, handlers } = useGridState();
51
+
52
+ return (
53
+ <Grid
54
+ columns={columns}
55
+ payload={{ data, total: data.length }}
56
+ state={state}
57
+ {...handlers}
58
+ />
59
+ );
60
+ }
61
+ ```
62
+
63
+ ---
64
+
65
+ ## API Reference
66
+
67
+ ### `<Grid />`
68
+
69
+ The top-level component that renders the full data grid.
70
+
71
+ | Prop | Type | Required | Description |
72
+ | ----------------------- | ------------------------------------------ | -------- | -------------------------------------------------------- |
73
+ | `columns` | `ColumnDef<T>[]` | ✅ | Column definitions (TanStack Table format) |
74
+ | `payload` | `{ data: T[], total: number }` | ✅ | Row data and total count for pagination |
75
+ | `state` | `Partial<TableState>` | ✅ | Controlled table state (from `useGridState`) |
76
+ | `onColumnFiltersChange` | `OnChangeFn<ColumnFiltersState>` | — | Callback for column filter changes |
77
+ | `onPaginationChange` | `OnChangeFn<PaginationState>` | — | Callback for pagination changes |
78
+ | `onSortingChange` | `OnChangeFn<SortingState>` | — | Callback for sort changes |
79
+ | `setGlobalFilter` | `Dispatch<SetStateAction<string>>` | — | Callback to update the global search filter |
80
+ | `isLoading` | `boolean` | — | Displays a loading state |
81
+ | `isError` | `boolean` | — | Displays an error state |
82
+ | `manualPagination` | `boolean` | — | Set `true` for server-side pagination (default: `false`) |
83
+ | `getRowCanExpand` | `(row: Row<T>) => boolean` | — | Controls which rows are expandable |
84
+ | `renderSubComponent` | `(props: { row: Row<T> }) => ReactElement` | — | Renders expanded row content |
85
+
86
+ ---
87
+
88
+ ### `useGridState()`
89
+
90
+ Hook that provides controlled state and event handlers to pass into `<Grid />`.
91
+
92
+ ```tsx
93
+ const { state, handlers } = useGridState();
94
+ ```
95
+
96
+ **Returns:**
97
+
98
+ | Key | Description |
99
+ | ---------- | ----------------------------------------------------------------------------------------------------- |
100
+ | `state` | Partial `TableState` object (sorting, pagination, filters, etc.) |
101
+ | `handlers` | Object containing `onSortingChange`, `onPaginationChange`, `onColumnFiltersChange`, `setGlobalFilter` |
102
+
103
+ Spread `handlers` directly onto `<Grid />`:
104
+
105
+ ```tsx
106
+ <Grid state={state} {...handlers} columns={columns} payload={payload} />
107
+ ```
108
+
109
+ ### Tailwind v4 Setup
110
+
111
+ If you're using Tailwind v4, add this to your `app.css` so Tailwind scans the grid's classes:
112
+
113
+ ```css
114
+ @source "../node_modules/munza-x-data-grid/**/*.{js,ts,jsx,tsx}";
115
+ @theme inline {
116
+ --color-background: var(--background);
117
+ --color-foreground: var(--foreground);
118
+ --color-border: var(--border);
119
+ --color-muted: var(--muted);
120
+ --color-accent: var(--accent);
121
+ }
122
+
123
+ :root {
124
+ --background: oklch(1 0 0);
125
+ --foreground: oklch(0.145 0 0);
126
+ --border: oklch(0.922 0 0);
127
+ --muted: oklch(0.97 0 0);
128
+ --accent: oklch(0.97 0 0);
129
+ }
130
+
131
+ .dark {
132
+ --background: oklch(0.145 0 0);
133
+ --foreground: oklch(0.985 0 0);
134
+ --border: oklch(1 0 0 / 10%);
135
+ --muted: oklch(0.269 0 0);
136
+ --accent: oklch(0.269 0 0);
137
+ }
138
+ ```
139
+
140
+ ---
141
+
142
+ ## Column Definitions
143
+
144
+ Columns follow the standard [TanStack Table `ColumnDef`](https://tanstack.com/table/latest/docs/api/core/column-def) format with an additional `meta` field for filter configuration.
145
+
146
+ ### Filter Variants
147
+
148
+ Set `meta.filterVariant` on a column to control its filter UI:
149
+
150
+ ```tsx
151
+ {
152
+ accessorKey: 'status',
153
+ header: 'Status',
154
+ meta: {
155
+ filterVariant: 'select', // dropdown filter
156
+ },
157
+ }
158
+
159
+ {
160
+ accessorKey: 'age',
161
+ header: 'Age',
162
+ meta: {
163
+ filterVariant: 'text', // text input filter
164
+ },
165
+ }
166
+ ```
167
+
168
+ ### Row Number Column
169
+
170
+ ```tsx
171
+ {
172
+ accessorFn: (_row, index) => index + 1,
173
+ cell: ({ row }) => row.index + 1,
174
+ id: 'rowNumber',
175
+ header: '',
176
+ size: 54,
177
+ maxSize: 54,
178
+ enableColumnFilter: false,
179
+ }
180
+ ```
181
+
182
+ ### Checkbox Selection Column
183
+
184
+ ```tsx
185
+ {
186
+ id: 'select',
187
+ header: ({ table }) => (
188
+ <Checkbox
189
+ checked={
190
+ table.getIsAllPageRowsSelected() ||
191
+ (table.getIsSomePageRowsSelected() && 'indeterminate')
192
+ }
193
+ onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
194
+ aria-label="Select all"
195
+ />
196
+ ),
197
+ cell: ({ row }) => (
198
+ <Checkbox
199
+ checked={row.getIsSelected()}
200
+ onCheckedChange={(value) => row.toggleSelected(!!value)}
201
+ aria-label="Select row"
202
+ />
203
+ ),
204
+ size: 40,
205
+ maxSize: 40,
206
+ enableColumnFilter: false,
207
+ }
208
+ ```
209
+
210
+ ---
211
+
212
+ ## Server-Side Pagination
213
+
214
+ Set `manualPagination` to `true` and pass `payload.total` as the full server-side count.
215
+
216
+ ```tsx
217
+ <Grid
218
+ columns={columns}
219
+ payload={{ data: serverData, total: serverTotal }}
220
+ state={state}
221
+ {...handlers}
222
+ manualPagination={true}
223
+ />
224
+ ```
225
+
226
+ The built-in pagination UI supports the following page sizes:
227
+
228
+ ```
229
+ 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000
230
+ ```
231
+
232
+ ---
233
+
234
+ ## Expandable Rows
235
+
236
+ ```tsx
237
+ <Grid
238
+ columns={columns}
239
+ payload={payload}
240
+ state={state}
241
+ {...handlers}
242
+ getRowCanExpand={(row) => !!row.original.subRows?.length}
243
+ renderSubComponent={({ row }) => (
244
+ <div className="p-4">
245
+ <pre>{JSON.stringify(row.original, null, 2)}</pre>
246
+ </div>
247
+ )}
248
+ />
249
+ ```
250
+
251
+ ---
252
+
253
+ ## Column Pinning
254
+
255
+ Column pinning is managed internally by the grid. No additional configuration is required — use the built-in toolbar UI to pin columns left or right.
256
+
257
+ ---
258
+
259
+ ## Default Column Sizing
260
+
261
+ | Property | Default |
262
+ | --------- | ------- |
263
+ | `size` | `180px` |
264
+ | `minSize` | `180px` |
265
+ | `maxSize` | `180px` |
266
+
267
+ Override per-column:
268
+
269
+ ```tsx
270
+ {
271
+ accessorKey: 'id',
272
+ size: 60,
273
+ minSize: 60,
274
+ maxSize: 60,
275
+ }
276
+ ```
277
+
278
+ ---
279
+
280
+ ## TypeScript
281
+
282
+ All props and hooks are fully typed. Import types directly from the package:
283
+
284
+ ```ts
285
+ import type { ColumnDef } from 'munza-x-data-grid';
286
+ ```
287
+
288
+ TanStack Table types (`Row`, `TableState`, `PaginationState`, etc.) are re-exported and available from `@tanstack/react-table`.