@gears-frontx/ui-kit 0.4.0 → 0.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/NOTICE +1 -0
- package/README.md +2 -1
- package/dist/chunks/data-grid.DIkpRRaf.css +1 -0
- package/dist/chunks/deep-equal.js +15 -0
- package/dist/chunks/deep-equal.js.map +1 -0
- package/dist/chunks/messages.js +42 -0
- package/dist/chunks/messages.js.map +1 -0
- package/dist/chunks/order.D7Jg_Mg8.css +1 -0
- package/dist/chunks/page-header.72nfJNkg.css +1 -0
- package/dist/chunks/pagination.Cn8tIWMX.css +1 -0
- package/dist/chunks/plugins-helpers.js +41 -0
- package/dist/chunks/plugins-helpers.js.map +1 -0
- package/dist/chunks/segment.js +18 -0
- package/dist/chunks/segment.js.map +1 -0
- package/dist/chunks/text-search.BeZYac6V.css +1 -0
- package/dist/components/data-grid/components/data-grid-content.d.ts +3 -0
- package/dist/components/data-grid/components/data-grid-content.d.ts.map +1 -0
- package/dist/components/data-grid/components/data-grid-empty-state.d.ts +3 -0
- package/dist/components/data-grid/components/data-grid-empty-state.d.ts.map +1 -0
- package/dist/components/data-grid/components/data-grid-spinner.d.ts +16 -0
- package/dist/components/data-grid/components/data-grid-spinner.d.ts.map +1 -0
- package/dist/components/data-grid/components/load-controlled.d.ts +15 -0
- package/dist/components/data-grid/components/load-controlled.d.ts.map +1 -0
- package/dist/components/data-grid/components/segment.d.ts +15 -0
- package/dist/components/data-grid/components/segment.d.ts.map +1 -0
- package/dist/components/data-grid/create-data-grid.d.ts +4 -0
- package/dist/components/data-grid/create-data-grid.d.ts.map +1 -0
- package/dist/components/data-grid/data-grid-types.d.ts +142 -0
- package/dist/components/data-grid/data-grid-types.d.ts.map +1 -0
- package/dist/components/data-grid/data-grid.d.ts +3 -0
- package/dist/components/data-grid/data-grid.d.ts.map +1 -0
- package/dist/components/data-grid/messages.d.ts +39 -0
- package/dist/components/data-grid/messages.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/empty-state/empty-state-plugin.d.ts +5 -0
- package/dist/components/data-grid/plugins/empty-state/empty-state-plugin.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/empty-state/empty-state-types.d.ts +14 -0
- package/dist/components/data-grid/plugins/empty-state/empty-state-types.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/empty-state/public.d.ts +3 -0
- package/dist/components/data-grid/plugins/empty-state/public.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/order/components/data-grid-order-button.d.ts +3 -0
- package/dist/components/data-grid/plugins/order/components/data-grid-order-button.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/order/components/data-grid-order-header-cell-label.d.ts +8 -0
- package/dist/components/data-grid/plugins/order/components/data-grid-order-header-cell-label.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/order/components/data-grid-order-icon.d.ts +7 -0
- package/dist/components/data-grid/plugins/order/components/data-grid-order-icon.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/order/order-plugin.d.ts +4 -0
- package/dist/components/data-grid/plugins/order/order-plugin.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/order/order-types.d.ts +66 -0
- package/dist/components/data-grid/plugins/order/order-types.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/order/public.d.ts +5 -0
- package/dist/components/data-grid/plugins/order/public.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/order/services/order-labels.d.ts +8 -0
- package/dist/components/data-grid/plugins/order/services/order-labels.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/order/services/order-option.d.ts +3 -0
- package/dist/components/data-grid/plugins/order/services/order-option.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/pagination/components/data-grid-pagination.d.ts +3 -0
- package/dist/components/data-grid/plugins/pagination/components/data-grid-pagination.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/pagination/components/pager.d.ts +22 -0
- package/dist/components/data-grid/plugins/pagination/components/pager.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/pagination/pagination-plugin.d.ts +31 -0
- package/dist/components/data-grid/plugins/pagination/pagination-plugin.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/pagination/public.d.ts +3 -0
- package/dist/components/data-grid/plugins/pagination/public.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/pagination/services/pagination-items.d.ts +14 -0
- package/dist/components/data-grid/plugins/pagination/services/pagination-items.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/text-search/components/data-grid-text-search.d.ts +3 -0
- package/dist/components/data-grid/plugins/text-search/components/data-grid-text-search.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/text-search/public.d.ts +3 -0
- package/dist/components/data-grid/plugins/text-search/public.d.ts.map +1 -0
- package/dist/components/data-grid/plugins/text-search/text-search-plugin.d.ts +38 -0
- package/dist/components/data-grid/plugins/text-search/text-search-plugin.d.ts.map +1 -0
- package/dist/components/data-grid/public.d.ts +12 -0
- package/dist/components/data-grid/public.d.ts.map +1 -0
- package/dist/components/data-grid/services/columns/create-column-auto-size.d.ts +7 -0
- package/dist/components/data-grid/services/columns/create-column-auto-size.d.ts.map +1 -0
- package/dist/components/data-grid/services/core/core-service.d.ts +3 -0
- package/dist/components/data-grid/services/core/core-service.d.ts.map +1 -0
- package/dist/components/data-grid/services/core/core-types.d.ts +28 -0
- package/dist/components/data-grid/services/core/core-types.d.ts.map +1 -0
- package/dist/components/data-grid/services/core/data-grid-context.d.ts +17 -0
- package/dist/components/data-grid/services/core/data-grid-context.d.ts.map +1 -0
- package/dist/components/data-grid/services/hooked/hooked-types.d.ts +34 -0
- package/dist/components/data-grid/services/hooked/hooked-types.d.ts.map +1 -0
- package/dist/components/data-grid/services/hooked/hooked.d.ts +4 -0
- package/dist/components/data-grid/services/hooked/hooked.d.ts.map +1 -0
- package/dist/components/data-grid/services/internal/internal-helpers.d.ts +2 -0
- package/dist/components/data-grid/services/internal/internal-helpers.d.ts.map +1 -0
- package/dist/components/data-grid/services/layout/components/data-grid-layout-content.d.ts +7 -0
- package/dist/components/data-grid/services/layout/components/data-grid-layout-content.d.ts.map +1 -0
- package/dist/components/data-grid/services/layout/components/data-grid-layout-main-slot-selector.d.ts +4 -0
- package/dist/components/data-grid/services/layout/components/data-grid-layout-main-slot-selector.d.ts.map +1 -0
- package/dist/components/data-grid/services/layout/components/data-grid-layout-main.d.ts +3 -0
- package/dist/components/data-grid/services/layout/components/data-grid-layout-main.d.ts.map +1 -0
- package/dist/components/data-grid/services/layout/components/data-grid-layout-slot.d.ts +7 -0
- package/dist/components/data-grid/services/layout/components/data-grid-layout-slot.d.ts.map +1 -0
- package/dist/components/data-grid/services/layout/components/data-grid-layout-top-default.d.ts +3 -0
- package/dist/components/data-grid/services/layout/components/data-grid-layout-top-default.d.ts.map +1 -0
- package/dist/components/data-grid/services/layout/components/data-grid-layout-top.d.ts +3 -0
- package/dist/components/data-grid/services/layout/components/data-grid-layout-top.d.ts.map +1 -0
- package/dist/components/data-grid/services/layout/data-grid-view.d.ts +16 -0
- package/dist/components/data-grid/services/layout/data-grid-view.d.ts.map +1 -0
- package/dist/components/data-grid/services/layout/layout-service.d.ts +4 -0
- package/dist/components/data-grid/services/layout/layout-service.d.ts.map +1 -0
- package/dist/components/data-grid/services/layout/layout-slot-ids.d.ts +3 -0
- package/dist/components/data-grid/services/layout/layout-slot-ids.d.ts.map +1 -0
- package/dist/components/data-grid/services/layout/layout-types.d.ts +74 -0
- package/dist/components/data-grid/services/layout/layout-types.d.ts.map +1 -0
- package/dist/components/data-grid/services/load/load-instance.d.ts +4 -0
- package/dist/components/data-grid/services/load/load-instance.d.ts.map +1 -0
- package/dist/components/data-grid/services/load/load-service.d.ts +4 -0
- package/dist/components/data-grid/services/load/load-service.d.ts.map +1 -0
- package/dist/components/data-grid/services/load/load-types.d.ts +76 -0
- package/dist/components/data-grid/services/load/load-types.d.ts.map +1 -0
- package/dist/components/data-grid/services/load/use-data-grid-loading.d.ts +16 -0
- package/dist/components/data-grid/services/load/use-data-grid-loading.d.ts.map +1 -0
- package/dist/components/data-grid/services/persistent-state/persistent-state-service.d.ts +4 -0
- package/dist/components/data-grid/services/persistent-state/persistent-state-service.d.ts.map +1 -0
- package/dist/components/data-grid/services/persistent-state/persistent-state-types.d.ts +36 -0
- package/dist/components/data-grid/services/persistent-state/persistent-state-types.d.ts.map +1 -0
- package/dist/components/data-grid/services/plugins/plugins-helpers.d.ts +49 -0
- package/dist/components/data-grid/services/plugins/plugins-helpers.d.ts.map +1 -0
- package/dist/components/data-grid/services/plugins/plugins-service.d.ts +4 -0
- package/dist/components/data-grid/services/plugins/plugins-service.d.ts.map +1 -0
- package/dist/components/data-grid/services/plugins/plugins-types.d.ts +62 -0
- package/dist/components/data-grid/services/plugins/plugins-types.d.ts.map +1 -0
- package/dist/components/data-grid/services/storage/storage-helpers.d.ts +4 -0
- package/dist/components/data-grid/services/storage/storage-helpers.d.ts.map +1 -0
- package/dist/components/data-grid/services/storage/storage-service.d.ts +4 -0
- package/dist/components/data-grid/services/storage/storage-service.d.ts.map +1 -0
- package/dist/components/data-grid/services/storage/storage-types.d.ts +93 -0
- package/dist/components/data-grid/services/storage/storage-types.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/components/data-grid-body-cell-content.d.ts +9 -0
- package/dist/components/data-grid/services/table/components/data-grid-body-cell-content.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/components/data-grid-cell.d.ts +57 -0
- package/dist/components/data-grid/services/table/components/data-grid-cell.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/components/data-grid-content.d.ts +7 -0
- package/dist/components/data-grid/services/table/components/data-grid-content.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/components/data-grid-extra-body-columns.d.ts +8 -0
- package/dist/components/data-grid/services/table/components/data-grid-extra-body-columns.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/components/data-grid-extra-header-cell.d.ts +12 -0
- package/dist/components/data-grid/services/table/components/data-grid-extra-header-cell.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/components/data-grid-extra-header-columns.d.ts +10 -0
- package/dist/components/data-grid/services/table/components/data-grid-extra-header-columns.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/components/data-grid-header-cell-content.d.ts +7 -0
- package/dist/components/data-grid/services/table/components/data-grid-header-cell-content.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/components/data-grid-header-cell-label.d.ts +8 -0
- package/dist/components/data-grid/services/table/components/data-grid-header-cell-label.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/components/data-grid-header-cell.d.ts +11 -0
- package/dist/components/data-grid/services/table/components/data-grid-header-cell.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/components/data-grid-header-group.d.ts +10 -0
- package/dist/components/data-grid/services/table/components/data-grid-header-group.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/components/data-grid-row.d.ts +8 -0
- package/dist/components/data-grid/services/table/components/data-grid-row.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/components/data-grid-table-body.d.ts +3 -0
- package/dist/components/data-grid/services/table/components/data-grid-table-body.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/components/data-grid-table-header.d.ts +3 -0
- package/dist/components/data-grid/services/table/components/data-grid-table-header.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/components/data-grid-table-record.d.ts +8 -0
- package/dist/components/data-grid/services/table/components/data-grid-table-record.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/components/data-grid-table-records.d.ts +8 -0
- package/dist/components/data-grid/services/table/components/data-grid-table-records.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/components/data-grid-table-slot.d.ts +7 -0
- package/dist/components/data-grid/services/table/components/data-grid-table-slot.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/components/data-grid-table.d.ts +3 -0
- package/dist/components/data-grid/services/table/components/data-grid-table.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/data-grid-record-context.d.ts +5 -0
- package/dist/components/data-grid/services/table/data-grid-record-context.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/ignore-row-click.d.ts +2 -0
- package/dist/components/data-grid/services/table/ignore-row-click.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/resolve-body-cell-props.d.ts +21 -0
- package/dist/components/data-grid/services/table/resolve-body-cell-props.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/resolve-column-style.d.ts +62 -0
- package/dist/components/data-grid/services/table/resolve-column-style.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/table-columns-persistence.d.ts +19 -0
- package/dist/components/data-grid/services/table/table-columns-persistence.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/table-columns.d.ts +15 -0
- package/dist/components/data-grid/services/table/table-columns.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/table-context.d.ts +4 -0
- package/dist/components/data-grid/services/table/table-context.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/table-extra-columns.d.ts +12 -0
- package/dist/components/data-grid/services/table/table-extra-columns.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/table-header.d.ts +11 -0
- package/dist/components/data-grid/services/table/table-header.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/table-helpers.d.ts +13 -0
- package/dist/components/data-grid/services/table/table-helpers.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/table-min-content-width.d.ts +36 -0
- package/dist/components/data-grid/services/table/table-min-content-width.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/table-service.d.ts +4 -0
- package/dist/components/data-grid/services/table/table-service.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/table-slots.d.ts +9 -0
- package/dist/components/data-grid/services/table/table-slots.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/table-sticky.d.ts +35 -0
- package/dist/components/data-grid/services/table/table-sticky.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/table-store.d.ts +4 -0
- package/dist/components/data-grid/services/table/table-store.d.ts.map +1 -0
- package/dist/components/data-grid/services/table/table-types.d.ts +239 -0
- package/dist/components/data-grid/services/table/table-types.d.ts.map +1 -0
- package/dist/components/data-grid/utils/debounce.d.ts +7 -0
- package/dist/components/data-grid/utils/debounce.d.ts.map +1 -0
- package/dist/components/data-grid/utils/deep-equal.d.ts +7 -0
- package/dist/components/data-grid/utils/deep-equal.d.ts.map +1 -0
- package/dist/components/data-grid/utils/hooked.d.ts +17 -0
- package/dist/components/data-grid/utils/hooked.d.ts.map +1 -0
- package/dist/components/data-grid/utils/is-record.d.ts +3 -0
- package/dist/components/data-grid/utils/is-record.d.ts.map +1 -0
- package/dist/components/data-grid/utils/load-state.d.ts +22 -0
- package/dist/components/data-grid/utils/load-state.d.ts.map +1 -0
- package/dist/components/data-grid/utils/use-latest.d.ts +4 -0
- package/dist/components/data-grid/utils/use-latest.d.ts.map +1 -0
- package/dist/components/page-header/page-header.d.ts +50 -0
- package/dist/components/page-header/page-header.d.ts.map +1 -0
- package/dist/components/page-header/public.d.ts +2 -0
- package/dist/components/page-header/public.d.ts.map +1 -0
- package/dist/data-grid/empty-state.d.ts +1 -0
- package/dist/data-grid/empty-state.js +27 -0
- package/dist/data-grid/empty-state.js.map +1 -0
- package/dist/data-grid/order.d.ts +1 -0
- package/dist/data-grid/order.js +254 -0
- package/dist/data-grid/order.js.map +1 -0
- package/dist/data-grid/pagination.d.ts +1 -0
- package/dist/data-grid/pagination.js +215 -0
- package/dist/data-grid/pagination.js.map +1 -0
- package/dist/data-grid/text-search.d.ts +1 -0
- package/dist/data-grid/text-search.js +112 -0
- package/dist/data-grid/text-search.js.map +1 -0
- package/dist/data-grid.d.ts +1 -0
- package/dist/data-grid.js +1650 -0
- package/dist/data-grid.js.map +1 -0
- package/dist/docs/data-grid.md +588 -0
- package/dist/docs/page-header.md +266 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +408 -381
- package/dist/index.js.map +1 -1
- package/dist/page-header.d.ts +1 -0
- package/dist/page-header.js +88 -0
- package/dist/page-header.js.map +1 -0
- package/llms.txt +21 -3
- package/package.json +4 -2
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
# DataGrid
|
|
2
|
+
|
|
3
|
+
A server-driven data grid: a `DataGrid` that renders rows through the kit's
|
|
4
|
+
`Table`, a `load(ctx)` callback that fetches them, a slot-based layout around
|
|
5
|
+
the table, and plugins that add behavior (paging, search, sorting, a custom
|
|
6
|
+
empty state) by registering into those slots and hooking the load. Each concern
|
|
7
|
+
(load, layout, table, storage, persistence) is a service with its own store, and
|
|
8
|
+
a plugin reaches all of them through one context object.
|
|
9
|
+
|
|
10
|
+
Built-in plugins: pagination, text search, order and empty state, each its own
|
|
11
|
+
entry (see below).
|
|
12
|
+
|
|
13
|
+
## When to use
|
|
14
|
+
|
|
15
|
+
- A list backed by an API that pages, searches and sorts on the server, where
|
|
16
|
+
the page, the query and the order must survive a reload or live in the URL.
|
|
17
|
+
- A list whose behavior you want to extend by composition: each feature is a
|
|
18
|
+
child component of `DataGrid`, and you can write your own the same way
|
|
19
|
+
(see "Custom plugins").
|
|
20
|
+
|
|
21
|
+
## When not to use
|
|
22
|
+
|
|
23
|
+
- Static, already-loaded rows with at most client-side sorting and paging -
|
|
24
|
+
use `DataTable`.
|
|
25
|
+
- Plain tabular markup you will drive yourself - use `Table`.
|
|
26
|
+
|
|
27
|
+
## Imports and entries
|
|
28
|
+
|
|
29
|
+
The grid is split in entries so a grid that uses no plugin ships none of their
|
|
30
|
+
code or CSS:
|
|
31
|
+
|
|
32
|
+
| Entry | Exports |
|
|
33
|
+
|-------|---------|
|
|
34
|
+
| `@gears-frontx/ui-kit/data-grid` | `DataGrid`, `createDataGridPlugin`, `useDataGrid`, `useDataGridPluginContext`, `useDataGridRecord`, `useDataGridActiveView`, `DATA_GRID_VIEW`, and the types |
|
|
35
|
+
| `@gears-frontx/ui-kit/data-grid/pagination` | `DataGridPaginationPlugin` |
|
|
36
|
+
| `@gears-frontx/ui-kit/data-grid/text-search` | `DataGridTextSearchPlugin` |
|
|
37
|
+
| `@gears-frontx/ui-kit/data-grid/order` | `DataGridOrderPlugin`, `createDataGridOrderOption` |
|
|
38
|
+
| `@gears-frontx/ui-kit/data-grid/empty-state` | `DataGridEmptyStatePlugin` |
|
|
39
|
+
|
|
40
|
+
The package root re-exports all of them, so
|
|
41
|
+
`import { DataGrid, DataGridPaginationPlugin } from '@gears-frontx/ui-kit'`
|
|
42
|
+
works too; a bundler that honors `sideEffects` keeps only what is used. The core
|
|
43
|
+
entry never imports a plugin. The core and every plugin entry carry `'use client'`,
|
|
44
|
+
so a Server Component can import and render them; props that are functions
|
|
45
|
+
(`load`, a column's `render`) have to come from a Client Component.
|
|
46
|
+
|
|
47
|
+
## Quick start
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
import {
|
|
51
|
+
DataGrid,
|
|
52
|
+
DataGridOrderPlugin,
|
|
53
|
+
DataGridPaginationPlugin,
|
|
54
|
+
DataGridTextSearchPlugin,
|
|
55
|
+
type DataGridLoadContext,
|
|
56
|
+
type DataGridTableColumn,
|
|
57
|
+
} from '@gears-frontx/ui-kit';
|
|
58
|
+
|
|
59
|
+
interface User {
|
|
60
|
+
id: number;
|
|
61
|
+
name: string;
|
|
62
|
+
email: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function loadUsers({ pagination, filters, order, signal }: DataGridLoadContext) {
|
|
66
|
+
const response = await fetchUsers({
|
|
67
|
+
page: pagination?.page ?? 1,
|
|
68
|
+
limit: pagination?.limit ?? 12,
|
|
69
|
+
search: filters?.textSearch?.value,
|
|
70
|
+
sort: order?.[0],
|
|
71
|
+
signal,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return { results: response.users, total: response.total };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const columns: DataGridTableColumn<User>[] = [
|
|
78
|
+
{ id: 'name', label: 'Name' },
|
|
79
|
+
{ id: 'email', label: 'Email' },
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
function UsersPage() {
|
|
83
|
+
return (
|
|
84
|
+
<DataGrid<User> name="users" load={loadUsers} columns={columns} persistent="localStorage">
|
|
85
|
+
<DataGridTextSearchPlugin />
|
|
86
|
+
<DataGridOrderPlugin />
|
|
87
|
+
<DataGridPaginationPlugin defaultLimit={12} limits={[12, 24, 48]} />
|
|
88
|
+
</DataGrid>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`columns` and `implicitFilterKeys` must keep their identity between renders (a
|
|
94
|
+
module-level constant, or `useMemo`): a new array each render is read as a
|
|
95
|
+
change and recomputes the grid's derived state. The built-in plugins compare
|
|
96
|
+
their own array props by content, so an inline `limits` or `options` is fine; a
|
|
97
|
+
plugin you write compares by reference unless you give it `propsAreEqual`.
|
|
98
|
+
|
|
99
|
+
## The `load` contract
|
|
100
|
+
|
|
101
|
+
`DataGrid` calls `load` once on mount and again whenever a plugin asks for a
|
|
102
|
+
reload (a page change, a search, a sort). It hands it a `DataGridLoadContext`, which the
|
|
103
|
+
plugins fill in, and expects a `DataGridLoadResult`.
|
|
104
|
+
|
|
105
|
+
| `DataGridLoadContext` field | Set by | Shape |
|
|
106
|
+
|---------------------|--------|-------|
|
|
107
|
+
| `pagination` | pagination plugin | `{ page: number; limit: number }`, page is 1-based |
|
|
108
|
+
| `filters` | text search plugin, and any plugin that registers one | `Record<string, { value, ... }>` keyed by filter key; text search writes `filters.textSearch` |
|
|
109
|
+
| `order` | order plugin | `{ column: string; direction: 'asc' \| 'desc' }[]`, absent when nothing is sorted |
|
|
110
|
+
| `signal` | the grid | an `AbortSignal`, aborted when a refresh replaces the load or the grid unmounts |
|
|
111
|
+
|
|
112
|
+
`DataGridLoadResult` is `{ results: TItem[]; total?: number }`. `total` is what the pager
|
|
113
|
+
counts; leave it out and the pager shows one page. A result without `results` is a
|
|
114
|
+
failed load, not an empty grid.
|
|
115
|
+
|
|
116
|
+
A plugin is not wired to your backend: it contributes to the context, and your
|
|
117
|
+
`load` has to read it (`filters.textSearch?.value`, `order?.[0]`).
|
|
118
|
+
|
|
119
|
+
If the first load fails, the grid shows an error view in place of itself and
|
|
120
|
+
logs the error to the console in development. It has no retry and a failed first
|
|
121
|
+
load stays failed; a failed later load has no UI of its own. Handle failures you
|
|
122
|
+
want shown inside `load`.
|
|
123
|
+
|
|
124
|
+
## Columns
|
|
125
|
+
|
|
126
|
+
Each entry of `columns` is a `DataGridTableColumn`, or a `DataGridTableGroup` holding columns
|
|
127
|
+
under a spanning header cell.
|
|
128
|
+
|
|
129
|
+
| Field | Type | Notes |
|
|
130
|
+
|-------|------|-------|
|
|
131
|
+
| `id` | `string` | Required, **snake_case** (`user_name`). Checked when the columns arrive and throws otherwise: ids travel into plugins, storage and analytics. |
|
|
132
|
+
| `key` | `string` | The item field to show. Defaults to `id`; a dotted path (`owner.name`) reads nested values. |
|
|
133
|
+
| `label` | `string \| () => string` | Header text. A function is called on every render, for a label that changes with locale. |
|
|
134
|
+
| `render` | `(item) => ReactNode \| ReactNode` | Cell content. Wins over `component` and `key`. |
|
|
135
|
+
| `component` | `ComponentType<{ item, column, value }>` | Cell component. |
|
|
136
|
+
| `formatter` | `(value) => string` | Formats the value when neither `render` nor `component` is set. |
|
|
137
|
+
| `headerComponent` | `ComponentType<{ column }>` | Replaces the header label (for example a select-all checkbox). |
|
|
138
|
+
| `width` | `number \| string \| 'min-content'` | See "Choosing column widths". |
|
|
139
|
+
| `minWidth`, `maxWidth` | `number` | Pixels. Independent floor and cap under `tableLayout="auto"`. |
|
|
140
|
+
| `headerOverflow` | `'nowrap' \| 'wrap'` | Default `'nowrap'`: one line, clipped with an ellipsis, the label in `title`. |
|
|
141
|
+
| `cellOverflow` | `'wrap' \| 'nowrap'` | Default `'wrap'`. `'nowrap'` clips with an ellipsis and sets `title` to the value. |
|
|
142
|
+
| `sticky` | `boolean` | Pins the column to the inline-start edge while the table scrolls sideways. |
|
|
143
|
+
| `visible` | `boolean` | Initial visibility. |
|
|
144
|
+
| `visibleToggleDisabled` | `boolean` | The column's visibility is not the user's to change. |
|
|
145
|
+
| `getClassName` | `(item) => string \| undefined` | A class for the column's cell in that row. |
|
|
146
|
+
| `type` | `'string' \| 'number' \| 'date'` | Declared on the type; nothing in the grid reads it yet (the order plugin's option `type` is what names the directions). |
|
|
147
|
+
| `groupId` | `string` | Set by the grid on columns inside a `DataGridTableGroup`; do not set it. |
|
|
148
|
+
|
|
149
|
+
A `DataGridTableGroup` is `{ id, label, columns, component?, visible?, sticky? }`; a
|
|
150
|
+
group's `sticky` pins all its columns. Pin a group as a whole or none of its
|
|
151
|
+
columns: a column pinned or unpinned on its own inside a group moves in the body
|
|
152
|
+
but not under the group's header, so the header labels stop matching their
|
|
153
|
+
columns (see "Known limitations").
|
|
154
|
+
|
|
155
|
+
Pass a component to a column as its own module-level component, not an inline
|
|
156
|
+
function: an inline component is a new component on every render and loses its
|
|
157
|
+
state.
|
|
158
|
+
|
|
159
|
+
### `tableLayout`
|
|
160
|
+
|
|
161
|
+
`'fixed'` (the default) shares one weighted track between the columns, computed
|
|
162
|
+
from the header row, so content never changes an already-rendered column's width.
|
|
163
|
+
`'auto'` sizes columns to their content, with `minWidth` and `maxWidth` as
|
|
164
|
+
independent floor and cap. This is the table's CSS `table-layout`, unrelated to
|
|
165
|
+
the slot layout below.
|
|
166
|
+
|
|
167
|
+
In both modes the table never shrinks below its content's natural width
|
|
168
|
+
(`min-inline-size: max-content`), so a grid with many columns scrolls sideways
|
|
169
|
+
rather than squeezing every column; the floor is adjustable (see "CSS
|
|
170
|
+
customization").
|
|
171
|
+
|
|
172
|
+
Under `'fixed'` the three width props collapse into one track: a lone `width`,
|
|
173
|
+
`minWidth` or `maxWidth` is the track, and combining them logs a development-only
|
|
174
|
+
warning (`width` wins). Under `'auto'`, if every column has a `width` or
|
|
175
|
+
`maxWidth` and the container is wider than their sum, the browser grows them all
|
|
176
|
+
past their caps and capped columns show trailing blank space; leave at least one
|
|
177
|
+
column unconstrained to absorb the slack (a development-only warning says so).
|
|
178
|
+
|
|
179
|
+
### Choosing column widths
|
|
180
|
+
|
|
181
|
+
1. Start from `tableLayout="fixed"`: it fills the container and keeps widths
|
|
182
|
+
stable when the page content changes.
|
|
183
|
+
2. Classify each column. Long variable text (titles, descriptions) should grow.
|
|
184
|
+
Bounded variable content (dates, statuses, ids) has a known range. Fixed-shape
|
|
185
|
+
content (action buttons, avatars, checkboxes) is always the same width. Names
|
|
186
|
+
look like long text but behave like bounded content.
|
|
187
|
+
3. Give long text no `width` so it absorbs the slack, bounded content a pixel
|
|
188
|
+
`width` sized to its widest value plus padding, and fixed-shape content
|
|
189
|
+
`width: 'min-content'` when the header defines the width (a pixel `width` when
|
|
190
|
+
the body is wider than the header).
|
|
191
|
+
4. Route the slack on purpose. Under `'fixed'` a track holds only while at least
|
|
192
|
+
one column stays flexible; give every column a `width` and they all stretch in
|
|
193
|
+
proportion. Several long-text columns share the slack evenly when none has a
|
|
194
|
+
`width`. Extra columns a plugin adds with no width are flexible too.
|
|
195
|
+
5. A flexible column in a narrow container can collapse to a word per line; a
|
|
196
|
+
definite track (a `width`, or a lone `minWidth`) gives it a floor while the
|
|
197
|
+
table scrolls around it. If the grid only starves in a narrow pane, raise the
|
|
198
|
+
table's floor with `--data-grid-table-min-inline-size` and leave the columns
|
|
199
|
+
alone.
|
|
200
|
+
6. Bodies default to `'wrap'` and headers to `'nowrap'`. Do not truncate
|
|
201
|
+
identifier or code columns: they must stay readable and copyable in full.
|
|
202
|
+
7. Reach for `tableLayout="auto"` only when a grid must shrink to its content or
|
|
203
|
+
needs caps `'fixed'` cannot express.
|
|
204
|
+
|
|
205
|
+
Give peer columns of one type (two date columns) one identical width, so one does
|
|
206
|
+
not wrap while its twin does.
|
|
207
|
+
|
|
208
|
+
### `stickyHeader`
|
|
209
|
+
|
|
210
|
+
`stickyHeader` pins the header row to the top of the grid's scroll area while the
|
|
211
|
+
rows scroll under it, with the cells on an opaque fill. Pinned columns keep
|
|
212
|
+
working, and the corner cells stick on both axes. With column groups both header
|
|
213
|
+
rows stay pinned.
|
|
214
|
+
|
|
215
|
+
It only takes effect when the surrounding layout bounds the grid's height, so
|
|
216
|
+
that the grid scrolls internally: every ancestor between an element with a
|
|
217
|
+
definite height and the grid must be a flex column that may shrink. On a grid
|
|
218
|
+
that grows to its content the header scrolls away with the rows.
|
|
219
|
+
|
|
220
|
+
```css
|
|
221
|
+
.grid-host {
|
|
222
|
+
display: flex;
|
|
223
|
+
flex: 1 1 0;
|
|
224
|
+
flex-direction: column;
|
|
225
|
+
min-block-size: 0;
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
The header fill is `--card`; set `--data-grid-header-background` to change it.
|
|
230
|
+
|
|
231
|
+
## Loading
|
|
232
|
+
|
|
233
|
+
While a load is in flight the grid is dimmed behind a scrim with a spinner
|
|
234
|
+
centered over it. The rows stay on screen underneath, so the grid keeps its shape
|
|
235
|
+
and scroll position, but they read as stale. The scrim covers the grid's own
|
|
236
|
+
regions - toolbar, rows and pagination - and takes the pointer events over them.
|
|
237
|
+
The first load is the exception: there is nothing to cover yet, so the grid shows
|
|
238
|
+
a centered spinner in its place.
|
|
239
|
+
|
|
240
|
+
The scrim and the spinner fade in after a short delay, so a load that settles
|
|
241
|
+
quickly shows nothing, and the content region carries `aria-busy="true"` while
|
|
242
|
+
either is on screen. The block is pointer-only: the covered controls stay in the tab
|
|
243
|
+
order and activatable from the keyboard.
|
|
244
|
+
|
|
245
|
+
Loads that only add to the grid (and so do not replace what you are looking at)
|
|
246
|
+
leave it alone.
|
|
247
|
+
|
|
248
|
+
### `loading`
|
|
249
|
+
|
|
250
|
+
Use `loading` for work the grid never reloads for, such as a bulk copy started
|
|
251
|
+
elsewhere:
|
|
252
|
+
|
|
253
|
+
```tsx
|
|
254
|
+
<DataGrid name="terms" load={loadTerms} columns={columns} loading={isCopying} />
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Hold the flag on the screen that renders the grid rather than inside the thing
|
|
258
|
+
that started the work, so the overlay survives that thing going away. It is OR-ed
|
|
259
|
+
with the grid's own loads, and there is no imperative equivalent.
|
|
260
|
+
|
|
261
|
+
## Empty state
|
|
262
|
+
|
|
263
|
+
A grid with no records shows a centered `Empty` instead of the table: "No results
|
|
264
|
+
found", with a "Try adjusting your search or filters" line when a filter is
|
|
265
|
+
applied (`hasActiveFilters`). To replace it, use `DataGridEmptyStatePlugin`.
|
|
266
|
+
|
|
267
|
+
### `implicitFilterKeys`
|
|
268
|
+
|
|
269
|
+
`hasActiveFilters` counts every filter key in the load context, including filters
|
|
270
|
+
the grid always sends on its own (a tenant or team taken from outside it). List
|
|
271
|
+
those keys to keep them out of the count, so an empty grid reaches its unfiltered
|
|
272
|
+
empty state:
|
|
273
|
+
|
|
274
|
+
```tsx
|
|
275
|
+
const IMPLICIT_KEYS = ['teamId'];
|
|
276
|
+
|
|
277
|
+
<DataGrid name="users" load={loadUsers} columns={columns} implicitFilterKeys={IMPLICIT_KEYS} />;
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
Only for filters with no control in the grid to clear them: a key the user can
|
|
281
|
+
clear belongs nowhere near this list, or they are stranded on an unfiltered empty
|
|
282
|
+
state with a filter still applied. The array must be referentially stable.
|
|
283
|
+
|
|
284
|
+
## Layout slots
|
|
285
|
+
|
|
286
|
+
The grid lays itself out in named slots, and plugins register components into
|
|
287
|
+
them with `registerSlot(name, { id, component, order? })`:
|
|
288
|
+
|
|
289
|
+
| Slot | Where |
|
|
290
|
+
|------|-------|
|
|
291
|
+
| `top-start` | Left of the toolbar (search, filters) |
|
|
292
|
+
| `top` | The whole toolbar row, replacing the two halves when its `active` option is set |
|
|
293
|
+
| `top-end` | Right of the toolbar (order button, actions) |
|
|
294
|
+
| `main` | The primary content: the table view is the default one |
|
|
295
|
+
| `bottom` | The footer (pagination); hidden while the grid has no records |
|
|
296
|
+
| `empty` | Replaces the built-in empty state |
|
|
297
|
+
|
|
298
|
+
With two or more `main` views (for example the table and a cards view) the grid
|
|
299
|
+
adds a view switch to `top-end` by itself. Read or set the active view with
|
|
300
|
+
`useDataGridActiveView()` and `DATA_GRID_VIEW`:
|
|
301
|
+
|
|
302
|
+
```tsx
|
|
303
|
+
const view = useDataGridActiveView(); // 'table_layout' | 'cards_layout' | undefined
|
|
304
|
+
grid.setActiveSlotId('main', DATA_GRID_VIEW.cards);
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
The `main` slot is hidden when the grid is empty and nothing is filtered, which is
|
|
308
|
+
why the empty state has a slot of its own.
|
|
309
|
+
|
|
310
|
+
## Persistence
|
|
311
|
+
|
|
312
|
+
`persistent` chooses where grid state (page and limit, search, order, and the
|
|
313
|
+
state of plugins that register any) is kept:
|
|
314
|
+
|
|
315
|
+
| Value | Where |
|
|
316
|
+
|-------|-------|
|
|
317
|
+
| `'localStorage'` (default) | Survives sessions |
|
|
318
|
+
| `'sessionStorage'` | Cleared when the tab closes |
|
|
319
|
+
| `'router'` | The URL query: `history.replaceState` on the current path, one query key per state |
|
|
320
|
+
| `'memory'` | Within one mount; a remount or reload starts clean |
|
|
321
|
+
|
|
322
|
+
Storage keys are `dataGrid:${name}:${key}`, with a JSON value, so a grid's `name`
|
|
323
|
+
is its identity: two grids with the same name on one page share state. A stored
|
|
324
|
+
value is user-editable (devtools, the address bar), so a value that is not valid
|
|
325
|
+
JSON reads as absent, and plugins narrow what they read.
|
|
326
|
+
|
|
327
|
+
Router mode writes the URL directly with bare keys, shared by every grid on the
|
|
328
|
+
page, and does not listen for `popstate`; a plugin can opt a state out of it
|
|
329
|
+
(`registerPersistentState(key, { router: false })`) or send one state to another
|
|
330
|
+
backend (`{ storage: 'localStorage' }`).
|
|
331
|
+
|
|
332
|
+
`persistentColumnVisibility` remembers which columns the user showed or hid, in
|
|
333
|
+
`localStorage` whatever `persistent` says. The grid ships no control that changes
|
|
334
|
+
it; a plugin of your own calls `updateColumnVisibility`.
|
|
335
|
+
|
|
336
|
+
## Plugins
|
|
337
|
+
|
|
338
|
+
Plugins are children of `DataGrid`. They render nothing themselves: each one
|
|
339
|
+
registers its UI into a slot and its behavior into the load, once, when it mounts.
|
|
340
|
+
|
|
341
|
+
### `DataGridPaginationPlugin`
|
|
342
|
+
|
|
343
|
+
Draws a pager in the `bottom` slot and fills `DataGridLoadContext.pagination`.
|
|
344
|
+
|
|
345
|
+
| Prop | Type | Default |
|
|
346
|
+
|------|------|---------|
|
|
347
|
+
| `defaultLimit` | `number` | `12` |
|
|
348
|
+
| `limits` | `number[]` | `[12, 24, 48, 96]`; the page-size selector appears with more than one |
|
|
349
|
+
| `autoHide` | `boolean` | `false`; hides the pager when everything fits the smallest limit |
|
|
350
|
+
|
|
351
|
+
A page change updates the page, stores it and reloads. A limit change goes back to
|
|
352
|
+
page 1, stores the limit and reloads. A refresh resets the page to 1. The page
|
|
353
|
+
count comes from `total`. The loading treatment is the grid's, not the pager's.
|
|
354
|
+
|
|
355
|
+
### `DataGridTextSearchPlugin`
|
|
356
|
+
|
|
357
|
+
Draws a search box in `top-start` and contributes the query to the load as
|
|
358
|
+
`filters[filterKey] = { value }` (default key `textSearch`); your `load` reads it.
|
|
359
|
+
|
|
360
|
+
| Prop | Type | Default |
|
|
361
|
+
|------|------|---------|
|
|
362
|
+
| `filterKey` | `string` | `'textSearch'` |
|
|
363
|
+
| `placeholder` | `string` | `Search...` |
|
|
364
|
+
| `fullWidth` | `boolean` | `false`; stretches across the free `top-start` space |
|
|
365
|
+
|
|
366
|
+
Typing shows at once and reloads 300 ms after the user stops. The clear button
|
|
367
|
+
cancels a pending reload, reloads immediately with no query, and keeps focus in
|
|
368
|
+
the field. A refresh that resets filters empties the box. Its API
|
|
369
|
+
(`getPlugin<DataGridTextSearchPluginApi>('textSearch')`) offers `useQuery`,
|
|
370
|
+
`usePlaceholder`, `useFullWidth`, `setSearch` (immediate) and `updateSearch`
|
|
371
|
+
(debounced).
|
|
372
|
+
|
|
373
|
+
### `DataGridOrderPlugin`
|
|
374
|
+
|
|
375
|
+
Header sorting plus an optional toolbar button; fills `DataGridLoadContext.order`.
|
|
376
|
+
|
|
377
|
+
| Prop | Type | Notes |
|
|
378
|
+
|------|------|-------|
|
|
379
|
+
| `options` | `DataGridOrderOption[]` | `createDataGridOrderOption({ id, label, type? })`. With options the toolbar button appears in `top-end`; `type` (`'string'`, `'number'`, `'date'`) names the directions A-Z, 0-9 or Oldest first. |
|
|
380
|
+
| `excludedColumns` | `string[]` | No header sort control for these. A column in both `excludedColumns` and `options` is sortable from the button only. |
|
|
381
|
+
| `defaultOrder` | `{ id, direction }` | Applies when nothing usable is stored. It seeds an order, it does not keep governing one. |
|
|
382
|
+
| `popover` | `{ minInlineSize }` | Sizes the button's popover. |
|
|
383
|
+
|
|
384
|
+
A header label is a button: the first click sorts descending, the second
|
|
385
|
+
ascending, the third clears the sort (and keeps `defaultOrder` suppressed on
|
|
386
|
+
later visits). The sorted column shows a direction icon that advances the same
|
|
387
|
+
cycle. The toolbar button changes the column and the direction, and never clears.
|
|
388
|
+
The order is stored; one whose column is orderable nowhere (excluded and not
|
|
389
|
+
offered) is withheld rather than deleted, so it returns if the column is offered
|
|
390
|
+
again.
|
|
391
|
+
|
|
392
|
+
The plugin compares `options` and `excludedColumns` by content, so an inline
|
|
393
|
+
array does not count as a change.
|
|
394
|
+
|
|
395
|
+
### `DataGridEmptyStatePlugin`
|
|
396
|
+
|
|
397
|
+
Renders your component in place of the built-in empty state, whenever the grid has
|
|
398
|
+
no records (it sits outside `main`, so it also renders for an empty grid with no
|
|
399
|
+
filters). Read `hasActiveFilters` from `useDataGrid()` inside it to tell "nothing
|
|
400
|
+
here yet" from "nothing matched".
|
|
401
|
+
|
|
402
|
+
```tsx
|
|
403
|
+
function UsersEmptyState() {
|
|
404
|
+
const { useStore } = useDataGrid();
|
|
405
|
+
const hasActiveFilters = useStore((s) => s.hasActiveFilters);
|
|
406
|
+
|
|
407
|
+
return (
|
|
408
|
+
<Empty>
|
|
409
|
+
<EmptyHeader>
|
|
410
|
+
<EmptyTitle>{hasActiveFilters ? 'No matching users' : 'No users yet'}</EmptyTitle>
|
|
411
|
+
</EmptyHeader>
|
|
412
|
+
</Empty>
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
<DataGrid name="users" load={loadUsers} columns={columns} implicitFilterKeys={IMPLICIT_KEYS}>
|
|
417
|
+
<DataGridEmptyStatePlugin component={UsersEmptyState} />
|
|
418
|
+
</DataGrid>;
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
## Custom plugins
|
|
422
|
+
|
|
423
|
+
`createDataGridPlugin(name, setup, propsAreEqual?)` returns a component to use as
|
|
424
|
+
a child of `DataGrid`. `setup` runs once, when it first mounts, with the plugin
|
|
425
|
+
context, and returns the plugin's API; the optional third argument is the
|
|
426
|
+
comparison `React.memo` uses for the props.
|
|
427
|
+
|
|
428
|
+
```tsx
|
|
429
|
+
import { createDataGridPlugin, useDataGrid, type DataGridPluginApi } from '@gears-frontx/ui-kit';
|
|
430
|
+
import { create } from 'zustand';
|
|
431
|
+
|
|
432
|
+
interface StatusApi extends DataGridPluginApi {
|
|
433
|
+
useStatus: () => string;
|
|
434
|
+
setStatus: (status: string) => void;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
function StatusFilter() {
|
|
438
|
+
const grid = useDataGrid();
|
|
439
|
+
const status = grid.getPlugin<StatusApi>('status')!;
|
|
440
|
+
return <Select value={status.useStatus()} onValueChange={status.setStatus} /* ... */ />;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
export const StatusPlugin = createDataGridPlugin<DataGridItem, 'status', Record<string, never>, StatusApi>(
|
|
444
|
+
'status',
|
|
445
|
+
(context) => {
|
|
446
|
+
const useStore = create(() => ({ status: '' }));
|
|
447
|
+
const persistent = context.registerPersistentState<{ status?: unknown }>('status');
|
|
448
|
+
|
|
449
|
+
// Storage is user-editable: narrow what you read.
|
|
450
|
+
const stored = persistent.value?.status;
|
|
451
|
+
if (typeof stored === 'string') useStore.setState({ status: stored });
|
|
452
|
+
|
|
453
|
+
context.registerSlot('top-start', { id: 'status', component: StatusFilter });
|
|
454
|
+
|
|
455
|
+
context.hook('load:context', () => {
|
|
456
|
+
const { status } = useStore.getState();
|
|
457
|
+
return status ? { filters: { status: { value: status } } } : undefined;
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
return {
|
|
461
|
+
useStatus: () => useStore((s) => s.status),
|
|
462
|
+
setStatus(status) {
|
|
463
|
+
useStore.setState({ status });
|
|
464
|
+
persistent.setValue(status ? { status } : undefined);
|
|
465
|
+
context.triggerLoad();
|
|
466
|
+
},
|
|
467
|
+
};
|
|
468
|
+
},
|
|
469
|
+
);
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
### The plugin context
|
|
473
|
+
|
|
474
|
+
| Area | Members |
|
|
475
|
+
|------|---------|
|
|
476
|
+
| Plugins | `hook(name, handler)`, `getPlugin<Api>(name)` |
|
|
477
|
+
| Layout | `registerSlot(name, options)`, `setActiveSlotId(name, id)`, `getActiveSlotId(name)` |
|
|
478
|
+
| Table | `registerTableSlot(name, options)` (`subheader`, `footer`, `header-cell-end`), `registerExtraColumn(options)`, `updateExtraColumnWidth` / `Order` / `Sticky`, `registerComponent(name, component)` (override `row`, `header-cell-label`, `body-cell-content` or `content`), `updateColumns`, `updateColumnVisibility`, `updateColumnSticky`, `updateTableLayout`, `updateStickyHeader` |
|
|
479
|
+
| Persistent state | `registerPersistentState(key, options?)` |
|
|
480
|
+
| Storage | `useStore(selector)` (`visibleRecords`, `rootSections`, `hasActiveFilters`, ...), `createSection`, `clearSections`, `getRecord`, `getItemId`, ... |
|
|
481
|
+
| Load | `triggerLoad(config?)`, `refresh(options?)`, `abort()`, `getLoadInstances()`, `useLoadStateStore` |
|
|
482
|
+
|
|
483
|
+
### Lifecycle hooks
|
|
484
|
+
|
|
485
|
+
| Hook | When |
|
|
486
|
+
|------|------|
|
|
487
|
+
| `init`, `destroy` | The grid mounts, and unmounts (release observers, timers and subscriptions here) |
|
|
488
|
+
| `load:prepare` | Before a load starts |
|
|
489
|
+
| `load:context` | Return a partial `DataGridLoadContext` to merge into this load: `pagination`, `filters`, `order` |
|
|
490
|
+
| `load:process` | Return a replacement `DataGridLoadResult` before it is stored |
|
|
491
|
+
| `load:store` | After the result is stored; read `instance.processResult.total`. Return `true` to claim the storing |
|
|
492
|
+
| `load:success`, `load:error` | The load settled |
|
|
493
|
+
| `refresh` | `refresh()` was called; the options say whether filters reset |
|
|
494
|
+
|
|
495
|
+
### Conventions
|
|
496
|
+
|
|
497
|
+
- `registerSlot`, `registerTableSlot` and `registerExtraColumn` append: call them
|
|
498
|
+
in `setup`, not in `onPropsChange`, which runs on every props change.
|
|
499
|
+
- `onPropsChange(props)` mirrors props into stores. Gate each optional prop with
|
|
500
|
+
`!== undefined` when you collect updates, or the guard is always true.
|
|
501
|
+
- Call `triggerLoad()` or `refresh()` from user actions, not from a global store
|
|
502
|
+
`subscribe`, which fires during initialization and adds loads on top of the
|
|
503
|
+
first. `triggerLoad` queues a load; `refresh` aborts the loads already in flight
|
|
504
|
+
before it starts its own, but two `refresh()` calls in the same tick both load
|
|
505
|
+
(see Known limitations).
|
|
506
|
+
- Functions that build plugin infrastructure but are not React hooks do not use
|
|
507
|
+
the `use` prefix.
|
|
508
|
+
- Do not import from another plugin's internals; share a utility through the
|
|
509
|
+
grid's services.
|
|
510
|
+
|
|
511
|
+
## Hooks
|
|
512
|
+
|
|
513
|
+
| Hook | Returns |
|
|
514
|
+
|------|---------|
|
|
515
|
+
| `useDataGrid<TItem>()` | The grid instance, inside a `DataGrid`: `getPlugin`, `useStore`, `triggerLoad`, `refresh`, `setActiveSlotId`, ... |
|
|
516
|
+
| `useDataGridPluginContext<TItem>()` | The plugin context above, for a component that needs it directly |
|
|
517
|
+
| `useDataGridRecord<TItem>()` | The record of the row being rendered, inside a cell or row component |
|
|
518
|
+
| `useDataGridActiveView()` | The id of the active `main` view |
|
|
519
|
+
|
|
520
|
+
## CSS customization
|
|
521
|
+
|
|
522
|
+
Set these on the grid or any ancestor:
|
|
523
|
+
|
|
524
|
+
| Variable | Default | Description |
|
|
525
|
+
|----------|---------|-------------|
|
|
526
|
+
| `--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. |
|
|
527
|
+
| `--data-grid-header-background` | `var(--card)` | Fill of the header cells while `stickyHeader` is on |
|
|
528
|
+
| `--data-grid-text-search-inline-size` | `initial` | Width of the search box; a fixed value stops it shifting as the clear button appears |
|
|
529
|
+
|
|
530
|
+
The floor is one constraint among several: under `'fixed'` a table whose columns
|
|
531
|
+
declare widths cannot shrink below their sum, and under either mode not below the
|
|
532
|
+
columns' minimum content widths.
|
|
533
|
+
|
|
534
|
+
## Accessibility
|
|
535
|
+
|
|
536
|
+
- The header label of an orderable column is a native `button` named "Change
|
|
537
|
+
sorting of '<column>' column"; Enter and Space sort. There is no `aria-sort`.
|
|
538
|
+
- The table's scroll container is a tab stop (it holds `tabIndex=0` so a keyboard
|
|
539
|
+
can scroll it).
|
|
540
|
+
- The pager is a `nav` named "Pagination"; the page buttons are named "Go to page
|
|
541
|
+
N" and carry `aria-current="page"` on the current one.
|
|
542
|
+
- `aria-busy` is set on the content region while a loader is on screen.
|
|
543
|
+
- The order popover's items are menu items without a menu popup, so they take
|
|
544
|
+
focus and Enter and Space, but arrow keys do not move between them.
|
|
545
|
+
- Strings are English and live in one module; the kit has no i18n layer yet.
|
|
546
|
+
|
|
547
|
+
## Known limitations
|
|
548
|
+
|
|
549
|
+
- Data loading has no stale-response guard: `triggerLoad` neither aborts the load
|
|
550
|
+
in flight nor ignores a late result, so when two loads overlap (two quick page
|
|
551
|
+
clicks, a page-size change, a refresh over a page change, two `refresh()` calls
|
|
552
|
+
in the same tick) the older result can replace the newer one. A `load` that
|
|
553
|
+
ignores `signal` is not protected even by the abort `refresh()` sends. `refresh()` also defaults to `resetFilters: true`.
|
|
554
|
+
- Changing the page size from a later page fires two loads.
|
|
555
|
+
- `abort()` counts as the grid's own abort. Called during the first load, or during
|
|
556
|
+
the refresh the first load waits on, it ends the first load with nothing loaded:
|
|
557
|
+
the grid shows "No results found" and loads nothing more. A superseded
|
|
558
|
+
`refresh()` resolves without its data, so a caller cannot tell it was superseded.
|
|
559
|
+
- A failed first load has no retry; a failed refetch has no UI, and when search or
|
|
560
|
+
sort started it, the failure also reaches the host as an unhandled rejection.
|
|
561
|
+
- A search still waiting out its debounce when the grid unmounts is flushed: its
|
|
562
|
+
refresh runs after the grid is gone, and its load's `signal` is not aborted.
|
|
563
|
+
- The loading overlay blocks the pointer only, not the keyboard.
|
|
564
|
+
- No `aria-sort`; Previous and Next drop keyboard focus at the ends of the range.
|
|
565
|
+
- Renderer overrides (`registerComponent`) are last registered wins.
|
|
566
|
+
- `registerComponent` accepts `'header-cell'` and `'header-group'`, but the header
|
|
567
|
+
always renders its own cell and group components, so those two overrides have no
|
|
568
|
+
effect.
|
|
569
|
+
- A column pinned on its own inside a group, or a pinned group with one column
|
|
570
|
+
unpinned, moves in the body but not under the group's header, so the header
|
|
571
|
+
labels sit over the wrong columns. Pin a group as a whole.
|
|
572
|
+
- Router persistence shares bare keys across grids and does not follow `popstate`;
|
|
573
|
+
it also drops `history.state` and the `#hash` when it writes the URL, and it does
|
|
574
|
+
not work during server rendering.
|
|
575
|
+
- A new `columns` array identity resets user pins and visibility.
|
|
576
|
+
- There is no plugin unregister.
|
|
577
|
+
|
|
578
|
+
## Anti-patterns
|
|
579
|
+
|
|
580
|
+
- Do not define a column's cell component inline in `render`: it is a new
|
|
581
|
+
component each render.
|
|
582
|
+
- Do not leave `columns`, `options` or `excludedColumns` as inline literals that
|
|
583
|
+
change identity every render.
|
|
584
|
+
- Do not use `camelCase` column ids; they must be snake_case.
|
|
585
|
+
- Do not put a key that the user can clear in `implicitFilterKeys`.
|
|
586
|
+
- Do not reach into the grid's markup from a consumer stylesheet; use the CSS
|
|
587
|
+
variables above.
|
|
588
|
+
- Do not trigger loads from a store `subscribe` in a plugin.
|