@gears-frontx/ui-kit 0.4.6 → 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.
Files changed (118) hide show
  1. package/dist/chunks/{data-grid.-6P4UQGJ.css → data-grid.DSkYrsay.css} +1 -1
  2. package/dist/chunks/drag-drop.BASVe3_O.css +1 -0
  3. package/dist/chunks/hooked.js +23 -31
  4. package/dist/chunks/hooked.js.map +1 -1
  5. package/dist/chunks/is-record.js +7 -0
  6. package/dist/chunks/is-record.js.map +1 -0
  7. package/dist/chunks/messages.js +12 -1
  8. package/dist/chunks/messages.js.map +1 -1
  9. package/dist/chunks/pagination.DJ7HJSFX.css +1 -0
  10. package/dist/chunks/resolve-body-cell-props.BA5IRWq0.css +1 -0
  11. package/dist/chunks/resolve-body-cell-props.js +80 -96
  12. package/dist/chunks/resolve-body-cell-props.js.map +1 -1
  13. package/dist/chunks/row-click-utils.js +12 -0
  14. package/dist/chunks/row-click-utils.js.map +1 -0
  15. package/dist/chunks/row-number.BxFT_3yP.css +1 -0
  16. package/dist/chunks/segment.js +16 -9
  17. package/dist/chunks/segment.js.map +1 -1
  18. package/dist/chunks/storage-helpers.js +40 -0
  19. package/dist/chunks/storage-helpers.js.map +1 -0
  20. package/dist/chunks/table-helpers.js +20 -0
  21. package/dist/chunks/table-helpers.js.map +1 -0
  22. package/dist/chunks/table-tree.DMtpMddS.css +1 -0
  23. package/dist/chunks/table.biUlW2U6.css +1 -0
  24. package/dist/chunks/use-latest.js +11 -0
  25. package/dist/chunks/use-latest.js.map +1 -0
  26. package/dist/components/data-grid/data-grid-types.d.ts +9 -0
  27. package/dist/components/data-grid/data-grid-types.d.ts.map +1 -1
  28. package/dist/components/data-grid/data-grid.d.ts +1 -1
  29. package/dist/components/data-grid/data-grid.d.ts.map +1 -1
  30. package/dist/components/data-grid/messages.d.ts +9 -0
  31. package/dist/components/data-grid/messages.d.ts.map +1 -1
  32. package/dist/components/data-grid/plugins/actions-menu/menu-items/export-menu-items/data-grid-export-menu-item.d.ts +6 -0
  33. package/dist/components/data-grid/plugins/actions-menu/menu-items/export-menu-items/data-grid-export-menu-item.d.ts.map +1 -0
  34. package/dist/components/data-grid/plugins/actions-menu/menu-items/export-menu-items/export-cells.d.ts +18 -0
  35. package/dist/components/data-grid/plugins/actions-menu/menu-items/export-menu-items/export-cells.d.ts.map +1 -0
  36. package/dist/components/data-grid/plugins/actions-menu/menu-items/export-menu-items/export-menu-items.d.ts +9 -0
  37. package/dist/components/data-grid/plugins/actions-menu/menu-items/export-menu-items/export-menu-items.d.ts.map +1 -0
  38. package/dist/components/data-grid/plugins/actions-menu/menu-items/export-menu-items/export-service.d.ts +5 -0
  39. package/dist/components/data-grid/plugins/actions-menu/menu-items/export-menu-items/export-service.d.ts.map +1 -0
  40. package/dist/components/data-grid/plugins/actions-menu/menu-items/export-menu-items/export-types.d.ts +77 -0
  41. package/dist/components/data-grid/plugins/actions-menu/menu-items/export-menu-items/export-types.d.ts.map +1 -0
  42. package/dist/components/data-grid/plugins/actions-menu/menu-items/export-menu-items/formatters/csv-formatter.d.ts +3 -0
  43. package/dist/components/data-grid/plugins/actions-menu/menu-items/export-menu-items/formatters/csv-formatter.d.ts.map +1 -0
  44. package/dist/components/data-grid/plugins/actions-menu/menu-items/export-menu-items/formatters/excel-formatter.d.ts +4 -0
  45. package/dist/components/data-grid/plugins/actions-menu/menu-items/export-menu-items/formatters/excel-formatter.d.ts.map +1 -0
  46. package/dist/components/data-grid/plugins/actions-menu/public.d.ts +2 -0
  47. package/dist/components/data-grid/plugins/actions-menu/public.d.ts.map +1 -1
  48. package/dist/components/data-grid/plugins/drag-drop/components/data-grid-drag-drop-body-cell.d.ts +3 -0
  49. package/dist/components/data-grid/plugins/drag-drop/components/data-grid-drag-drop-body-cell.d.ts.map +1 -0
  50. package/dist/components/data-grid/plugins/drag-drop/components/data-grid-drag-drop-content.d.ts +7 -0
  51. package/dist/components/data-grid/plugins/drag-drop/components/data-grid-drag-drop-content.d.ts.map +1 -0
  52. package/dist/components/data-grid/plugins/drag-drop/components/data-grid-drag-drop-row.d.ts +8 -0
  53. package/dist/components/data-grid/plugins/drag-drop/components/data-grid-drag-drop-row.d.ts.map +1 -0
  54. package/dist/components/data-grid/plugins/drag-drop/drag-data.d.ts +4 -0
  55. package/dist/components/data-grid/plugins/drag-drop/drag-data.d.ts.map +1 -0
  56. package/dist/components/data-grid/plugins/drag-drop/drag-drop-plugin.d.ts +18 -0
  57. package/dist/components/data-grid/plugins/drag-drop/drag-drop-plugin.d.ts.map +1 -0
  58. package/dist/components/data-grid/plugins/drag-drop/drag-drop-types.d.ts +60 -0
  59. package/dist/components/data-grid/plugins/drag-drop/drag-drop-types.d.ts.map +1 -0
  60. package/dist/components/data-grid/plugins/drag-drop/drag-preview.d.ts +2 -0
  61. package/dist/components/data-grid/plugins/drag-drop/drag-preview.d.ts.map +1 -0
  62. package/dist/components/data-grid/plugins/drag-drop/public.d.ts +3 -0
  63. package/dist/components/data-grid/plugins/drag-drop/public.d.ts.map +1 -0
  64. package/dist/components/data-grid/plugins/pagination/components/data-grid-pagination.d.ts.map +1 -1
  65. package/dist/components/data-grid/plugins/pagination/components/pager.d.ts +6 -0
  66. package/dist/components/data-grid/plugins/pagination/components/pager.d.ts.map +1 -1
  67. package/dist/components/data-grid/plugins/table-tree/components/data-grid-table-tree-body-cell-content.d.ts +9 -0
  68. package/dist/components/data-grid/plugins/table-tree/components/data-grid-table-tree-body-cell-content.d.ts.map +1 -0
  69. package/dist/components/data-grid/plugins/table-tree/components/data-grid-table-tree-expand.d.ts +3 -0
  70. package/dist/components/data-grid/plugins/table-tree/components/data-grid-table-tree-expand.d.ts.map +1 -0
  71. package/dist/components/data-grid/plugins/table-tree/components/data-grid-table-tree-row.d.ts +8 -0
  72. package/dist/components/data-grid/plugins/table-tree/components/data-grid-table-tree-row.d.ts.map +1 -0
  73. package/dist/components/data-grid/plugins/table-tree/public.d.ts +3 -0
  74. package/dist/components/data-grid/plugins/table-tree/public.d.ts.map +1 -0
  75. package/dist/components/data-grid/plugins/table-tree/table-tree-helpers.d.ts +4 -0
  76. package/dist/components/data-grid/plugins/table-tree/table-tree-helpers.d.ts.map +1 -0
  77. package/dist/components/data-grid/plugins/table-tree/table-tree-plugin.d.ts +5 -0
  78. package/dist/components/data-grid/plugins/table-tree/table-tree-plugin.d.ts.map +1 -0
  79. package/dist/components/data-grid/plugins/table-tree/table-tree-types.d.ts +33 -0
  80. package/dist/components/data-grid/plugins/table-tree/table-tree-types.d.ts.map +1 -0
  81. package/dist/components/data-grid/services/core/data-grid-label-context.d.ts +7 -0
  82. package/dist/components/data-grid/services/core/data-grid-label-context.d.ts.map +1 -0
  83. package/dist/components/data-grid/services/table/components/data-grid-table.d.ts.map +1 -1
  84. package/dist/components/pagination/pagination.d.ts +7 -4
  85. package/dist/components/pagination/pagination.d.ts.map +1 -1
  86. package/dist/data-grid/actions-menu.js +349 -33
  87. package/dist/data-grid/actions-menu.js.map +1 -1
  88. package/dist/data-grid/drag-drop.d.ts +1 -0
  89. package/dist/data-grid/drag-drop.js +261 -0
  90. package/dist/data-grid/drag-drop.js.map +1 -0
  91. package/dist/data-grid/filters.js +22 -21
  92. package/dist/data-grid/filters.js.map +1 -1
  93. package/dist/data-grid/pagination.js +152 -143
  94. package/dist/data-grid/pagination.js.map +1 -1
  95. package/dist/data-grid/row-click.js +35 -42
  96. package/dist/data-grid/row-click.js.map +1 -1
  97. package/dist/data-grid/row-number.js +6 -6
  98. package/dist/data-grid/table-tree.d.ts +1 -0
  99. package/dist/data-grid/table-tree.js +233 -0
  100. package/dist/data-grid/table-tree.js.map +1 -0
  101. package/dist/data-grid.js +508 -536
  102. package/dist/data-grid.js.map +1 -1
  103. package/dist/docs/data-grid.md +280 -7
  104. package/dist/docs/pagination.md +14 -0
  105. package/dist/docs/table.md +10 -1
  106. package/dist/index.d.ts +2 -0
  107. package/dist/index.d.ts.map +1 -1
  108. package/dist/index.js +375 -370
  109. package/dist/index.js.map +1 -1
  110. package/dist/pagination.js +23 -23
  111. package/dist/pagination.js.map +1 -1
  112. package/dist/table.js +88 -88
  113. package/llms.txt +6 -3
  114. package/package.json +10 -1
  115. package/dist/chunks/pagination.CKDEuWt6.css +0 -1
  116. package/dist/chunks/resolve-body-cell-props.DGczzk1U.css +0 -1
  117. package/dist/chunks/row-number.C7fNu9Bw.css +0 -1
  118. package/dist/chunks/table.Dmz7LEk7.css +0 -1
@@ -8,8 +8,8 @@ custom empty state) by registering into those slots and hooking the load. Each c
8
8
  a plugin reaches all of them through one context object.
9
9
 
10
10
  Built-in plugins: pagination, text search, order, filters, empty state, row number, row
11
- click, actions, row actions, an actions menu, table configuration and row select, each its
12
- own entry (see below).
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).
13
13
 
14
14
  ## When to use
15
15
 
@@ -42,9 +42,11 @@ code or CSS:
42
42
  | `@gears-frontx/ui-kit/data-grid/row-click` | `DataGridRowClickPlugin` |
43
43
  | `@gears-frontx/ui-kit/data-grid/actions` | `DataGridActionsPlugin` |
44
44
  | `@gears-frontx/ui-kit/data-grid/row-actions` | `DataGridRowActionsPlugin` |
45
- | `@gears-frontx/ui-kit/data-grid/actions-menu` | `DataGridActionsMenuPlugin` |
45
+ | `@gears-frontx/ui-kit/data-grid/actions-menu` | `DataGridActionsMenuPlugin`, `exportMenuItems` (the menu items that export the rows) and the types |
46
46
  | `@gears-frontx/ui-kit/data-grid/table-configuration` | `DataGridTableConfigurationPlugin` |
47
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 |
48
50
 
49
51
  The package root re-exports all of them, so
50
52
  `import { DataGrid, DataGridPaginationPlugin } from '@gears-frontx/ui-kit'`
@@ -116,6 +118,7 @@ plugins fill in, and expects a `DataGridLoadResult`.
116
118
  | `pagination` | pagination plugin | `{ page: number; limit: number }`, page is 1-based |
117
119
  | `filters` | text search plugin, and any plugin that registers one | `Record<string, { value, ... }>` keyed by filter key; text search writes `filters.textSearch` |
118
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 |
119
122
  | `signal` | the grid | an `AbortSignal`, aborted when a refresh replaces the load or the grid unmounts |
120
123
 
121
124
  `DataGridLoadResult` is `{ results: TItem[]; total?: number }`. `total` is what the pager
@@ -268,6 +271,25 @@ Hold the flag on the screen that renders the grid rather than inside the thing
268
271
  that started the work, so the overlay survives that thing going away. It is OR-ed
269
272
  with the grid's own loads, and there is no imperative equivalent.
270
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
+
271
293
  ## Empty state
272
294
 
273
295
  A grid with no records shows a centered `Empty` instead of the table: "No results
@@ -374,7 +396,11 @@ A page change updates the page, stores it and reloads. A limit change goes back
374
396
  page 1, stores the limit and reloads. A refresh resets the page to 1. The page
375
397
  count comes from `total`. The loading treatment is the grid's, not the pager's.
376
398
  In a container too narrow for one row, the page buttons wrap to a centred line
377
- 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`).
378
404
 
379
405
  ### `DataGridTextSearchPlugin`
380
406
 
@@ -717,7 +743,8 @@ CSS customization) when the grid sits on `--background`.
717
743
  ### `DataGridActionsMenuPlugin`
718
744
 
719
745
  Adds an ellipsis button named "Actions" to the toolbar's `top-end` slot, after the other
720
- toolbar buttons (order 100). It opens a `DropdownMenu` whose items are components of yours.
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).
721
748
 
722
749
  | Prop | Type | Notes |
723
750
  |------|------|-------|
@@ -745,6 +772,65 @@ on the plugin's API (`getPlugin<DataGridActionsMenuPluginApi>('actionsMenu')`);
745
772
  (`10 * (count + 1)`). A new `menuItems` array replaces every item, the registered ones too, so
746
773
  keep `menuItems` in a module-level constant or `useMemo`.
747
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
+
748
834
  ### `DataGridTableConfigurationPlugin`
749
835
 
750
836
  Adds a gear button named "Configure columns" to the toolbar's `top-end` slot, after an
@@ -863,6 +949,162 @@ scope.
863
949
  The checkbox column marks its whole cell, header and body, as ignoring row clicks, so ticking a
864
950
  box does not call a row click plugin's `click`. Nothing to configure.
865
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
+
866
1108
  ## Custom plugins
867
1109
 
868
1110
  `createDataGridPlugin(name, setup, propsAreEqual?)` returns a component to use as
@@ -973,6 +1215,7 @@ Set these on the grid or any ancestor:
973
1215
  | `--data-grid-text-search-inline-size` | `initial` | Width of the search box; a fixed value stops it shifting as the clear button appears |
974
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` |
975
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 |
976
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 |
977
1220
 
978
1221
  The floor is one constraint among several: under `'fixed'` a table whose columns
@@ -986,7 +1229,10 @@ columns' minimum content widths.
986
1229
  - The table's scroll container is a tab stop (it holds `tabIndex=0` so a keyboard
987
1230
  can scroll it).
988
1231
  - The pager is a `nav` named "Pagination"; the page buttons are named "Go to page
989
- 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.
990
1236
  - `aria-busy` is set on the content region while a loader is on screen.
991
1237
  - The order popover's items are menu items without a menu popup, so they take
992
1238
  focus and Enter and Space, but arrow keys do not move between them.
@@ -1007,6 +1253,11 @@ columns' minimum content widths.
1007
1253
  and the pin buttons are named "Pin column" and "Unpin column" without the column.
1008
1254
  - With the row click plugin every body row is a tab stop and Enter activates it; Space
1009
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.
1010
1261
  - The row select checkboxes, the select-all one included, have no accessible name. "Select all
1011
1262
  N" and "Clear selection" in the banner are buttons, and the banner is an `alert`, so it is
1012
1263
  announced when it appears.
@@ -1045,7 +1296,29 @@ columns' minimum content widths.
1045
1296
  }}
1046
1297
  >
1047
1298
  ```
1048
- - Renderer overrides (`registerComponent`) are last registered wins.
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.
1049
1322
  - `registerComponent` accepts `'header-cell'` and `'header-group'`, but the header
1050
1323
  always renders its own cell and group components, so those two overrides have no
1051
1324
  effect.
@@ -92,6 +92,20 @@ native `<button>`s, because `PaginationLink` always renders an anchor (it has
92
92
  no `render` prop). Pick by what a page change is: a navigation to a URL is a
93
93
  link, a state update is a button.
94
94
 
95
+ The Previous/Next labels hide below 640px, measured on the `Pagination` root
96
+ when there is one. The root is a size container (`container-type: inline-size`,
97
+ named `pagination`), so inside it the labels follow the root's own width: a
98
+ pager in a narrow column of a wide screen shows the chevrons alone, as it does
99
+ on a phone, and a pager in a wide container keeps the words on a narrow
100
+ screen. A Previous/Next part used without the root has no such container and
101
+ follows the viewport (upstream's `hidden sm:block`).
102
+
103
+ Because of the containment the root takes the width its parent gives it rather
104
+ than the width of its content: put it in block flow or a stretched flex item,
105
+ not inside a parent that shrinks to fit its content (an `inline-block`, a
106
+ float, a `width: max-content` box, a `width: auto` flex item), which would
107
+ collapse it to zero width. Give such a parent a width.
108
+
95
109
  ## Examples
96
110
 
97
111
  ```tsx
@@ -197,7 +197,16 @@ that shape — the drawn state language of the Studio Data Table:
197
197
  both themes; `--muted` would not, since the theme draws it equal to
198
198
  `--background` in light and to every surface in dark. A `data-state` tint
199
199
  outranks hover, so a selected row stays selected-colored under the
200
- pointer.
200
+ pointer. The tint is the hook `--table-row-hover-fill`, read with
201
+ `--card-hover` as its fallback and declared nowhere by the kit: set it on the
202
+ table (through `className`) or on an ancestor to change the tint, or to
203
+ `transparent` to turn it off while something else shows the user where they
204
+ are, as a drag over the rows does. A pinned cell follows it, as it follows
205
+ every fill a row has.
206
+
207
+ ```css
208
+ .reordering { --table-row-hover-fill: transparent; }
209
+ ```
201
210
 
202
211
  Because rows carry no fill at rest, the surface behind the table shows
203
212
  through them — put a `Table` on a `Card`, on `DataTable`'s own card, or on
package/dist/index.d.ts CHANGED
@@ -49,6 +49,7 @@ export * from './components/command/public.js';
49
49
  export * from './components/context-menu/public.js';
50
50
  export * from './components/data-grid/plugins/actions-menu/public.js';
51
51
  export * from './components/data-grid/plugins/actions/public.js';
52
+ export * from './components/data-grid/plugins/drag-drop/public.js';
52
53
  export * from './components/data-grid/plugins/empty-state/public.js';
53
54
  export * from './components/data-grid/plugins/filters/public.js';
54
55
  export * from './components/data-grid/plugins/order/public.js';
@@ -58,6 +59,7 @@ export * from './components/data-grid/plugins/row-click/public.js';
58
59
  export * from './components/data-grid/plugins/row-number/public.js';
59
60
  export * from './components/data-grid/plugins/row-select/public.js';
60
61
  export * from './components/data-grid/plugins/table-configuration/public.js';
62
+ export * from './components/data-grid/plugins/table-tree/public.js';
61
63
  export * from './components/data-grid/plugins/text-search/public.js';
62
64
  export * from './components/data-grid/public.js';
63
65
  export * from './components/data-table/public.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,cAAc,kCAAkC,CAAC;AACjD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qCAAqC,CAAC;AACpD,cAAc,qCAAqC,CAAC;AACpD,cAAc,mCAAmC,CAAC;AAClD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mCAAmC,CAAC;AAClD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qCAAqC,CAAC;AACpD,cAAc,iCAAiC,CAAC;AAChD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iCAAiC,CAAC;AAChD,cAAc,mCAAmC,CAAC;AAClD,cAAc,oCAAoC,CAAC;AACnD,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qCAAqC,CAAC;AACpD,cAAc,uDAAuD,CAAC;AACtE,cAAc,kDAAkD,CAAC;AACjE,cAAc,sDAAsD,CAAC;AACrE,cAAc,kDAAkD,CAAC;AACjE,cAAc,gDAAgD,CAAC;AAC/D,cAAc,qDAAqD,CAAC;AACpE,cAAc,sDAAsD,CAAC;AACrE,cAAc,oDAAoD,CAAC;AACnE,cAAc,qDAAqD,CAAC;AACpE,cAAc,qDAAqD,CAAC;AACpE,cAAc,8DAA8D,CAAC;AAC7E,cAAc,sDAAsD,CAAC;AACrE,cAAc,kCAAkC,CAAC;AACjD,cAAc,mCAAmC,CAAC;AAClD,cAAc,oCAAoC,CAAC;AACnD,cAAc,yCAAyC,CAAC;AACxD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kCAAkC,CAAC;AACjD,cAAc,+BAA+B,CAAC;AAC9C,cAAc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