@gears-frontx/ui-kit 0.4.5 → 0.4.7
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/chunks/actions.iasfkjWq.css +1 -0
- package/dist/chunks/create-column-auto-size.js +62 -0
- package/dist/chunks/create-column-auto-size.js.map +1 -0
- package/dist/chunks/data-grid-record-context.js +13 -0
- package/dist/chunks/data-grid-record-context.js.map +1 -0
- package/dist/chunks/data-grid.DSkYrsay.css +1 -0
- package/dist/chunks/drag-drop.BASVe3_O.css +1 -0
- package/dist/chunks/hooked.js +23 -39
- package/dist/chunks/hooked.js.map +1 -1
- package/dist/chunks/ignore-row-click.js +5 -0
- package/dist/chunks/ignore-row-click.js.map +1 -0
- package/dist/chunks/is-record.js +7 -0
- package/dist/chunks/is-record.js.map +1 -0
- package/dist/chunks/messages.js +30 -3
- package/dist/chunks/messages.js.map +1 -1
- package/dist/chunks/pagination.DJ7HJSFX.css +1 -0
- package/dist/chunks/resolve-body-cell-props.BA5IRWq0.css +1 -0
- package/dist/chunks/resolve-body-cell-props.js +124 -0
- package/dist/chunks/resolve-body-cell-props.js.map +1 -0
- package/dist/chunks/row-actions.BprAXgu2.css +1 -0
- package/dist/chunks/row-click-utils.js +12 -0
- package/dist/chunks/row-click-utils.js.map +1 -0
- package/dist/chunks/row-click.DAYTmSBO.css +1 -0
- package/dist/chunks/row-number.BxFT_3yP.css +1 -0
- package/dist/chunks/row-select.BjKdiMf5.css +1 -0
- package/dist/chunks/segment.js +16 -9
- package/dist/chunks/segment.js.map +1 -1
- package/dist/chunks/storage-helpers.js +40 -0
- package/dist/chunks/storage-helpers.js.map +1 -0
- package/dist/chunks/table-configuration.a6C_fp7B.css +1 -0
- package/dist/chunks/table-context.js +8 -0
- package/dist/chunks/table-context.js.map +1 -0
- package/dist/chunks/table-helpers.js +20 -0
- package/dist/chunks/table-helpers.js.map +1 -0
- package/dist/chunks/table-tree.DMtpMddS.css +1 -0
- package/dist/chunks/table-types.js +11 -0
- package/dist/chunks/table-types.js.map +1 -0
- package/dist/chunks/table.biUlW2U6.css +1 -0
- package/dist/chunks/use-latest.js +11 -0
- package/dist/chunks/use-latest.js.map +1 -0
- package/dist/components/data-grid/data-grid-types.d.ts +9 -0
- package/dist/components/data-grid/data-grid-types.d.ts.map +1 -1
- package/dist/components/data-grid/data-grid.d.ts +1 -1
- package/dist/components/data-grid/data-grid.d.ts.map +1 -1
- package/dist/components/data-grid/messages.d.ts +25 -0
- package/dist/components/data-grid/messages.d.ts.map +1 -1
- package/dist/components/data-grid/plugins/actions/actions-plugin.d.ts +4 -0
- package/dist/components/data-grid/plugins/actions/actions-plugin.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/actions/actions-types.d.ts +11 -0
- package/dist/components/data-grid/plugins/actions/actions-types.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/actions/components/data-grid-actions-wrapper.d.ts +3 -0
- package/dist/components/data-grid/plugins/actions/components/data-grid-actions-wrapper.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/actions/public.d.ts +3 -0
- package/dist/components/data-grid/plugins/actions/public.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/actions-menu/actions-menu-plugin.d.ts +3 -0
- package/dist/components/data-grid/plugins/actions-menu/actions-menu-plugin.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/actions-menu/actions-menu-types.d.ts +25 -0
- package/dist/components/data-grid/plugins/actions-menu/actions-menu-types.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/actions-menu/components/data-grid-actions-menu.d.ts +3 -0
- package/dist/components/data-grid/plugins/actions-menu/components/data-grid-actions-menu.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/actions-menu/menu-items/export-menu-items/data-grid-export-menu-item.d.ts +6 -0
- package/dist/components/data-grid/plugins/actions-menu/menu-items/export-menu-items/data-grid-export-menu-item.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/actions-menu/menu-items/export-menu-items/export-cells.d.ts +18 -0
- package/dist/components/data-grid/plugins/actions-menu/menu-items/export-menu-items/export-cells.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/actions-menu/menu-items/export-menu-items/export-menu-items.d.ts +9 -0
- package/dist/components/data-grid/plugins/actions-menu/menu-items/export-menu-items/export-menu-items.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/actions-menu/menu-items/export-menu-items/export-service.d.ts +5 -0
- package/dist/components/data-grid/plugins/actions-menu/menu-items/export-menu-items/export-service.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/actions-menu/menu-items/export-menu-items/export-types.d.ts +77 -0
- package/dist/components/data-grid/plugins/actions-menu/menu-items/export-menu-items/export-types.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/actions-menu/menu-items/export-menu-items/formatters/csv-formatter.d.ts +3 -0
- package/dist/components/data-grid/plugins/actions-menu/menu-items/export-menu-items/formatters/csv-formatter.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/actions-menu/menu-items/export-menu-items/formatters/excel-formatter.d.ts +4 -0
- package/dist/components/data-grid/plugins/actions-menu/menu-items/export-menu-items/formatters/excel-formatter.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/actions-menu/public.d.ts +5 -0
- package/dist/components/data-grid/plugins/actions-menu/public.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/drag-drop/components/data-grid-drag-drop-body-cell.d.ts +3 -0
- package/dist/components/data-grid/plugins/drag-drop/components/data-grid-drag-drop-body-cell.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/drag-drop/components/data-grid-drag-drop-content.d.ts +7 -0
- package/dist/components/data-grid/plugins/drag-drop/components/data-grid-drag-drop-content.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/drag-drop/components/data-grid-drag-drop-row.d.ts +8 -0
- package/dist/components/data-grid/plugins/drag-drop/components/data-grid-drag-drop-row.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/drag-drop/drag-data.d.ts +4 -0
- package/dist/components/data-grid/plugins/drag-drop/drag-data.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/drag-drop/drag-drop-plugin.d.ts +18 -0
- package/dist/components/data-grid/plugins/drag-drop/drag-drop-plugin.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/drag-drop/drag-drop-types.d.ts +60 -0
- package/dist/components/data-grid/plugins/drag-drop/drag-drop-types.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/drag-drop/drag-preview.d.ts +2 -0
- package/dist/components/data-grid/plugins/drag-drop/drag-preview.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/drag-drop/public.d.ts +3 -0
- package/dist/components/data-grid/plugins/drag-drop/public.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/pagination/components/data-grid-pagination.d.ts.map +1 -1
- package/dist/components/data-grid/plugins/pagination/components/pager.d.ts +6 -0
- package/dist/components/data-grid/plugins/pagination/components/pager.d.ts.map +1 -1
- package/dist/components/data-grid/plugins/row-actions/components/data-grid-row-actions-cell.d.ts +3 -0
- package/dist/components/data-grid/plugins/row-actions/components/data-grid-row-actions-cell.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/row-actions/public.d.ts +3 -0
- package/dist/components/data-grid/plugins/row-actions/public.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/row-actions/row-actions-plugin.d.ts +6 -0
- package/dist/components/data-grid/plugins/row-actions/row-actions-plugin.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/row-actions/row-actions-types.d.ts +24 -0
- package/dist/components/data-grid/plugins/row-actions/row-actions-types.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/row-click/components/data-grid-row-click.d.ts +8 -0
- package/dist/components/data-grid/plugins/row-click/components/data-grid-row-click.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/row-click/public.d.ts +3 -0
- package/dist/components/data-grid/plugins/row-click/public.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/row-click/row-click-plugin.d.ts +14 -0
- package/dist/components/data-grid/plugins/row-click/row-click-plugin.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/row-click/row-click-utils.d.ts +9 -0
- package/dist/components/data-grid/plugins/row-click/row-click-utils.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/row-number/components/data-grid-row-number-cell.d.ts +3 -0
- package/dist/components/data-grid/plugins/row-number/components/data-grid-row-number-cell.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/row-number/public.d.ts +3 -0
- package/dist/components/data-grid/plugins/row-number/public.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/row-number/row-number-plugin.d.ts +4 -0
- package/dist/components/data-grid/plugins/row-number/row-number-plugin.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/row-number/row-number-types.d.ts +6 -0
- package/dist/components/data-grid/plugins/row-number/row-number-types.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/row-number/services/row-number-formula.d.ts +2 -0
- package/dist/components/data-grid/plugins/row-number/services/row-number-formula.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/row-select/components/data-grid-row-select-banner.d.ts +3 -0
- package/dist/components/data-grid/plugins/row-select/components/data-grid-row-select-banner.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/row-select/components/data-grid-row-select-body.d.ts +3 -0
- package/dist/components/data-grid/plugins/row-select/components/data-grid-row-select-body.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/row-select/components/data-grid-row-select-header.d.ts +3 -0
- package/dist/components/data-grid/plugins/row-select/components/data-grid-row-select-header.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/row-select/components/data-grid-row-select-top.d.ts +3 -0
- package/dist/components/data-grid/plugins/row-select/components/data-grid-row-select-top.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/row-select/public.d.ts +3 -0
- package/dist/components/data-grid/plugins/row-select/public.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/row-select/row-select-plugin.d.ts +5 -0
- package/dist/components/data-grid/plugins/row-select/row-select-plugin.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/row-select/row-select-types.d.ts +113 -0
- package/dist/components/data-grid/plugins/row-select/row-select-types.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/table-configuration/components/data-grid-table-configuration-group-item.d.ts +10 -0
- package/dist/components/data-grid/plugins/table-configuration/components/data-grid-table-configuration-group-item.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/table-configuration/components/data-grid-table-configuration-item.d.ts +10 -0
- package/dist/components/data-grid/plugins/table-configuration/components/data-grid-table-configuration-item.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/table-configuration/components/data-grid-table-configuration-pin-button.d.ts +8 -0
- package/dist/components/data-grid/plugins/table-configuration/components/data-grid-table-configuration-pin-button.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/table-configuration/components/data-grid-table-configuration-trigger.d.ts +3 -0
- package/dist/components/data-grid/plugins/table-configuration/components/data-grid-table-configuration-trigger.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/table-configuration/components/data-grid-table-configuration.d.ts +3 -0
- package/dist/components/data-grid/plugins/table-configuration/components/data-grid-table-configuration.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/table-configuration/public.d.ts +3 -0
- package/dist/components/data-grid/plugins/table-configuration/public.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/table-configuration/table-configuration-plugin.d.ts +5 -0
- package/dist/components/data-grid/plugins/table-configuration/table-configuration-plugin.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/table-tree/components/data-grid-table-tree-body-cell-content.d.ts +9 -0
- package/dist/components/data-grid/plugins/table-tree/components/data-grid-table-tree-body-cell-content.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/table-tree/components/data-grid-table-tree-expand.d.ts +3 -0
- package/dist/components/data-grid/plugins/table-tree/components/data-grid-table-tree-expand.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/table-tree/components/data-grid-table-tree-row.d.ts +8 -0
- package/dist/components/data-grid/plugins/table-tree/components/data-grid-table-tree-row.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/table-tree/public.d.ts +3 -0
- package/dist/components/data-grid/plugins/table-tree/public.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/table-tree/table-tree-helpers.d.ts +4 -0
- package/dist/components/data-grid/plugins/table-tree/table-tree-helpers.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/table-tree/table-tree-plugin.d.ts +5 -0
- package/dist/components/data-grid/plugins/table-tree/table-tree-plugin.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/table-tree/table-tree-types.d.ts +33 -0
- package/dist/components/data-grid/plugins/table-tree/table-tree-types.d.ts.map +1 -0
- package/dist/components/data-grid/services/core/data-grid-label-context.d.ts +7 -0
- package/dist/components/data-grid/services/core/data-grid-label-context.d.ts.map +1 -0
- package/dist/components/data-grid/services/layout/components/data-grid-layout-top.d.ts.map +1 -1
- package/dist/components/data-grid/services/layout/components/toolbar-lines.d.ts +2 -0
- package/dist/components/data-grid/services/layout/components/toolbar-lines.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/components/data-grid-cell.d.ts.map +1 -1
- package/dist/components/data-grid/services/table/components/data-grid-extra-header-cell.d.ts.map +1 -1
- package/dist/components/data-grid/services/table/components/data-grid-header-cell.d.ts.map +1 -1
- package/dist/components/data-grid/services/table/components/data-grid-header-group.d.ts.map +1 -1
- package/dist/components/data-grid/services/table/components/data-grid-table.d.ts.map +1 -1
- package/dist/components/data-grid/services/table/table-service.d.ts.map +1 -1
- package/dist/components/data-grid/services/table/table-sticky.d.ts +16 -0
- package/dist/components/data-grid/services/table/table-sticky.d.ts.map +1 -1
- package/dist/components/pagination/pagination.d.ts +7 -4
- package/dist/components/pagination/pagination.d.ts.map +1 -1
- package/dist/components/table/table.d.ts +20 -3
- package/dist/components/table/table.d.ts.map +1 -1
- package/dist/data-grid/actions-menu.d.ts +1 -0
- package/dist/data-grid/actions-menu.js +373 -0
- package/dist/data-grid/actions-menu.js.map +1 -0
- package/dist/data-grid/actions.d.ts +1 -0
- package/dist/data-grid/actions.js +36 -0
- package/dist/data-grid/actions.js.map +1 -0
- package/dist/data-grid/drag-drop.d.ts +1 -0
- package/dist/data-grid/drag-drop.js +261 -0
- package/dist/data-grid/drag-drop.js.map +1 -0
- package/dist/data-grid/filters.js +27 -25
- package/dist/data-grid/filters.js.map +1 -1
- package/dist/data-grid/pagination.js +152 -143
- package/dist/data-grid/pagination.js.map +1 -1
- package/dist/data-grid/row-actions.d.ts +1 -0
- package/dist/data-grid/row-actions.js +52 -0
- package/dist/data-grid/row-actions.js.map +1 -0
- package/dist/data-grid/row-click.d.ts +1 -0
- package/dist/data-grid/row-click.js +62 -0
- package/dist/data-grid/row-click.js.map +1 -0
- package/dist/data-grid/row-number.d.ts +1 -0
- package/dist/data-grid/row-number.js +38 -0
- package/dist/data-grid/row-number.js.map +1 -0
- package/dist/data-grid/row-select.d.ts +1 -0
- package/dist/data-grid/row-select.js +293 -0
- package/dist/data-grid/row-select.js.map +1 -0
- package/dist/data-grid/table-configuration.d.ts +1 -0
- package/dist/data-grid/table-configuration.js +165 -0
- package/dist/data-grid/table-configuration.js.map +1 -0
- package/dist/data-grid/table-tree.d.ts +1 -0
- package/dist/data-grid/table-tree.js +233 -0
- package/dist/data-grid/table-tree.js.map +1 -0
- package/dist/data-grid.js +791 -887
- package/dist/data-grid.js.map +1 -1
- package/dist/docs/data-grid.md +612 -12
- package/dist/docs/pagination.md +14 -0
- package/dist/docs/table.md +67 -3
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +409 -389
- package/dist/index.js.map +1 -1
- package/dist/pagination.js +23 -23
- package/dist/pagination.js.map +1 -1
- package/dist/table.js +137 -135
- package/dist/table.js.map +1 -1
- package/llms.txt +12 -7
- package/package.json +10 -1
- package/dist/chunks/data-grid.DYrZEU-F.css +0 -1
- package/dist/chunks/pagination.CKDEuWt6.css +0 -1
- package/dist/chunks/table.CMm41tvy.css +0 -1
package/dist/docs/data-grid.md
CHANGED
|
@@ -7,8 +7,9 @@ custom empty state) by registering into those slots and hooking the load. Each c
|
|
|
7
7
|
(load, layout, table, storage, persistence) is a service with its own store, and
|
|
8
8
|
a plugin reaches all of them through one context object.
|
|
9
9
|
|
|
10
|
-
Built-in plugins: pagination, text search, order, filters
|
|
11
|
-
|
|
10
|
+
Built-in plugins: pagination, text search, order, filters, empty state, row number, row
|
|
11
|
+
click, actions, row actions, an actions menu, table configuration, row select, a table tree
|
|
12
|
+
and drag and drop, each its own entry (see below).
|
|
12
13
|
|
|
13
14
|
## When to use
|
|
14
15
|
|
|
@@ -37,6 +38,15 @@ code or CSS:
|
|
|
37
38
|
| `@gears-frontx/ui-kit/data-grid/order` | `DataGridOrderPlugin`, `createDataGridOrderOption` |
|
|
38
39
|
| `@gears-frontx/ui-kit/data-grid/filters` | `DataGridFiltersPlugin`, the entity factories `filterSearch`, `filterToggle`, `filterCheckboxGroup`, `filterTagGroup`, `filterTree` and `filterDateRange`, `createDataGridTreeStructure` and `useDataGridTreeStructure` (the tree `filterTree` takes), and the types |
|
|
39
40
|
| `@gears-frontx/ui-kit/data-grid/empty-state` | `DataGridEmptyStatePlugin` |
|
|
41
|
+
| `@gears-frontx/ui-kit/data-grid/row-number` | `DataGridRowNumberPlugin` |
|
|
42
|
+
| `@gears-frontx/ui-kit/data-grid/row-click` | `DataGridRowClickPlugin` |
|
|
43
|
+
| `@gears-frontx/ui-kit/data-grid/actions` | `DataGridActionsPlugin` |
|
|
44
|
+
| `@gears-frontx/ui-kit/data-grid/row-actions` | `DataGridRowActionsPlugin` |
|
|
45
|
+
| `@gears-frontx/ui-kit/data-grid/actions-menu` | `DataGridActionsMenuPlugin`, `exportMenuItems` (the menu items that export the rows) and the types |
|
|
46
|
+
| `@gears-frontx/ui-kit/data-grid/table-configuration` | `DataGridTableConfigurationPlugin` |
|
|
47
|
+
| `@gears-frontx/ui-kit/data-grid/row-select` | `DataGridRowSelectPlugin` |
|
|
48
|
+
| `@gears-frontx/ui-kit/data-grid/table-tree` | `DataGridTableTreePlugin` |
|
|
49
|
+
| `@gears-frontx/ui-kit/data-grid/drag-drop` | `createDataGridDragDropPlugin` and the types |
|
|
40
50
|
|
|
41
51
|
The package root re-exports all of them, so
|
|
42
52
|
`import { DataGrid, DataGridPaginationPlugin } from '@gears-frontx/ui-kit'`
|
|
@@ -108,6 +118,7 @@ plugins fill in, and expects a `DataGridLoadResult`.
|
|
|
108
118
|
| `pagination` | pagination plugin | `{ page: number; limit: number }`, page is 1-based |
|
|
109
119
|
| `filters` | text search plugin, and any plugin that registers one | `Record<string, { value, ... }>` keyed by filter key; text search writes `filters.textSearch` |
|
|
110
120
|
| `order` | order plugin | `{ column: string; direction: 'asc' \| 'desc' }[]`, absent when nothing is sorted |
|
|
121
|
+
| `tree` | table tree plugin | `{ parentId }`: `null` for the rows of the grid, a row's id for its children |
|
|
111
122
|
| `signal` | the grid | an `AbortSignal`, aborted when a refresh replaces the load or the grid unmounts |
|
|
112
123
|
|
|
113
124
|
`DataGridLoadResult` is `{ results: TItem[]; total?: number }`. `total` is what the pager
|
|
@@ -140,7 +151,7 @@ under a spanning header cell.
|
|
|
140
151
|
| `minWidth`, `maxWidth` | `number` | Pixels. Independent floor and cap under `tableLayout="auto"`. |
|
|
141
152
|
| `headerOverflow` | `'nowrap' \| 'wrap'` | Default `'nowrap'`: one line, clipped with an ellipsis, the label in `title`. |
|
|
142
153
|
| `cellOverflow` | `'wrap' \| 'nowrap'` | Default `'wrap'`. `'nowrap'` clips with an ellipsis and sets `title` to the value. |
|
|
143
|
-
| `sticky` | `boolean` | Pins the column to the inline-start edge while the table scrolls sideways. |
|
|
154
|
+
| `sticky` | `boolean` | Pins the column to the inline-start edge while the table scrolls sideways. The columns a plugin adds before the data (a row number, a selection checkbox) pin with the first pinned column, in front of it, so they stay in view; with nothing pinned they scroll away with the rest. |
|
|
144
155
|
| `visible` | `boolean` | Initial visibility. |
|
|
145
156
|
| `visibleToggleDisabled` | `boolean` | The column's visibility is not the user's to change. |
|
|
146
157
|
| `getClassName` | `(item) => string \| undefined` | A class for the column's cell in that row. |
|
|
@@ -148,10 +159,11 @@ under a spanning header cell.
|
|
|
148
159
|
| `groupId` | `string` | Set by the grid on columns inside a `DataGridTableGroup`; do not set it. |
|
|
149
160
|
|
|
150
161
|
A `DataGridTableGroup` is `{ id, label, columns, component?, visible?, sticky? }`; a
|
|
151
|
-
group's `sticky` pins all its columns.
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
162
|
+
group's `sticky` pins all its columns. Pinning or unpinning a group at run time (the table
|
|
163
|
+
configuration plugin does) moves its heading and all its columns together. Pin a group as a
|
|
164
|
+
whole or none of its columns: a column pinned or unpinned on its own inside a group moves in
|
|
165
|
+
the body but not under the group's header, so the header labels stop matching their columns
|
|
166
|
+
(see "Known limitations").
|
|
155
167
|
|
|
156
168
|
Pass a component to a column as its own module-level component, not an inline
|
|
157
169
|
function: an inline component is a new component on every render and loses its
|
|
@@ -259,6 +271,25 @@ Hold the flag on the screen that renders the grid rather than inside the thing
|
|
|
259
271
|
that started the work, so the overlay survives that thing going away. It is OR-ed
|
|
260
272
|
with the grid's own loads, and there is no imperative equivalent.
|
|
261
273
|
|
|
274
|
+
### `label`
|
|
275
|
+
|
|
276
|
+
`label` names the grid for assistive tech, for a page that renders more than
|
|
277
|
+
one grid: the table's scroll container becomes a `region` named with it, and
|
|
278
|
+
the pagination plugin's pager becomes a `nav` named `<label> pagination`.
|
|
279
|
+
|
|
280
|
+
```tsx
|
|
281
|
+
<DataGrid name="users" label="Users" load={loadUsers} columns={columns}>
|
|
282
|
+
<DataGridPaginationPlugin />
|
|
283
|
+
</DataGrid>
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
Without it the pager is the one `nav` named "Pagination" and the table's
|
|
287
|
+
scroll container stays roleless, so a single grid on a page needs no label.
|
|
288
|
+
Give every grid on a page that holds more than one a distinct label: two grids
|
|
289
|
+
sharing one still leave their landmarks indistinguishable. The label is a spoken name, not the storage key `name`
|
|
290
|
+
(which identifies a grid's persisted state, and is not readable text), and it
|
|
291
|
+
is never persisted.
|
|
292
|
+
|
|
262
293
|
## Empty state
|
|
263
294
|
|
|
264
295
|
A grid with no records shows a centered `Empty` instead of the table: "No results
|
|
@@ -301,6 +332,13 @@ further lines when it is too wide for one, and `top-end` goes on to a line of it
|
|
|
301
332
|
own, at its end, when it would not fit beside `top-start` on a single line. A
|
|
302
333
|
toolbar that fits on one line has everything centred on it.
|
|
303
334
|
|
|
335
|
+
A slot registered in `top` and made active replaces the toolbar's two halves. While the toolbar
|
|
336
|
+
is on one line, the grid gives the slot at least the height the toolbar had and centres what it
|
|
337
|
+
holds in that height, so the table under it does not move when the slot takes the toolbar's place
|
|
338
|
+
(the row select bar does). A toolbar that has wrapped onto several lines, as a row of quick
|
|
339
|
+
filters does on a narrow screen, is not kept: the slot takes its own height and the table moves
|
|
340
|
+
up with it.
|
|
341
|
+
|
|
304
342
|
With two or more `main` views (for example the table and a cards view) the grid
|
|
305
343
|
adds a view switch to `top-end` by itself. Read or set the active view with
|
|
306
344
|
`useDataGridActiveView()` and `DATA_GRID_VIEW`:
|
|
@@ -336,8 +374,8 @@ page, and does not listen for `popstate`; a plugin can opt a state out of it
|
|
|
336
374
|
backend (`{ storage: 'localStorage' }`).
|
|
337
375
|
|
|
338
376
|
`persistentColumnVisibility` remembers which columns the user showed or hid, in
|
|
339
|
-
`localStorage` whatever `persistent` says. The
|
|
340
|
-
it; a plugin of your own calls `updateColumnVisibility`.
|
|
377
|
+
`localStorage` whatever `persistent` says. The table configuration plugin is the
|
|
378
|
+
built-in control that changes it; a plugin of your own calls `updateColumnVisibility`.
|
|
341
379
|
|
|
342
380
|
## Plugins
|
|
343
381
|
|
|
@@ -358,7 +396,11 @@ A page change updates the page, stores it and reloads. A limit change goes back
|
|
|
358
396
|
page 1, stores the limit and reloads. A refresh resets the page to 1. The page
|
|
359
397
|
count comes from `total`. The loading treatment is the grid's, not the pager's.
|
|
360
398
|
In a container too narrow for one row, the page buttons wrap to a centred line
|
|
361
|
-
under the page-size selector and the page text
|
|
399
|
+
under the page-size selector and the page text, and below a 640px container the
|
|
400
|
+
Previous and Next words collapse to their chevrons. The pager is a size
|
|
401
|
+
container, so a parent that shrinks to fit its content collapses it to zero
|
|
402
|
+
width (see the containment note in `pagination.md`). A grid with a `label`
|
|
403
|
+
names the pager `<label> pagination` (see `label`).
|
|
362
404
|
|
|
363
405
|
### `DataGridTextSearchPlugin`
|
|
364
406
|
|
|
@@ -563,6 +605,506 @@ function UsersEmptyState() {
|
|
|
563
605
|
</DataGrid>;
|
|
564
606
|
```
|
|
565
607
|
|
|
608
|
+
### `DataGridRowNumberPlugin`
|
|
609
|
+
|
|
610
|
+
Adds a column before the data with the row's 1-based number, in the monospace face. It
|
|
611
|
+
takes no props.
|
|
612
|
+
|
|
613
|
+
```tsx
|
|
614
|
+
import { DataGridPaginationPlugin } from '@gears-frontx/ui-kit/data-grid/pagination';
|
|
615
|
+
import { DataGridRowNumberPlugin } from '@gears-frontx/ui-kit/data-grid/row-number';
|
|
616
|
+
|
|
617
|
+
<DataGrid name="users" load={loadUsers} columns={columns}>
|
|
618
|
+
<DataGridPaginationPlugin defaultLimit={20} />
|
|
619
|
+
<DataGridRowNumberPlugin />
|
|
620
|
+
</DataGrid>;
|
|
621
|
+
```
|
|
622
|
+
|
|
623
|
+
The number is `limit * (page - 1) + index + 1`, so with the pagination plugin the second page
|
|
624
|
+
of 20 starts at 21; without it the number is the row's position. The column has no header
|
|
625
|
+
text, starts at 32px and grows to the widest number on the page.
|
|
626
|
+
|
|
627
|
+
### `DataGridRowClickPlugin`
|
|
628
|
+
|
|
629
|
+
Calls back with the row's item when a row is clicked, double-clicked, or has Enter pressed
|
|
630
|
+
on it. It replaces the `row` renderer, so it takes the whole row.
|
|
631
|
+
|
|
632
|
+
| Prop | Type | Notes |
|
|
633
|
+
|------|------|-------|
|
|
634
|
+
| `click` | `(item) => void` | A click, and Enter on a focused row |
|
|
635
|
+
| `dblclick` | `(item) => void` | A double click, which also fires `click` twice first, as in a browser |
|
|
636
|
+
|
|
637
|
+
```tsx
|
|
638
|
+
import { DataGridRowClickPlugin } from '@gears-frontx/ui-kit/data-grid/row-click';
|
|
639
|
+
|
|
640
|
+
<DataGrid<User> name="users" load={loadUsers} columns={columns}>
|
|
641
|
+
<DataGridRowClickPlugin<User> click={(user) => navigate(`/users/${user.id}`)} />
|
|
642
|
+
</DataGrid>;
|
|
643
|
+
```
|
|
644
|
+
|
|
645
|
+
Every body row gets `tabIndex={0}` and a pointer cursor. The callbacks are read when the event
|
|
646
|
+
fires, so a new function each render is fine.
|
|
647
|
+
|
|
648
|
+
A click anywhere in the row counts, including on a control inside a cell, so a button, link or
|
|
649
|
+
checkbox in a cell would fire the row click as well. Mark such an element with
|
|
650
|
+
`data-grid-row-ignore-click`, or any ancestor of it in the cell: clicks, double clicks and
|
|
651
|
+
Enter that start inside it are skipped. An extra column marks its whole cell with the
|
|
652
|
+
`ignoreRowClick` option of `registerExtraColumn`.
|
|
653
|
+
|
|
654
|
+
```tsx
|
|
655
|
+
const columns: DataGridTableColumn<User>[] = [
|
|
656
|
+
{ id: 'name', label: 'Name' },
|
|
657
|
+
{
|
|
658
|
+
id: 'actions',
|
|
659
|
+
label: 'Actions',
|
|
660
|
+
component: ({ item }) => (
|
|
661
|
+
<Button data-grid-row-ignore-click onClick={() => remove(item.id)}>
|
|
662
|
+
Delete
|
|
663
|
+
</Button>
|
|
664
|
+
),
|
|
665
|
+
},
|
|
666
|
+
];
|
|
667
|
+
```
|
|
668
|
+
|
|
669
|
+
### `DataGridActionsPlugin`
|
|
670
|
+
|
|
671
|
+
Renders a component of yours in the toolbar's `top-end` slot, at order 0, so it sits before
|
|
672
|
+
the other toolbar buttons. It is for toolbar content (an "Add" button, a bulk-import
|
|
673
|
+
trigger); actions on a row belong in a column of your own.
|
|
674
|
+
|
|
675
|
+
| Prop | Type | Notes |
|
|
676
|
+
|------|------|-------|
|
|
677
|
+
| `component` | `ComponentType` | Required. Keep its identity between renders (a module-level component) |
|
|
678
|
+
| `props` | `Record<string, unknown>` | Spread onto `component` |
|
|
679
|
+
|
|
680
|
+
```tsx
|
|
681
|
+
import { DataGridActionsPlugin } from '@gears-frontx/ui-kit/data-grid/actions';
|
|
682
|
+
|
|
683
|
+
function AddUserButton({ onAdd }: { onAdd?: () => void }) {
|
|
684
|
+
return <Button onClick={onAdd}>Add user</Button>;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
<DataGrid name="users" load={loadUsers} columns={columns}>
|
|
688
|
+
<DataGridActionsPlugin component={AddUserButton} props={{ onAdd: openCreateDialog }} />
|
|
689
|
+
</DataGrid>;
|
|
690
|
+
```
|
|
691
|
+
|
|
692
|
+
`props` is not typed against `component`, so the component's own props have to be optional
|
|
693
|
+
for it to type-check, as `onAdd` is here.
|
|
694
|
+
|
|
695
|
+
The wrapper lays its content out in a row with a small gap. The component renders as a
|
|
696
|
+
child of the grid, so `useDataGrid()` works inside it.
|
|
697
|
+
|
|
698
|
+
### `DataGridRowActionsPlugin`
|
|
699
|
+
|
|
700
|
+
Adds a last column that renders your component in every row, given the row's `item`:
|
|
701
|
+
the place for a row's edit and delete buttons or its "more" menu.
|
|
702
|
+
|
|
703
|
+
| Prop | Type | Default |
|
|
704
|
+
|------|------|---------|
|
|
705
|
+
| `component` | `ComponentType<{ item }>` | required |
|
|
706
|
+
| `order` | `number` | `100`, its place among the columns at the end |
|
|
707
|
+
| `className` | `string` | none; goes on the wrapper around your component |
|
|
708
|
+
| `sticky` | `boolean` | `false`; pins the column to the inline-end edge |
|
|
709
|
+
|
|
710
|
+
```tsx
|
|
711
|
+
import { DataGridRowActionsPlugin } from '@gears-frontx/ui-kit/data-grid/row-actions';
|
|
712
|
+
|
|
713
|
+
function UserActions({ item }: { item: User }) {
|
|
714
|
+
return (
|
|
715
|
+
<DropdownMenu>
|
|
716
|
+
<DropdownMenuTrigger
|
|
717
|
+
render={<Button variant="ghost" size="sm" icon={<MoreHorizontal />} aria-label={`Actions for ${item.name}`} />}
|
|
718
|
+
/>
|
|
719
|
+
<DropdownMenuContent align="end">
|
|
720
|
+
<DropdownMenuItem onClick={() => edit(item)}>Edit</DropdownMenuItem>
|
|
721
|
+
<DropdownMenuItem onClick={() => remove(item)}>Delete</DropdownMenuItem>
|
|
722
|
+
</DropdownMenuContent>
|
|
723
|
+
</DropdownMenu>
|
|
724
|
+
);
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
<DataGrid<User> name="users" load={loadUsers} columns={columns}>
|
|
728
|
+
<DataGridRowActionsPlugin<User> component={UserActions} sticky />
|
|
729
|
+
</DataGrid>;
|
|
730
|
+
```
|
|
731
|
+
|
|
732
|
+
The column has no header text and is as wide as the widest actions it holds. The wrapper is
|
|
733
|
+
marked `data-grid-row-ignore-click`, so with the row click plugin a click on your buttons does
|
|
734
|
+
not also click the row. A menu your component opens renders in a portal, outside that
|
|
735
|
+
wrapper: see Known limitations.
|
|
736
|
+
|
|
737
|
+
`sticky` keeps the actions in view on a table wide enough to scroll sideways: the column sticks
|
|
738
|
+
to the inline-end edge, in left-to-right and right-to-left alike, and its cells are opaque, so
|
|
739
|
+
the rows scroll under it. A pinned cell is painted with its row's own fill over `--card`, so
|
|
740
|
+
it follows hover, selection and the other row states; set `--data-grid-pinned-background` (see
|
|
741
|
+
CSS customization) when the grid sits on `--background`.
|
|
742
|
+
|
|
743
|
+
### `DataGridActionsMenuPlugin`
|
|
744
|
+
|
|
745
|
+
Adds an ellipsis button named "Actions" to the toolbar's `top-end` slot, after the other
|
|
746
|
+
toolbar buttons (order 100). It opens a `DropdownMenu` whose items are components of yours,
|
|
747
|
+
or the export items the kit ships (see Export below).
|
|
748
|
+
|
|
749
|
+
| Prop | Type | Notes |
|
|
750
|
+
|------|------|-------|
|
|
751
|
+
| `menuItems` | `{ component, params?, order? }[]` | `component` receives `{ params }` and renders a `DropdownMenuItem` (or any menu part) |
|
|
752
|
+
|
|
753
|
+
```tsx
|
|
754
|
+
import { DataGridActionsMenuPlugin } from '@gears-frontx/ui-kit/data-grid/actions-menu';
|
|
755
|
+
|
|
756
|
+
// `params` is typed as a plain record, so each field of an item's own params is optional.
|
|
757
|
+
function ArchiveItem({ params }: { params?: { onArchive?: () => void } }) {
|
|
758
|
+
return <DropdownMenuItem onClick={params?.onArchive}>Archive</DropdownMenuItem>;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
const menuItems = [{ component: ArchiveItem, params: { onArchive: archiveAll } }];
|
|
762
|
+
|
|
763
|
+
<DataGrid name="users" load={loadUsers} columns={columns}>
|
|
764
|
+
<DataGridActionsMenuPlugin menuItems={menuItems} />
|
|
765
|
+
</DataGrid>;
|
|
766
|
+
```
|
|
767
|
+
|
|
768
|
+
Items are listed by `order`; one without it takes ten times its position in the array, so
|
|
769
|
+
10, 20, 30. Another plugin can add items with `registerMenuItem({ component, params?, order? })`
|
|
770
|
+
on the plugin's API (`getPlugin<DataGridActionsMenuPluginApi>('actionsMenu')`); without an
|
|
771
|
+
`order` it takes ten times one more than the number of items already there, so 20 when one is
|
|
772
|
+
(`10 * (count + 1)`). A new `menuItems` array replaces every item, the registered ones too, so
|
|
773
|
+
keep `menuItems` in a module-level constant or `useMemo`.
|
|
774
|
+
|
|
775
|
+
#### Export
|
|
776
|
+
|
|
777
|
+
`exportMenuItems(config?)` returns menu items that download the grid's rows: "Export as Excel", when
|
|
778
|
+
`loadExcelJs` is given, and "Export as CSV". Put them in `menuItems`:
|
|
779
|
+
|
|
780
|
+
```tsx
|
|
781
|
+
import {
|
|
782
|
+
DataGridActionsMenuPlugin,
|
|
783
|
+
exportMenuItems,
|
|
784
|
+
} from '@gears-frontx/ui-kit/data-grid/actions-menu';
|
|
785
|
+
|
|
786
|
+
const menuItems = exportMenuItems<User>({
|
|
787
|
+
filename: 'users',
|
|
788
|
+
// Excel only: install `exceljs` (4.4.0) in your app and hand the package over.
|
|
789
|
+
loadExcelJs: () => import('exceljs'),
|
|
790
|
+
});
|
|
791
|
+
|
|
792
|
+
<DataGrid<User> name="users" load={loadUsers} columns={columns}>
|
|
793
|
+
<DataGridActionsMenuPlugin menuItems={menuItems} />
|
|
794
|
+
</DataGrid>;
|
|
795
|
+
```
|
|
796
|
+
|
|
797
|
+
The kit never imports `exceljs`: `exceljs` is an optional peer dependency, and the import lives in
|
|
798
|
+
your code, so an app that exports only CSV does not install it and builds without it. Without
|
|
799
|
+
`loadExcelJs` there is no Excel item. `DataGridExcelJsModule`, what the loader resolves to, is
|
|
800
|
+
spelled out as the `Workbook` the export uses and names no `exceljs` type, so the kit's types
|
|
801
|
+
need nothing installed either.
|
|
802
|
+
|
|
803
|
+
| Option | Type | Default |
|
|
804
|
+
|--------|------|---------|
|
|
805
|
+
| `filename` | `string \| () => string` | `Report`; the extension is added when it is missing |
|
|
806
|
+
| `includeHeaders` | `boolean` | `true` |
|
|
807
|
+
| `delimiter` | `string` | `,` (CSV) |
|
|
808
|
+
| `sheetName` | `string` | `Sheet` (Excel) |
|
|
809
|
+
| `transformCellText` | `Record<columnId, ({ value, formattedValue, row }, grid) => string>` | none; replaces the text of one column's cells |
|
|
810
|
+
| `loadExcelJs` | `() => Promise<DataGridExcelJsModule>` | none; `() => import('exceljs')` fits, and without it there is CSV only |
|
|
811
|
+
| `onError` | `(error: Error) => void` | none; see below |
|
|
812
|
+
|
|
813
|
+
The export is of every row, not the page on screen:
|
|
814
|
+
- With the pagination plugin it reads the pages itself from `load`, with the search, filters and
|
|
815
|
+
order the grid has now, and leaves the grid on the page it was on (the pager's total is the one
|
|
816
|
+
thing it can change, for a lazy tree: see Known limitations).
|
|
817
|
+
- With the table tree plugin it walks the tree, each row followed by its children, closed rows
|
|
818
|
+
included; a lazy tree loads the children of every row that can have them, and keeps what it
|
|
819
|
+
loaded without opening those rows.
|
|
820
|
+
- Otherwise it is what is on screen.
|
|
821
|
+
|
|
822
|
+
The columns are the visible ones, in their order, headed by their labels. A cell is the row's
|
|
823
|
+
property named by the column's `key` (its `id` without one), through the column's `formatter` and
|
|
824
|
+
then `transformCellText`; a column drawn by `render` or `component` exports its value, not what is
|
|
825
|
+
drawn. In CSV a value that holds the delimiter, a quote or a line break is quoted, and one that
|
|
826
|
+
starts with `=`, `+`, `-`, `@`, a tab or a carriage return is quoted and prefixed with a tab, so a
|
|
827
|
+
spreadsheet does not read it as a formula. In Excel a value that nothing changed stays a number,
|
|
828
|
+
a boolean or a date, and a string that is an ISO date or a plain number (not one with a leading
|
|
829
|
+
zero, or an exponent) is written as one.
|
|
830
|
+
|
|
831
|
+
A failure while the cells are made goes to `onError`, or to `console.error` without it; the menu
|
|
832
|
+
closes when an item is chosen, so there is no other place to show it.
|
|
833
|
+
|
|
834
|
+
### `DataGridTableConfigurationPlugin`
|
|
835
|
+
|
|
836
|
+
Adds a gear button named "Configure columns" to the toolbar's `top-end` slot, after an
|
|
837
|
+
`actions` component and before the actions menu (order 10). It opens a popover headed "Table
|
|
838
|
+
configuration" that lists the grid's columns, so the user can show, hide and pin them. It
|
|
839
|
+
takes no props.
|
|
840
|
+
|
|
841
|
+
```tsx
|
|
842
|
+
import { DataGridTableConfigurationPlugin } from '@gears-frontx/ui-kit/data-grid/table-configuration';
|
|
843
|
+
|
|
844
|
+
<DataGrid name="users" load={loadUsers} columns={columns} persistentColumnVisibility>
|
|
845
|
+
<DataGridTableConfigurationPlugin />
|
|
846
|
+
</DataGrid>;
|
|
847
|
+
```
|
|
848
|
+
|
|
849
|
+
Every column has a switch for its visibility and a pin button for keeping it at the inline
|
|
850
|
+
start while the table scrolls sideways. The pin button shows while its row is hovered or has
|
|
851
|
+
keyboard focus, and always while the column is pinned. A group is a section: a pin button for
|
|
852
|
+
the group, then a switch for each column in it, with no pin button of their own. Pinning the
|
|
853
|
+
group pins its heading and all its columns together, and unpinning reverses it. The switch of
|
|
854
|
+
the last visible column is locked so the table is never empty, and a column's own
|
|
855
|
+
`visibleToggleDisabled` locks its switch.
|
|
856
|
+
|
|
857
|
+
A choice applies at once. Which columns are hidden survives a reload only with
|
|
858
|
+
`persistentColumnVisibility` on the grid; pins are not stored. A new `columns` array resets both.
|
|
859
|
+
|
|
860
|
+
The panel renders in a portal, so set its two size hooks on `:root` or `body`, not on the grid
|
|
861
|
+
(see CSS customization). It keeps inside the screen: its width floor gives way to the room there
|
|
862
|
+
is on a narrow one, and a list longer than the room scrolls inside it.
|
|
863
|
+
|
|
864
|
+
### `DataGridRowSelectPlugin`
|
|
865
|
+
|
|
866
|
+
Adds a checkbox column at the start, a select-all checkbox in its header, and an action bar
|
|
867
|
+
that replaces the toolbar while rows are selected.
|
|
868
|
+
|
|
869
|
+
| Prop | Type | Default |
|
|
870
|
+
|------|------|---------|
|
|
871
|
+
| `onSelectionChange` | `(items, meta) => void` | none; `meta` is `{ mode: 'none' \| 'page' \| 'all', count }` |
|
|
872
|
+
| `component` | `ComponentType<{ rowSelect }>` | none; your actions in the action bar |
|
|
873
|
+
| `statusComponent` | `ComponentType<{ rowSelect }>` | none; replaces the "N items selected" text |
|
|
874
|
+
| `multiple` | `boolean` | `true`; `false` allows one row, with no select-all checkbox |
|
|
875
|
+
| `showSelectAll` | `boolean` | `true`; the select-all checkbox in the header |
|
|
876
|
+
| `visible` | `(item) => boolean` | none; rows it rejects get no checkbox, and select-all skips them |
|
|
877
|
+
| `showSelectAllMatching` | `boolean` | `false`; see below |
|
|
878
|
+
| `keepHiddenSelection` | `boolean` | `false`; see below |
|
|
879
|
+
|
|
880
|
+
```tsx
|
|
881
|
+
import { DataGridRowSelectPlugin, type DataGridRowSelectPluginApi } from '@gears-frontx/ui-kit/data-grid/row-select';
|
|
882
|
+
|
|
883
|
+
function BulkActions({ rowSelect }: { rowSelect: DataGridRowSelectPluginApi<User> }) {
|
|
884
|
+
return (
|
|
885
|
+
<>
|
|
886
|
+
<Button variant="outline" onClick={rowSelect.clearSelection}>Cancel</Button>
|
|
887
|
+
<Button variant="destructive" onClick={() => deactivate(rowSelect.getSelectionDescriptor())}>
|
|
888
|
+
Deactivate
|
|
889
|
+
</Button>
|
|
890
|
+
</>
|
|
891
|
+
);
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
<DataGrid<User> name="users" load={loadUsers} columns={columns}>
|
|
895
|
+
<DataGridRowSelectPlugin<User> component={BulkActions} onSelectionChange={setSelected} />
|
|
896
|
+
</DataGrid>;
|
|
897
|
+
```
|
|
898
|
+
|
|
899
|
+
The action bar needs `component` or `statusComponent`; with neither, selecting only ticks the
|
|
900
|
+
checkboxes. It shows the count ("1 item selected", "3 items selected") at the end, or your
|
|
901
|
+
`statusComponent` in its place, and your `component` at the start. `rowSelect` is the plugin's
|
|
902
|
+
API: `useSelectedIds`, `useSelectionCount`, `useSelectionMode` and the other `use*` hooks read
|
|
903
|
+
it, `toggleSelection(id)`, `toggleSelectAll(value)` and `clearSelection()` change it.
|
|
904
|
+
|
|
905
|
+
Selection is kept per page, and it follows the rows that are loaded. Every load empties the
|
|
906
|
+
loaded rows while it runs, so every load clears the selection and calls `onSelectionChange` with
|
|
907
|
+
`[]` and `{ mode: 'none', count: 0 }`: a page change, a filter, a search, and also `refresh()` or
|
|
908
|
+
`triggerLoad()` when they bring back the very same rows. With `keepHiddenSelection` the ids
|
|
909
|
+
selected by hand survive loads. The `total` of the load result is mirrored, so the plugin does
|
|
910
|
+
not depend on the pagination plugin being registered first.
|
|
911
|
+
|
|
912
|
+
#### Select all matching
|
|
913
|
+
|
|
914
|
+
`showSelectAllMatching` is opt-in: turn it on only when your bulk action handles the all-matching
|
|
915
|
+
scope. With it on, once every selectable row on the page is selected and the load result's
|
|
916
|
+
`total` is more than the rows loaded, a banner offers "Select all N". Taking it enters
|
|
917
|
+
all-matching mode, every record that matches the current filter across all pages, without
|
|
918
|
+
listing ids. In that mode `onSelectionChange` still gets only the current page's items, and the
|
|
919
|
+
scope is in `meta` (`mode: 'all'`, `count: total`) and in `getSelectionDescriptor()`. Any single
|
|
920
|
+
row toggle, a clear, or any load leaves all-matching, and
|
|
921
|
+
`getSelectionDescriptor()` is back to ids. In single-selection mode the banner and all-matching
|
|
922
|
+
are off.
|
|
923
|
+
|
|
924
|
+
Send the descriptor, never a list of thousands of ids:
|
|
925
|
+
|
|
926
|
+
```tsx
|
|
927
|
+
const selection = rowSelect.getSelectionDescriptor();
|
|
928
|
+
// { mode: 'ids', ids: [1, 2, 3] } or { mode: 'all-matching' }
|
|
929
|
+
await (selection.mode === 'all-matching' ? deleteMatching(currentFilter) : deleteIds(selection.ids));
|
|
930
|
+
```
|
|
931
|
+
|
|
932
|
+
The count in all-matching mode is the load result's `total`, which the client cannot narrow by
|
|
933
|
+
`visible`, and a filter-based action acts on every match, so `visible` is not honoured by "select
|
|
934
|
+
all matching". If `visible` is a permission gate, leave `showSelectAllMatching` off. The backend
|
|
935
|
+
enforces permissions either way.
|
|
936
|
+
|
|
937
|
+
#### `keepHiddenSelection`
|
|
938
|
+
|
|
939
|
+
With it on, rows selected by hand stay selected when they leave the screen (another page, a
|
|
940
|
+
filter, a search). `onSelectionChange` then reports every selected item across pages, and the
|
|
941
|
+
select-all checkbox, which acts on the page, is ticked or mixed by the page's rows only. Select-all
|
|
942
|
+
adds the page to the selection rather than replacing it, but unticking it clears the whole
|
|
943
|
+
selection, other pages included, as the source grid does. It is not meant to be combined with
|
|
944
|
+
`showSelectAllMatching`: the one keeps a hand-picked set across pages, the other offers a single
|
|
945
|
+
scope.
|
|
946
|
+
|
|
947
|
+
#### With row click
|
|
948
|
+
|
|
949
|
+
The checkbox column marks its whole cell, header and body, as ignoring row clicks, so ticking a
|
|
950
|
+
box does not call a row click plugin's `click`. Nothing to configure.
|
|
951
|
+
|
|
952
|
+
### `DataGridTableTreePlugin`
|
|
953
|
+
|
|
954
|
+
Shows hierarchical rows as a tree: a row that has children gets a toggle button in the first
|
|
955
|
+
visible column, and its children appear under it, each level indented one step further. It
|
|
956
|
+
replaces the `row` and `body-cell-content` renderers, so it takes the whole row.
|
|
957
|
+
|
|
958
|
+
| Prop | Type | Notes |
|
|
959
|
+
|------|------|-------|
|
|
960
|
+
| `parentKey` | `string \| (item) => id` | Every row arrives in one load and names its parent by this field (or function); a row whose parent is `null` or `undefined` is a root, and the field has to be on every row. A row with children is expandable |
|
|
961
|
+
| `expandable` | `(item) => boolean` | Children load when a row opens: a row it accepts is expandable. Keep its identity between renders (a module-level function, or `useCallback`): a new one each render updates the plugin's props and re-renders every row |
|
|
962
|
+
|
|
963
|
+
Use one of the two. With neither, no row is expandable.
|
|
964
|
+
|
|
965
|
+
```tsx
|
|
966
|
+
import { DataGridTableTreePlugin } from '@gears-frontx/ui-kit/data-grid/table-tree';
|
|
967
|
+
|
|
968
|
+
interface Category {
|
|
969
|
+
id: number;
|
|
970
|
+
name: string;
|
|
971
|
+
parent_id: number | null;
|
|
972
|
+
hasChildren: boolean;
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
// Flat: one load returns every row, and each row names its parent.
|
|
976
|
+
<DataGrid<Category> name="categories" load={loadAllCategories} columns={columns}>
|
|
977
|
+
<DataGridTableTreePlugin<Category> parentKey="parent_id" />
|
|
978
|
+
</DataGrid>;
|
|
979
|
+
|
|
980
|
+
// Lazy: the children of a row load when it opens.
|
|
981
|
+
const hasChildren = (category: Category) => category.hasChildren;
|
|
982
|
+
|
|
983
|
+
async function loadCategories({ tree, signal }: DataGridLoadContext) {
|
|
984
|
+
const response = await fetchCategories({ parentId: tree?.parentId ?? null, signal });
|
|
985
|
+
return { results: response.items, total: response.total };
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
<DataGrid<Category> name="categories" load={loadCategories} columns={columns}>
|
|
989
|
+
<DataGridTableTreePlugin<Category> expandable={hasChildren} />
|
|
990
|
+
</DataGrid>;
|
|
991
|
+
```
|
|
992
|
+
|
|
993
|
+
In flat mode every row has to carry the `parentKey` field (`null` for a root). A row without it
|
|
994
|
+
fails the whole load: the first load shows the grid's error view, "Something went wrong", in place
|
|
995
|
+
of the table and logs `Key "…" not found in item …` to the console in development, and a later
|
|
996
|
+
load has no UI of its own (see Known limitations). A row's children are the rows of the same load
|
|
997
|
+
that name it as their parent, so with the pagination plugin a page has to hold the children of the
|
|
998
|
+
roots it shows, and a row whose parent is not in the load is not shown. Opening and closing a row
|
|
999
|
+
shows and hides its children and loads nothing.
|
|
1000
|
+
|
|
1001
|
+
In lazy mode `load` is called with `tree.parentId` set to the row's id when it opens, and
|
|
1002
|
+
`null` for the rows of the grid. That load carries the same `pagination`, `filters` and
|
|
1003
|
+
`order` as the rows' load, so read `tree.parentId` first and decide whether they apply to a
|
|
1004
|
+
branch. Closing a row keeps what was loaded: opening it again shows the children without a load.
|
|
1005
|
+
A refresh or a page change drops everything loaded; the open rows that come back in the new
|
|
1006
|
+
load fetch their children again.
|
|
1007
|
+
|
|
1008
|
+
The toggle sits in the first visible column, so hiding that column moves it to the next one.
|
|
1009
|
+
Clicking it does not call the row click plugin's `click`.
|
|
1010
|
+
|
|
1011
|
+
#### Persisted expand state
|
|
1012
|
+
|
|
1013
|
+
Which rows are open is stored with the grid's other state, under `dataGrid:${name}:tree`, as a
|
|
1014
|
+
list of ids with no opt-in. The list keeps the 200 most recent ids and is read back with the
|
|
1015
|
+
same cap, and anything in it that is not a string or a number is ignored. Under
|
|
1016
|
+
`persistent="router"` the expand state is not stored at all: the list holds ids of rows that may
|
|
1017
|
+
no longer exist, and a copied link would carry all of that into whichever grid opens it.
|
|
1018
|
+
|
|
1019
|
+
- Ids are kept when the page changes, so coming back to a page restores its open rows; ids of
|
|
1020
|
+
other pages stay stored and take effect once those rows load.
|
|
1021
|
+
- In lazy mode a restored row's children are fetched when its record arrives, and a restored id
|
|
1022
|
+
whose row turns out not to be expandable is dropped from the list.
|
|
1023
|
+
|
|
1024
|
+
The plugin's API (`getPlugin<DataGridTableTreePluginApi>('tableTree')`) has `toggle(id)`, which
|
|
1025
|
+
opens or closes a row and stores the change, `useIsExpanded(id)`, `useIsExpandable(record)`,
|
|
1026
|
+
`isExpandable(record)` (the same check outside a render) and `useLevel(section)`, the depth of
|
|
1027
|
+
a section's rows.
|
|
1028
|
+
|
|
1029
|
+
#### With row click
|
|
1030
|
+
|
|
1031
|
+
Declare `DataGridRowClickPlugin` before the tree. Both replace the `row` renderer and the last
|
|
1032
|
+
one registered wins. The tree's row does what the row click plugin's does when that plugin is
|
|
1033
|
+
registered (`click`, `dblclick`, Enter, a tab stop and the pointer cursor on every row, the
|
|
1034
|
+
children's too), so with the tree last the two work together. With the row click plugin last,
|
|
1035
|
+
its rows replace the tree's, which draw no children: a toggle opens a branch that never appears.
|
|
1036
|
+
|
|
1037
|
+
```tsx
|
|
1038
|
+
<DataGrid<Category> name="categories" load={loadCategories} columns={columns}>
|
|
1039
|
+
<DataGridRowClickPlugin<Category> click={(category) => navigate(`/categories/${category.id}`)} />
|
|
1040
|
+
<DataGridTableTreePlugin<Category> expandable={hasChildren} />
|
|
1041
|
+
</DataGrid>
|
|
1042
|
+
```
|
|
1043
|
+
|
|
1044
|
+
### `createDataGridDragDropPlugin`
|
|
1045
|
+
|
|
1046
|
+
Adds a handle column at the start of the grid and lets the user reorder rows by dragging a row,
|
|
1047
|
+
by its handle, onto another row or onto the grid. It replaces the `row` and `content` renderers.
|
|
1048
|
+
Unlike the other plugins it is a factory: the callbacks are its configuration, and what it
|
|
1049
|
+
returns is the component to render as a child of the grid. Create it once, outside render, or in
|
|
1050
|
+
`useState`. `onDrop` is the one it was created with, so anything it needs that changes between
|
|
1051
|
+
renders has to reach it some other way, through a ref or a store.
|
|
1052
|
+
|
|
1053
|
+
| Option | Type | Notes |
|
|
1054
|
+
|--------|------|-------|
|
|
1055
|
+
| `onDrop` | `({ item, target, ...context }) => void \| Promise<void>` | Required. `item` is the dragged row's item and `target` the item of the row it was dropped on, or `null` for a drop on the grid and not on a row. The rest is the plugin context, so `refresh()` reloads the grid |
|
|
1056
|
+
| `renderDragPreview` | `(item) => ReactNode` | What follows the pointer; without it, a copy of the dragged row |
|
|
1057
|
+
|
|
1058
|
+
```tsx
|
|
1059
|
+
import { createDataGridDragDropPlugin } from '@gears-frontx/ui-kit/data-grid/drag-drop';
|
|
1060
|
+
|
|
1061
|
+
const DragDrop = createDataGridDragDropPlugin<Task>({
|
|
1062
|
+
onDrop: async ({ item, target, refresh }) => {
|
|
1063
|
+
// `target` is the row the task was dropped on, or null when it was dropped on the grid.
|
|
1064
|
+
await moveTask(item.id, target?.id ?? null);
|
|
1065
|
+
await refresh({ resetFilters: false });
|
|
1066
|
+
},
|
|
1067
|
+
});
|
|
1068
|
+
|
|
1069
|
+
<DataGrid<Task> name="tasks" load={loadTasks} columns={columns}>
|
|
1070
|
+
<DragDrop />
|
|
1071
|
+
</DataGrid>;
|
|
1072
|
+
```
|
|
1073
|
+
|
|
1074
|
+
The plugin does not reorder anything: it reports the drop, and `onDrop` moves the row, usually on
|
|
1075
|
+
the server, and reloads. It is told the item and the row it was dropped on, and not which edge of
|
|
1076
|
+
that row the pointer was nearer.
|
|
1077
|
+
|
|
1078
|
+
The handle is the only place a drag can start, and dragging is pointer-only: there is no keyboard
|
|
1079
|
+
way to move a row. While a row is dragged it is tinted, the row under the pointer is tinted too
|
|
1080
|
+
and has a line on its top or bottom edge, and a drop on the grid outside every row outlines the
|
|
1081
|
+
whole grid. A drop outside the grid does nothing.
|
|
1082
|
+
|
|
1083
|
+
When `onDrop` returns a promise, the handle of the dragged row shows a spinner until it settles.
|
|
1084
|
+
A rejection is swallowed and the spinner stops: handle errors inside `onDrop`. A callback that
|
|
1085
|
+
returns anything else is done at once.
|
|
1086
|
+
|
|
1087
|
+
The handle, which fills its cell, is marked `data-grid-row-ignore-click`; the rest of the cell
|
|
1088
|
+
around it is not, since there is none. Only this entry loads the drag
|
|
1089
|
+
library (`@atlaskit/pragmatic-drag-and-drop`, a dependency of the kit), so a grid without the
|
|
1090
|
+
plugin ships none of it.
|
|
1091
|
+
|
|
1092
|
+
`--data-grid-drag-cursor` sets the cursor over a handle at rest (see CSS customization).
|
|
1093
|
+
|
|
1094
|
+
#### With other row plugins
|
|
1095
|
+
|
|
1096
|
+
Row click, the table tree and drag and drop each replace the `row` renderer and the last one
|
|
1097
|
+
registered wins, so declaration order decides what a grid with two of them does:
|
|
1098
|
+
|
|
1099
|
+
| Declared last | What the grid does |
|
|
1100
|
+
|---------------|--------------------|
|
|
1101
|
+
| Drag and drop, after row click | Rows drag; the row click callbacks are not called |
|
|
1102
|
+
| Row click, after drag and drop | Rows click; the handle column is drawn but nothing drags |
|
|
1103
|
+
| Drag and drop, after the table tree | Rows drag, and the tree's toggle and indentation are drawn, but opening a row shows no children |
|
|
1104
|
+
| The table tree, after drag and drop | The tree's rows show their children; the handle column is drawn but nothing drags |
|
|
1105
|
+
|
|
1106
|
+
With row select the handle column comes first, ahead of the checkboxes.
|
|
1107
|
+
|
|
566
1108
|
## Custom plugins
|
|
567
1109
|
|
|
568
1110
|
`createDataGridPlugin(name, setup, propsAreEqual?)` returns a component to use as
|
|
@@ -671,6 +1213,10 @@ Set these on the grid or any ancestor:
|
|
|
671
1213
|
| `--data-grid-table-min-inline-size` | `max-content` | Floor for the table's width. Raise it for a narrow pane that starves flexible columns, set it to `0` for a grid that must fit its wrapper. |
|
|
672
1214
|
| `--data-grid-header-background` | `var(--card)` | Fill of the header cells while `stickyHeader` is on |
|
|
673
1215
|
| `--data-grid-text-search-inline-size` | `initial` | Width of the search box; a fixed value stops it shifting as the clear button appears |
|
|
1216
|
+
| `--data-grid-table-configuration-min-inline-size` | `304px` | Minimum width of the table configuration panel. The panel renders in a portal: set it on `:root` or `body` |
|
|
1217
|
+
| `--data-grid-table-configuration-content-max-block-size` | `500px` | Height at which the panel's column list scrolls. Set it where the panel's portal is under the cascade, like the width |
|
|
1218
|
+
| `--data-grid-drag-cursor` | `grab` | Cursor over a drag handle at rest. The row being dragged sets it to `grabbing` on itself, so a value set above it applies before and after a drag |
|
|
1219
|
+
| `--data-grid-pinned-background` | `var(--card)` | Fill of a pinned column's cells at rest. A pinned cell is painted with its row's own fill over it, so it follows hover and the other row states. Set `var(--background)` for a grid that sits on the page rather than on a card |
|
|
674
1220
|
|
|
675
1221
|
The floor is one constraint among several: under `'fixed'` a table whose columns
|
|
676
1222
|
declare widths cannot shrink below their sum, and under either mode not below the
|
|
@@ -683,7 +1229,10 @@ columns' minimum content widths.
|
|
|
683
1229
|
- The table's scroll container is a tab stop (it holds `tabIndex=0` so a keyboard
|
|
684
1230
|
can scroll it).
|
|
685
1231
|
- The pager is a `nav` named "Pagination"; the page buttons are named "Go to page
|
|
686
|
-
N" and carry `aria-current="page"` on the current one.
|
|
1232
|
+
N" and carry `aria-current="page"` on the current one. A grid with a `label`
|
|
1233
|
+
names its pager `<label> pagination` and its table's scroll container a
|
|
1234
|
+
`region` named `<label>` - pass a distinct `label` per grid when a page
|
|
1235
|
+
holds more than one grid, so their landmarks do not collide.
|
|
687
1236
|
- `aria-busy` is set on the content region while a loader is on screen.
|
|
688
1237
|
- The order popover's items are menu items without a menu popup, so they take
|
|
689
1238
|
focus and Enter and Space, but arrow keys do not move between them.
|
|
@@ -698,6 +1247,20 @@ columns' minimum content widths.
|
|
|
698
1247
|
or by Tab to its radio and Space.
|
|
699
1248
|
- The "All filters" panel is a dialog; it is left with its close button (named
|
|
700
1249
|
"Close dialog"), Escape or a click outside.
|
|
1250
|
+
- The table configuration panel is built like the order popover, from menu items without
|
|
1251
|
+
a menu popup: its switches and pin buttons are reached with Tab, not with arrow keys, the
|
|
1252
|
+
switches carry no accessible name of their own (the column's name is the text beside them),
|
|
1253
|
+
and the pin buttons are named "Pin column" and "Unpin column" without the column.
|
|
1254
|
+
- With the row click plugin every body row is a tab stop and Enter activates it; Space
|
|
1255
|
+
does not.
|
|
1256
|
+
- Drag and drop is pointer-only: there is no keyboard way to move a row. The handle is a `div`
|
|
1257
|
+
with the label "Drag to reorder row" and no role, so it is not reached with Tab and a screen
|
|
1258
|
+
reader does not announce it as a control.
|
|
1259
|
+
- The table tree's toggle is a native `button` with no accessible name and no `aria-expanded`,
|
|
1260
|
+
so a screen reader announces an unnamed button and not whether the row is open.
|
|
1261
|
+
- The row select checkboxes, the select-all one included, have no accessible name. "Select all
|
|
1262
|
+
N" and "Clear selection" in the banner are buttons, and the banner is an `alert`, so it is
|
|
1263
|
+
announced when it appears.
|
|
701
1264
|
- Strings are English and live in one module; the kit has no i18n layer yet.
|
|
702
1265
|
|
|
703
1266
|
## Known limitations
|
|
@@ -718,7 +1281,44 @@ columns' minimum content widths.
|
|
|
718
1281
|
refresh runs after the grid is gone, and its load's `signal` is not aborted.
|
|
719
1282
|
- The loading overlay blocks the pointer only, not the keyboard.
|
|
720
1283
|
- No `aria-sort`; Previous and Next drop keyboard focus at the ends of the range.
|
|
721
|
-
-
|
|
1284
|
+
- With the row click plugin, activating an item of a menu that a row action opens fires the row
|
|
1285
|
+
click, and fires it twice: with the mouse, and with Enter on the item (Space does not, a row
|
|
1286
|
+
ignores it). The menu renders in a portal, so the item is not inside the element marked to
|
|
1287
|
+
ignore row clicks, and a React event still bubbles from it to the row, where it arrives twice.
|
|
1288
|
+
Stop both in the menu's content, which leaves the item's own `onClick`, Escape and the arrow
|
|
1289
|
+
keys as they were:
|
|
1290
|
+
|
|
1291
|
+
```tsx
|
|
1292
|
+
<DropdownMenuContent
|
|
1293
|
+
onClick={(event) => event.stopPropagation()}
|
|
1294
|
+
onKeyDown={(event) => {
|
|
1295
|
+
if (event.key === 'Enter') event.stopPropagation();
|
|
1296
|
+
}}
|
|
1297
|
+
>
|
|
1298
|
+
```
|
|
1299
|
+
- The export reads a cell as `item[key]`, a plain property and not a path: a column whose `key` is
|
|
1300
|
+
dotted exports empty, though the grid shows the nested value. A failing `load` while it reads
|
|
1301
|
+
the pages is logged to the console and does not reach `onError`, and the `format` and `encoding`
|
|
1302
|
+
options are accepted and ignored.
|
|
1303
|
+
- Renderer overrides (`registerComponent`) are last registered wins. The row click, table
|
|
1304
|
+
tree and drag and drop plugins all override `row`, so declare the tree after row click (see
|
|
1305
|
+
the tree's section), and see "With other row plugins" under drag and drop for what each
|
|
1306
|
+
pair does.
|
|
1307
|
+
- With the drag and drop plugin, a row dropped on itself is not refused: a row is never its own
|
|
1308
|
+
target, so the drop falls through to the grid and `onDrop` is called with a `null` target, the
|
|
1309
|
+
same as for a drop outside every row. A row dropped on another grid that has the plugin does
|
|
1310
|
+
the same for its own grid: its `onDrop` is called with `target: null`, and the other grid's is
|
|
1311
|
+
not.
|
|
1312
|
+
- The line on a drop target's edge is the edge the pointer entered the row by: it does not
|
|
1313
|
+
follow the pointer inside the row. The grid's outline for a drop on the grid shows once the
|
|
1314
|
+
pointer has been over another row first, since a drag starts over its own row.
|
|
1315
|
+
- In lazy mode, the load of a row's children replaces the `total` that the pagination plugin
|
|
1316
|
+
shows and that row select mirrors with the children's own: after a row is opened the pager
|
|
1317
|
+
counts its children until the next load of the rows. The export of a lazy tree does the same,
|
|
1318
|
+
since it loads the children of every row that can have them: with the pagination plugin the pager
|
|
1319
|
+
is left counting the last branch it loaded (`Page 1 of 4 (11 items)` reads `Page 1 of 1 (1
|
|
1320
|
+
items)`) until the grid loads its rows again. The export's file and the rows on screen are not
|
|
1321
|
+
affected.
|
|
722
1322
|
- `registerComponent` accepts `'header-cell'` and `'header-group'`, but the header
|
|
723
1323
|
always renders its own cell and group components, so those two overrides have no
|
|
724
1324
|
effect.
|