@toolbox-web/grid-react 0.0.2 → 0.0.3

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.
Files changed (2) hide show
  1. package/README.md +181 -56
  2. package/package.json +50 -50
package/README.md CHANGED
@@ -1,17 +1,54 @@
1
1
  # @toolbox-web/grid-react
2
2
 
3
- React adapter library for [@toolbox-web/grid](https://www.npmjs.com/package/@toolbox-web/grid) - a high-performance, framework-agnostic data grid web component.
3
+ [![npm](https://img.shields.io/npm/v/@toolbox-web/grid-react.svg)](https://www.npmjs.com/package/@toolbox-web/grid-react)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](../../LICENSE)
5
+ [![GitHub Sponsors](https://img.shields.io/badge/Sponsor-❤-ea4aaa?logo=github)](https://github.com/sponsors/OysteinAmundsen)
6
+
7
+ React adapter for `@toolbox-web/grid` data grid component. Provides components and hooks for declarative React integration with custom cell renderers and editors.
8
+
9
+ ## Features
10
+
11
+ - ✅ **Full React integration** - Use JSX for cell renderers and editors
12
+ - ✅ **Declarative columns** - Define columns via props or `GridColumn` components
13
+ - ✅ **Render props** - Clean `children` syntax for custom cells
14
+ - ✅ **Hooks API** - `useGrid` and `useGridEvent` for programmatic access
15
+ - ✅ **Ref forwarding** - Access grid instance via `DataGridRef`
16
+ - ✅ **Master-detail** - `GridDetailPanel` for expandable rows
17
+ - ✅ **Tool panels** - `GridToolPanel` for custom sidebar content
18
+ - ✅ **Full type safety** - TypeScript generics support
19
+ - ✅ **React 18+** - Concurrent features and Suspense compatible
4
20
 
5
21
  ## Installation
6
22
 
7
23
  ```bash
24
+ # npm
8
25
  npm install @toolbox-web/grid @toolbox-web/grid-react
26
+
27
+ # yarn
28
+ yarn add @toolbox-web/grid @toolbox-web/grid-react
29
+
30
+ # pnpm
31
+ pnpm add @toolbox-web/grid @toolbox-web/grid-react
32
+
33
+ # bun
34
+ bun add @toolbox-web/grid @toolbox-web/grid-react
35
+ ```
36
+
37
+ ## Quick Start
38
+
39
+ ### 1. Register the Grid Component
40
+
41
+ In your application entry point, import the grid registration:
42
+
43
+ ```typescript
44
+ // main.tsx or index.tsx
45
+ import '@toolbox-web/grid';
9
46
  ```
10
47
 
11
- ## Basic Usage
48
+ ### 2. Use in Components
12
49
 
13
50
  ```tsx
14
- import { DataGrid, GridColumn } from '@toolbox-web/grid-react';
51
+ import { DataGrid } from '@toolbox-web/grid-react';
15
52
 
16
53
  interface Employee {
17
54
  id: number;
@@ -60,11 +97,7 @@ const config: ReactGridConfig<Employee> = {
60
97
  field: 'status',
61
98
  header: 'Status',
62
99
  // Custom React renderer - same property name as vanilla!
63
- renderer: (ctx) => (
64
- <span className={`badge badge-${ctx.value.toLowerCase()}`}>
65
- {ctx.value}
66
- </span>
67
- ),
100
+ renderer: (ctx) => <span className={`badge badge-${ctx.value.toLowerCase()}`}>{ctx.value}</span>,
68
101
  },
69
102
  ],
70
103
  };
@@ -74,6 +107,14 @@ function EmployeeGrid() {
74
107
  }
75
108
  ```
76
109
 
110
+ **Renderer Context:**
111
+
112
+ | Property | Type | Description |
113
+ | -------- | --------- | ------------------------ |
114
+ | `value` | `TValue` | The cell value |
115
+ | `row` | `TRow` | The full row data object |
116
+ | `column` | `unknown` | The column configuration |
117
+
77
118
  ### Using GridColumn Components
78
119
 
79
120
  Use the `GridColumn` component with a render prop:
@@ -125,6 +166,16 @@ const config: ReactGridConfig<Employee> = {
125
166
  };
126
167
  ```
127
168
 
169
+ **Editor Context:**
170
+
171
+ | Property | Type | Description |
172
+ | -------- | ------------- | ---------------------------- |
173
+ | `value` | `TValue` | The current cell value |
174
+ | `row` | `TRow` | The full row data object |
175
+ | `column` | `unknown` | The column configuration |
176
+ | `commit` | `(v) => void` | Callback to commit new value |
177
+ | `cancel` | `() => void` | Callback to cancel editing |
178
+
128
179
  ### Using GridColumn
129
180
 
130
181
  ```tsx
@@ -179,11 +230,11 @@ function EmployeeGrid() {
179
230
 
180
231
  **GridDetailPanel Props:**
181
232
 
182
- | Prop | Type | Default | Description |
183
- | ------------------ | ----------------------------------------- | --------- | ------------------------------------ |
184
- | `children` | `(ctx: DetailPanelContext) => ReactNode` | Required | Render function for panel content |
185
- | `showExpandColumn` | `boolean` | `true` | Show expand/collapse chevron column |
186
- | `animation` | `'slide' \| 'fade' \| false` | `'slide'` | Animation style for expand/collapse |
233
+ | Prop | Type | Default | Description |
234
+ | ------------------ | ---------------------------------------- | --------- | ----------------------------------- |
235
+ | `children` | `(ctx: DetailPanelContext) => ReactNode` | Required | Render function for panel content |
236
+ | `showExpandColumn` | `boolean` | `true` | Show expand/collapse chevron column |
237
+ | `animation` | `'slide' \| 'fade' \| false` | `'slide'` | Animation style for expand/collapse |
187
238
 
188
239
  ## Custom Tool Panels with GridToolPanel
189
240
 
@@ -229,56 +280,58 @@ function EmployeeGrid() {
229
280
 
230
281
  **GridToolPanel Props:**
231
282
 
232
- | Prop | Type | Default | Description |
233
- | ---------- | --------------------------------------- | ---------- | ------------------------------------ |
234
- | `id` | `string` | Required | Unique panel identifier |
235
- | `title` | `string` | Required | Panel title in accordion header |
236
- | `children` | `(ctx: ToolPanelContext) => ReactNode` | Required | Render function for panel content |
237
- | `icon` | `string` | - | Icon for the accordion header |
238
- | `tooltip` | `string` | - | Tooltip text for header |
239
- | `order` | `number` | `100` | Panel sort order (lower = higher) |
283
+ | Prop | Type | Default | Description |
284
+ | ---------- | -------------------------------------- | -------- | --------------------------------- |
285
+ | `id` | `string` | Required | Unique panel identifier |
286
+ | `title` | `string` | Required | Panel title in accordion header |
287
+ | `children` | `(ctx: ToolPanelContext) => ReactNode` | Required | Render function for panel content |
288
+ | `icon` | `string` | - | Icon for the accordion header |
289
+ | `tooltip` | `string` | - | Tooltip text for header |
290
+ | `order` | `number` | `100` | Panel sort order (lower = higher) |
240
291
 
241
- ## Using Refs
292
+ ## Hooks
293
+
294
+ ### useGrid
242
295
 
243
296
  Access the grid instance for programmatic control:
244
297
 
245
298
  ```tsx
246
- import { DataGrid, DataGridRef } from '@toolbox-web/grid-react';
247
- import { useRef } from 'react';
299
+ import { DataGrid, useGrid } from '@toolbox-web/grid-react';
248
300
 
249
301
  function MyComponent() {
250
- const gridRef = useRef<DataGridRef>(null);
302
+ const { ref, isReady, forceLayout, getConfig } = useGrid<Employee>();
251
303
 
252
304
  const handleExport = async () => {
253
- const config = await gridRef.current?.getConfig();
305
+ const config = await getConfig();
254
306
  console.log('Columns:', config?.columns);
255
307
  };
256
308
 
257
309
  return (
258
310
  <>
259
311
  <button onClick={handleExport}>Export</button>
260
- <DataGrid ref={gridRef} rows={employees} />
312
+ <button onClick={() => forceLayout()}>Refresh Layout</button>
313
+ <DataGrid ref={ref} rows={employees} />
261
314
  </>
262
315
  );
263
316
  }
264
317
  ```
265
318
 
266
- ## useGrid Hook
319
+ ### useGridEvent
267
320
 
268
- For more complex scenarios, use the `useGrid` hook:
321
+ Type-safe event subscription with automatic cleanup:
269
322
 
270
323
  ```tsx
271
- import { DataGrid, useGrid } from '@toolbox-web/grid-react';
324
+ import { DataGrid, useGridEvent, DataGridRef } from '@toolbox-web/grid-react';
325
+ import { useRef } from 'react';
272
326
 
273
327
  function MyComponent() {
274
- const { ref, isReady, forceLayout } = useGrid<Employee>();
328
+ const gridRef = useRef<DataGridRef>(null);
275
329
 
276
- return (
277
- <>
278
- <button onClick={() => forceLayout()}>Refresh Layout</button>
279
- <DataGrid ref={ref} rows={employees} />
280
- </>
281
- );
330
+ useGridEvent(gridRef, 'selection-change', (event) => {
331
+ console.log('Selected:', event.detail.selectedRows);
332
+ });
333
+
334
+ return <DataGrid ref={gridRef} rows={employees} />;
282
335
  }
283
336
  ```
284
337
 
@@ -297,27 +350,16 @@ function MyComponent() {
297
350
 
298
351
  ### Via useGridEvent Hook
299
352
 
300
- ```tsx
301
- import { DataGrid, useGridEvent, DataGridRef } from '@toolbox-web/grid-react';
302
-
303
- function MyComponent() {
304
- const gridRef = useRef<DataGridRef>(null);
305
-
306
- useGridEvent(gridRef, 'selection-change', (event) => {
307
- console.log('Selected:', event.detail.selectedRows);
308
- });
309
-
310
- return <DataGrid ref={gridRef} rows={employees} />;
311
- }
312
- ```
353
+ See [useGridEvent](#usegridevent) above.
313
354
 
314
- ## Plugins
355
+ ## Using Plugins
315
356
 
316
- Use plugins from `@toolbox-web/grid/all`:
357
+ Import plugins individually for smaller bundles:
317
358
 
318
359
  ```tsx
319
360
  import { DataGrid } from '@toolbox-web/grid-react';
320
- import { SelectionPlugin, FilteringPlugin } from '@toolbox-web/grid/all';
361
+ import { SelectionPlugin } from '@toolbox-web/grid/plugins/selection';
362
+ import { FilteringPlugin } from '@toolbox-web/grid/plugins/filtering';
321
363
 
322
364
  function MyComponent() {
323
365
  return (
@@ -335,6 +377,12 @@ function MyComponent() {
335
377
  }
336
378
  ```
337
379
 
380
+ Or import all plugins at once (larger bundle, but convenient):
381
+
382
+ ```tsx
383
+ import { SelectionPlugin, FilteringPlugin } from '@toolbox-web/grid/all';
384
+ ```
385
+
338
386
  ## Custom Styles
339
387
 
340
388
  Inject custom CSS into the grid's shadow DOM:
@@ -353,6 +401,38 @@ Inject custom CSS into the grid's shadow DOM:
353
401
 
354
402
  ## API Reference
355
403
 
404
+ ### Exported Components
405
+
406
+ | Component | Description |
407
+ | ----------------- | ------------------------------------ |
408
+ | `DataGrid` | Main grid component wrapper |
409
+ | `GridColumn` | Declarative column with render props |
410
+ | `GridDetailPanel` | Master-detail expandable panel |
411
+ | `GridToolPanel` | Custom sidebar panel |
412
+ | `GridToolButtons` | Toolbar button container |
413
+
414
+ ### Exported Hooks
415
+
416
+ | Hook | Description |
417
+ | -------------- | ----------------------------------------- |
418
+ | `useGrid` | Grid ref with ready state and methods |
419
+ | `useGridEvent` | Type-safe event subscription with cleanup |
420
+
421
+ ### Exported Types
422
+
423
+ ```typescript
424
+ import type {
425
+ ReactGridConfig,
426
+ ReactColumnConfig,
427
+ CellRenderContext,
428
+ ColumnEditorContext,
429
+ DetailPanelContext,
430
+ ToolPanelContext,
431
+ DataGridRef,
432
+ DataGridProps,
433
+ } from '@toolbox-web/grid-react';
434
+ ```
435
+
356
436
  ### DataGrid Props
357
437
 
358
438
  | Prop | Type | Description |
@@ -384,18 +464,63 @@ Inject custom CSS into the grid's shadow DOM:
384
464
  ### DataGridRef Methods
385
465
 
386
466
  | Method | Description |
387
- | ------------------------- | --------------------------- |
467
+ | ------------------------- | --------------------------- | -------------------- |
388
468
  | `getConfig()` | Get effective configuration |
389
469
  | `ready()` | Wait for grid ready |
390
470
  | `forceLayout()` | Force layout recalculation |
391
471
  | `toggleGroup(key)` | Toggle group expansion |
392
472
  | `registerStyles(id, css)` | Register custom styles |
393
- | `unregisterStyles(id)` | Remove custom styles |
473
+ | `unregisterStyles(id)` | `void` | Remove custom styles |
474
+
475
+ ### ReactGridAdapter
476
+
477
+ The adapter class is exported for advanced use cases:
478
+
479
+ ```typescript
480
+ import { ReactGridAdapter } from '@toolbox-web/grid-react';
481
+ ```
482
+
483
+ In most cases, the `DataGrid` component handles adapter registration automatically.
484
+
485
+ ## Demo
486
+
487
+ See the full React demo at [`demos/employee-management/react/`](../../demos/employee-management/react/) which demonstrates:
488
+
489
+ - 15+ plugins with full configuration
490
+ - Custom editors (star rating, date picker, status select, bonus slider)
491
+ - Custom renderers (status badges, rating colors, top performer stars)
492
+ - Hooks for programmatic control
493
+ - Shell integration (header, tool panels)
494
+ - Master-detail expandable rows
394
495
 
395
496
  ## Requirements
396
497
 
397
498
  - React 18.0.0 or higher
398
- - @toolbox-web/grid 0.2.0 or higher
499
+ - `@toolbox-web/grid` >= 0.2.0
500
+
501
+ ## Development
502
+
503
+ ```bash
504
+ # Build the library
505
+ bun nx build grid-react
506
+
507
+ # Run tests
508
+ bun nx test grid-react
509
+
510
+ # Lint
511
+ bun nx lint grid-react
512
+ ```
513
+
514
+ ---
515
+
516
+ ## Support This Project
517
+
518
+ This grid is built and maintained by a single developer in spare time. If it saves you time or money, consider sponsoring to keep development going:
519
+
520
+ [![GitHub Sponsors](https://img.shields.io/badge/Sponsor_on_GitHub-ea4aaa?style=for-the-badge&logo=github)](https://github.com/sponsors/OysteinAmundsen)
521
+ [![Patreon](https://img.shields.io/badge/Support_on_Patreon-f96854?style=for-the-badge&logo=patreon)](https://www.patreon.com/c/OysteinAmundsen)
522
+
523
+ ---
399
524
 
400
525
  ## License
401
526
 
package/package.json CHANGED
@@ -1,50 +1,50 @@
1
- {
2
- "name": "@toolbox-web/grid-react",
3
- "version": "0.0.2",
4
- "description": "React adapter for @toolbox-web/grid data grid component",
5
- "type": "module",
6
- "main": "./dist/index.js",
7
- "module": "./dist/index.js",
8
- "types": "./dist/index.d.ts",
9
- "exports": {
10
- "./package.json": "./package.json",
11
- ".": {
12
- "types": "./dist/index.d.ts",
13
- "import": "./dist/index.js",
14
- "default": "./dist/index.js"
15
- }
16
- },
17
- "keywords": [
18
- "react",
19
- "data-grid",
20
- "web-component",
21
- "toolbox-web"
22
- ],
23
- "license": "MIT",
24
- "author": "Oystein Amundsen",
25
- "repository": {
26
- "type": "git",
27
- "url": "https://github.com/OysteinAmundsen/toolbox.git",
28
- "directory": "libs/grid-react"
29
- },
30
- "homepage": "https://github.com/OysteinAmundsen/toolbox/tree/main/libs/grid-react#readme",
31
- "bugs": {
32
- "url": "https://github.com/OysteinAmundsen/toolbox/issues"
33
- },
34
- "publishConfig": {
35
- "access": "public"
36
- },
37
- "dependencies": {},
38
- "devDependencies": {
39
- "react": "^19.0.0",
40
- "react-dom": "^19.0.0",
41
- "@types/react": "^19.0.0",
42
- "@types/react-dom": "^19.0.0",
43
- "@toolbox-web/grid": ">=0.2.0"
44
- },
45
- "peerDependencies": {
46
- "react": ">=18.0.0",
47
- "react-dom": ">=18.0.0",
48
- "@toolbox-web/grid": ">=0.2.0"
49
- }
50
- }
1
+ {
2
+ "name": "@toolbox-web/grid-react",
3
+ "version": "0.0.3",
4
+ "description": "React adapter for @toolbox-web/grid data grid component",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ "./package.json": "./package.json",
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "default": "./dist/index.js"
15
+ }
16
+ },
17
+ "keywords": [
18
+ "react",
19
+ "data-grid",
20
+ "web-component",
21
+ "toolbox-web"
22
+ ],
23
+ "license": "MIT",
24
+ "author": "Oystein Amundsen",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/OysteinAmundsen/toolbox.git",
28
+ "directory": "libs/grid-react"
29
+ },
30
+ "homepage": "https://github.com/OysteinAmundsen/toolbox/tree/main/libs/grid-react#readme",
31
+ "bugs": {
32
+ "url": "https://github.com/OysteinAmundsen/toolbox/issues"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "dependencies": {},
38
+ "devDependencies": {
39
+ "react": "^19.0.0",
40
+ "react-dom": "^19.0.0",
41
+ "@types/react": "^19.0.0",
42
+ "@types/react-dom": "^19.0.0",
43
+ "@toolbox-web/grid": ">=0.2.0"
44
+ },
45
+ "peerDependencies": {
46
+ "react": ">=18.0.0",
47
+ "react-dom": ">=18.0.0",
48
+ "@toolbox-web/grid": ">=0.2.0"
49
+ }
50
+ }