react-glide-table 1.7.0 → 2.0.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/README.md CHANGED
@@ -74,7 +74,8 @@ export function Products({ data }: { data: Product[] }) {
74
74
  | `slots.Pending` / `slots.Empty` | Loading and empty states |
75
75
  | `className` / column `className` / `headerClassName` | Extra class hooks |
76
76
  | `labels` / `summary` / `toolbar` | Copy and slot nodes |
77
- | `Column.render` | Cell content custom render |
77
+ | `Column.render` / `ColumnDef.cell` | Cell content custom render (prefer `update` via context) |
78
+ | `Column.kind` / `cellRenderers` | Built-in or custom cell kinds (override / add via registry) |
78
79
 
79
80
  Row/cell **state** is exposed as `data-*` attributes for Tailwind variants:
80
81
 
@@ -83,10 +84,77 @@ Row/cell **state** is exposed as `data-*` attributes for Tailwind variants:
83
84
 
84
85
  Example: `row: "data-[selected]:bg-blue-600"`.
85
86
 
86
- Row-level UI → `slots.Row`. Cell content → `Column.render`. Header/Cell are not separate slots.
87
+ Row-level UI → `slots.Row`. Cell content → `Column.render` or `Column.kind`. Header/Cell are not separate slots.
87
88
 
88
89
  `slots.Scroll` receives `{ scrollRef, className, children }`. Attach `scrollRef` to the element that owns overflow scrolling — virtualization depends on it. Styling-only changes can stay on `classNames.scroll`.
89
90
 
91
+ ### Cell render context (`Column.render`)
92
+
93
+ **Breaking change (v2.0.0):** `render` receives one context object (not positional args). Destructure only what you need.
94
+
95
+ ```tsx
96
+ <ProductTable.Column
97
+ field="status"
98
+ render={({ value, update }) => (
99
+ <button type="button" onClick={() => update("done")}>
100
+ {String(value)}
101
+ </button>
102
+ )}
103
+ />
104
+ ```
105
+
106
+ `update` commits through `onCellChange` (preferred) or `onDataChange`. Prefer `update` over calling `setData` inside the render.
107
+
108
+ The same `update` is available on TanStack `ColumnDef.cell` when using `DataTable` directly (or `useGlideTable().getCellContext` with `flexRender`). Bare `cell.getContext()` does **not** include `update` at runtime — only the wrapped context does (`CellContextWithUpdate`).
109
+
110
+ ```tsx
111
+ const columns: ColumnDef<Product, unknown>[] = [
112
+ {
113
+ accessorKey: "status",
114
+ header: "Status",
115
+ cell: ({ getValue, update }) => (
116
+ <button type="button" onClick={() => update?.("done")}>
117
+ {String(getValue())}
118
+ </button>
119
+ ),
120
+ },
121
+ ];
122
+
123
+ <DataTable data={data} columns={columns} onCellChange={...} />
124
+ ```
125
+
126
+ Double-click inline editing (`editable` / `editType`) stays separate: use it for overlay text/number edits; use `render` / `cell` + `update` for always-visible controls.
127
+
128
+ ### Cell kinds (`Column.kind` + `cellRenderers`)
129
+
130
+ Built-ins (DOM, inspired by [Glide All Cell Kinds](https://glideapps.github.io/glide-data-grid/?path=/story/glide-data-grid-dataeditor-demos--all-cell-kinds)):
131
+ `text`, `number`, `boolean`, `uri`, `image`, `bubble`, `markdown`, `drilldown`, `loading`, `protected`, `row-id`.
132
+
133
+ Priority: **column `render` > registry `kind` > default text**.
134
+
135
+ ```tsx
136
+ const buttonRenderer = {
137
+ kind: "my-button",
138
+ render: ({ value, update }) => (
139
+ <button type="button" onClick={() => update("done")}>
140
+ {String(value)}
141
+ </button>
142
+ ),
143
+ };
144
+
145
+ <ProductTable cellRenderers={[buttonRenderer]}>
146
+ <ProductTable.Header>
147
+ <ProductTable.Column field="active" kind="boolean">
148
+ Active
149
+ </ProductTable.Column>
150
+ <ProductTable.Column field="action" kind="my-button">
151
+ Action
152
+ </ProductTable.Column>
153
+ </ProductTable.Header>
154
+ </ProductTable>
155
+ ```
156
+
157
+ Same `kind` in `cellRenderers` overrides the builtin. Extra kinds are added by key.
90
158
  ## Escape hatch (`useGlideTable`)
91
159
 
92
160
  ```tsx
@@ -98,15 +166,26 @@ type Product = { id: string; name: string; qty: number };
98
166
 
99
167
  const columns: ColumnDef<Product, unknown>[] = [
100
168
  { accessorKey: "name", header: "Name" },
101
- { accessorKey: "qty", header: "Qty" },
169
+ {
170
+ accessorKey: "qty",
171
+ header: "Qty",
172
+ cell: ({ getValue, update }) => (
173
+ <button type="button" onClick={() => update?.(Number(getValue()) + 1)}>
174
+ {String(getValue())}
175
+ </button>
176
+ ),
177
+ },
102
178
  ];
103
179
 
104
180
  export function ProductTable({ data }: { data: Product[] }) {
105
- const { table, rows, scrollRef } = useGlideTable({
181
+ const { table, rows, scrollRef, getCellContext } = useGlideTable({
106
182
  data,
107
183
  columns,
108
184
  getRowId: (row) => row.id,
109
185
  rowSelectionMode: "multi",
186
+ onCellChange: (rowId, columnId, value) => {
187
+ /* update your data */
188
+ },
110
189
  });
111
190
 
112
191
  return (
@@ -133,7 +212,7 @@ export function ProductTable({ data }: { data: Product[] }) {
133
212
  <tr key={row.id}>
134
213
  {row.getVisibleCells().map((cell) => (
135
214
  <td key={cell.id}>
136
- {flexRender(cell.column.columnDef.cell, cell.getContext())}
215
+ {flexRender(cell.column.columnDef.cell, getCellContext(cell))}
137
216
  </td>
138
217
  ))}
139
218
  </tr>
@@ -145,7 +224,7 @@ export function ProductTable({ data }: { data: Product[] }) {
145
224
  }
146
225
  ```
147
226
 
148
- Wire `rowContextValue` into your own row/cell components for edit, selection, expand, and row-span behavior.
227
+ Wire `rowContextValue` into your own row/cell components for edit, selection, expand, and row-span behavior. Use `getCellContext(cell)` (not bare `cell.getContext()`) so `ColumnDef.cell` receives `update`.
149
228
 
150
229
  ## Clipboard copy & paste
151
230
 
@@ -216,6 +295,8 @@ Opt in with `enableColumnResize`. Drag the handle on the right edge of a header
216
295
 
217
296
  Opt in with `enableColumnFreeze`. Mark columns with `frozen` — sticky insets are stacked so frozen cells never overlap, and **column order is unchanged** (middle columns may also freeze).
218
297
 
298
+ Keep vertical stickiness on the header via `classNames.head` (e.g. `sticky top-0`). Frozen header cells only stick horizontally (`left` / `right`); setting `top` on both `thead` and frozen `th` can detach the freeze band.
299
+
219
300
  ```tsx
220
301
  <ProductTable data={data} enableColumnFreeze>
221
302
  <ProductTable.Header>