@calcifer-design/ui 0.5.0 → 0.7.0

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 (229) hide show
  1. package/dist/components/Alert/Alert.d.ts +5 -2
  2. package/dist/components/Alert/Alert.js +1 -0
  3. package/dist/components/Alert/Alert.module.js +5 -5
  4. package/dist/components/Alert/Alert_module.css +20 -17
  5. package/dist/components/Avatar/Avatar.d.ts +16 -2
  6. package/dist/components/Avatar/Avatar.js +23 -7
  7. package/dist/components/Avatar/Avatar.module.js +3 -3
  8. package/dist/components/Avatar/Avatar_module.css +58 -17
  9. package/dist/components/Avatar/avatarColor.d.ts +12 -0
  10. package/dist/components/Avatar/avatarColor.js +12 -0
  11. package/dist/components/AvatarGroup/AvatarGroup.d.ts +37 -0
  12. package/dist/components/AvatarGroup/AvatarGroup.js +52 -0
  13. package/dist/components/AvatarGroup/AvatarGroup.module.js +8 -0
  14. package/dist/components/AvatarGroup/AvatarGroup_module.css +67 -0
  15. package/dist/components/Breadcrumb/Breadcrumb.module.js +6 -6
  16. package/dist/components/Breadcrumb/Breadcrumb_module.css +7 -7
  17. package/dist/components/Button/Button.d.ts +40 -4
  18. package/dist/components/Button/Button.js +48 -11
  19. package/dist/components/Button/Button.module.js +6 -2
  20. package/dist/components/Button/Button_module.css +143 -17
  21. package/dist/components/Button/LinkButton.d.ts +10 -3
  22. package/dist/components/Button/LinkButton.js +16 -5
  23. package/dist/components/Card/Card.module.js +5 -5
  24. package/dist/components/Card/Card_module.css +15 -9
  25. package/dist/components/CardList/CardList.module.js +3 -3
  26. package/dist/components/CardList/CardList_module.css +5 -3
  27. package/dist/components/Checkbox/Checkbox.module.js +2 -2
  28. package/dist/components/Checkbox/Checkbox_module.css +3 -3
  29. package/dist/components/ChoiceCard/ChoiceCard.d.ts +34 -0
  30. package/dist/components/ChoiceCard/ChoiceCard.js +81 -0
  31. package/dist/components/ChoiceCard/ChoiceCard.module.js +12 -0
  32. package/dist/components/ChoiceCard/ChoiceCard_module.css +161 -0
  33. package/dist/components/Collapsible/Collapsible.d.ts +39 -0
  34. package/dist/components/Collapsible/Collapsible.js +63 -0
  35. package/dist/components/Collapsible/Collapsible.module.js +10 -0
  36. package/dist/components/Collapsible/Collapsible_module.css +80 -0
  37. package/dist/components/DataGrid/DataGrid.d.ts +3 -0
  38. package/dist/components/DataGrid/DataGrid.js +436 -0
  39. package/dist/components/DataGrid/DataGrid.module.js +36 -0
  40. package/dist/components/DataGrid/DataGrid_module.css +372 -0
  41. package/dist/components/DataGrid/GridCardHeader.d.ts +16 -0
  42. package/dist/components/DataGrid/GridCardHeader.js +40 -0
  43. package/dist/components/DataGrid/GridCheckbox.d.ts +15 -0
  44. package/dist/components/DataGrid/GridCheckbox.js +25 -0
  45. package/dist/components/DataGrid/GridHeaderCell.d.ts +14 -0
  46. package/dist/components/DataGrid/GridHeaderCell.js +29 -0
  47. package/dist/components/DataGrid/GridHeaderRow.d.ts +35 -0
  48. package/dist/components/DataGrid/GridHeaderRow.js +56 -0
  49. package/dist/components/DataGrid/GridRow.d.ts +69 -0
  50. package/dist/components/DataGrid/GridRow.js +139 -0
  51. package/dist/components/DataGrid/GridStateRows.d.ts +24 -0
  52. package/dist/components/DataGrid/GridStateRows.js +59 -0
  53. package/dist/components/DataGrid/columns.d.ts +40 -0
  54. package/dist/components/DataGrid/columns.js +37 -0
  55. package/dist/components/DataGrid/labels.d.ts +20 -0
  56. package/dist/components/DataGrid/labels.js +25 -0
  57. package/dist/components/DataGrid/types.d.ts +88 -0
  58. package/dist/components/DataGrid/types.js +0 -0
  59. package/dist/components/DataGrid/useGridEntries.d.ts +17 -0
  60. package/dist/components/DataGrid/useGridEntries.js +40 -0
  61. package/dist/components/DataGrid/useGridHighlight.d.ts +16 -0
  62. package/dist/components/DataGrid/useGridHighlight.js +24 -0
  63. package/dist/components/DataGrid/useGridKeyboard.d.ts +50 -0
  64. package/dist/components/DataGrid/useGridKeyboard.js +242 -0
  65. package/dist/components/DataGrid/useGridMetrics.d.ts +13 -0
  66. package/dist/components/DataGrid/useGridMetrics.js +35 -0
  67. package/dist/components/DataGrid/useLatest.d.ts +7 -0
  68. package/dist/components/DataGrid/useLatest.js +9 -0
  69. package/dist/components/DataGrid/useLoadMore.d.ts +30 -0
  70. package/dist/components/DataGrid/useLoadMore.js +39 -0
  71. package/dist/components/DataGrid/useRowExpansion.d.ts +14 -0
  72. package/dist/components/DataGrid/useRowExpansion.js +21 -0
  73. package/dist/components/DataGrid/useRowSelection.d.ts +43 -0
  74. package/dist/components/DataGrid/useRowSelection.js +107 -0
  75. package/dist/components/DataTable/DataTable.module.js +9 -9
  76. package/dist/components/DataTable/DataTable_module.css +24 -21
  77. package/dist/components/DatePicker/DatePicker.d.ts +15 -1
  78. package/dist/components/DatePicker/DatePicker.js +30 -5
  79. package/dist/components/DatePicker/DatePicker.module.js +10 -10
  80. package/dist/components/DatePicker/DatePicker_module.css +22 -21
  81. package/dist/components/Descriptions/Descriptions.module.js +4 -4
  82. package/dist/components/Descriptions/Descriptions_module.css +12 -8
  83. package/dist/components/Dialog/Dialog.d.ts +30 -2
  84. package/dist/components/Dialog/Dialog.js +52 -11
  85. package/dist/components/Dialog/Dialog.module.js +8 -6
  86. package/dist/components/Dialog/Dialog_module.css +60 -13
  87. package/dist/components/EmptyState/EmptyState.d.ts +41 -0
  88. package/dist/components/EmptyState/EmptyState.js +39 -0
  89. package/dist/components/EmptyState/EmptyState.module.js +9 -0
  90. package/dist/components/EmptyState/EmptyState_module.css +65 -0
  91. package/dist/components/ErrorBoundary/ErrorBoundary.d.ts +5 -2
  92. package/dist/components/ErrorBoundary/ErrorBoundary.module.js +1 -1
  93. package/dist/components/ErrorBoundary/ErrorBoundary_module.css +1 -1
  94. package/dist/components/Field/AffixInput.d.ts +28 -0
  95. package/dist/components/Field/AffixInput.js +50 -0
  96. package/dist/components/Field/GroupFrame.d.ts +19 -0
  97. package/dist/components/Field/GroupFrame.js +31 -0
  98. package/dist/components/Field/PickerField.d.ts +8 -2
  99. package/dist/components/Field/PickerField.js +12 -8
  100. package/dist/components/Field/PickerField.module.js +4 -4
  101. package/dist/components/Field/PickerField_module.css +11 -6
  102. package/dist/components/FilterBar/FilterBar.module.js +9 -9
  103. package/dist/components/FilterBar/FilterBar_module.css +13 -13
  104. package/dist/components/Form/Form.d.ts +9 -7
  105. package/dist/components/Form/Form.module.js +1 -1
  106. package/dist/components/Form/Form_module.css +1 -1
  107. package/dist/components/IconButton/IconButton.d.ts +1 -1
  108. package/dist/components/IconButton/IconButton.module.js +2 -2
  109. package/dist/components/IconButton/IconButton_module.css +28 -17
  110. package/dist/components/Menu/Menu.js +3 -0
  111. package/dist/components/Menu/Menu.module.js +2 -2
  112. package/dist/components/Menu/Menu_module.css +5 -4
  113. package/dist/components/NavMenu/NavMenu.d.ts +27 -4
  114. package/dist/components/NavMenu/NavMenu.js +10 -8
  115. package/dist/components/NavMenu/NavMenu.module.js +6 -6
  116. package/dist/components/NavMenu/NavMenu_module.css +37 -19
  117. package/dist/components/NavMenu/currentPath.d.ts +9 -0
  118. package/dist/components/NavMenu/currentPath.js +5 -0
  119. package/dist/components/PageHeading/PageHeading.module.js +3 -3
  120. package/dist/components/PageHeading/PageHeading_module.css +12 -9
  121. package/dist/components/PageShell/PageShell.module.js +5 -5
  122. package/dist/components/PageShell/PageShell_module.css +9 -9
  123. package/dist/components/Popover/Popover.js +3 -0
  124. package/dist/components/Popover/Popover.module.js +2 -2
  125. package/dist/components/Popover/Popover_module.css +6 -3
  126. package/dist/components/ProgressBar/ProgressBar.d.ts +55 -0
  127. package/dist/components/ProgressBar/ProgressBar.js +76 -0
  128. package/dist/components/ProgressBar/ProgressBar.module.js +12 -0
  129. package/dist/components/ProgressBar/ProgressBar_module.css +120 -0
  130. package/dist/components/RadioGroup/RadioGroup.d.ts +1 -1
  131. package/dist/components/RadioGroup/RadioGroup.js +35 -49
  132. package/dist/components/RadioGroup/RadioGroup.module.js +2 -2
  133. package/dist/components/RadioGroup/RadioGroup_module.css +2 -2
  134. package/dist/components/SearchField/SearchField.d.ts +32 -0
  135. package/dist/components/SearchField/SearchField.js +100 -0
  136. package/dist/components/SearchField/SearchField.module.js +8 -0
  137. package/dist/components/SearchField/SearchField_module.css +34 -0
  138. package/dist/components/Segmented/Segmented.d.ts +23 -6
  139. package/dist/components/Segmented/Segmented.js +37 -20
  140. package/dist/components/Segmented/Segmented.module.js +4 -3
  141. package/dist/components/Segmented/Segmented_module.css +46 -20
  142. package/dist/components/Select/Select.js +3 -0
  143. package/dist/components/Select/Select.module.js +5 -5
  144. package/dist/components/Select/Select_module.css +12 -11
  145. package/dist/components/Skeleton/Skeleton.module.js +3 -3
  146. package/dist/components/Skeleton/Skeleton_module.css +9 -9
  147. package/dist/components/SkipLink/SkipLink.module.js +1 -1
  148. package/dist/components/SkipLink/SkipLink_module.css +4 -4
  149. package/dist/components/Spinner/Spinner.module.js +3 -3
  150. package/dist/components/Spinner/Spinner_module.css +7 -7
  151. package/dist/components/StatusDot/StatusDot.module.js +5 -5
  152. package/dist/components/StatusDot/StatusDot_module.css +11 -11
  153. package/dist/components/Steps/Steps.module.js +6 -6
  154. package/dist/components/Steps/Steps_module.css +19 -19
  155. package/dist/components/Switch/Switch.module.js +2 -2
  156. package/dist/components/Switch/Switch_module.css +5 -5
  157. package/dist/components/TabBar/TabBar.d.ts +26 -0
  158. package/dist/components/TabBar/TabBar.js +52 -0
  159. package/dist/components/TabBar/TabBar.module.js +11 -0
  160. package/dist/components/TabBar/TabBar_module.css +100 -0
  161. package/dist/components/Tabs/Tabs.module.js +4 -4
  162. package/dist/components/Tabs/Tabs_module.css +9 -8
  163. package/dist/components/Tag/Tag.module.js +1 -1
  164. package/dist/components/Tag/Tag_module.css +3 -2
  165. package/dist/components/TextArea/TextArea.module.js +1 -1
  166. package/dist/components/TextArea/TextArea_module.css +6 -2
  167. package/dist/components/TextInput/TextInput.d.ts +14 -2
  168. package/dist/components/TextInput/TextInput.js +4 -5
  169. package/dist/components/ThemeScope/PortalContainerContext.d.ts +17 -0
  170. package/dist/components/ThemeScope/PortalContainerContext.js +6 -0
  171. package/dist/components/ThemeScope/ThemeScope.d.ts +23 -0
  172. package/dist/components/ThemeScope/ThemeScope.js +29 -0
  173. package/dist/components/ThemeScope/ThemeScope.module.js +6 -0
  174. package/dist/components/ThemeScope/ThemeScope_module.css +10 -0
  175. package/dist/components/TimePicker/TimePicker.d.ts +15 -2
  176. package/dist/components/TimePicker/TimePicker.js +5 -5
  177. package/dist/components/Timeline/Timeline.module.js +8 -8
  178. package/dist/components/Timeline/Timeline_module.css +15 -13
  179. package/dist/components/ToastRegion/ToastRegion.js +3 -0
  180. package/dist/components/ToastRegion/ToastRegion.module.js +6 -6
  181. package/dist/components/ToastRegion/ToastRegion_module.css +23 -19
  182. package/dist/components/ToggleChip/ToggleChip.d.ts +49 -0
  183. package/dist/components/ToggleChip/ToggleChip.js +45 -0
  184. package/dist/components/ToggleChip/ToggleChip.module.js +9 -0
  185. package/dist/components/ToggleChip/ToggleChipGroup.d.ts +57 -0
  186. package/dist/components/ToggleChip/ToggleChipGroup.js +93 -0
  187. package/dist/components/ToggleChip/ToggleChip_module.css +97 -0
  188. package/dist/components/Toolbar/Toolbar.module.js +3 -3
  189. package/dist/components/Toolbar/Toolbar_module.css +5 -5
  190. package/dist/components/Tooltip/Tooltip.js +3 -0
  191. package/dist/components/Tree/Tree.module.js +8 -8
  192. package/dist/components/Tree/Tree_module.css +20 -20
  193. package/dist/components/TreeSelect/TreeSelect.js +3 -0
  194. package/dist/components/TreeSelect/TreeSelect.module.js +3 -3
  195. package/dist/components/TreeSelect/TreeSelect_module.css +4 -4
  196. package/dist/components/Upload/Upload.module.js +8 -8
  197. package/dist/components/Upload/Upload_module.css +16 -16
  198. package/dist/components/ViewField/ViewField.module.js +2 -2
  199. package/dist/components/ViewField/ViewField_module.css +3 -3
  200. package/dist/hooks/useControllable.d.ts +11 -0
  201. package/dist/hooks/useControllable.js +13 -0
  202. package/dist/hooks/useIndexedToggleGroup.d.ts +30 -0
  203. package/dist/hooks/useIndexedToggleGroup.js +26 -0
  204. package/dist/hooks/useOverflowFocusable.d.ts +17 -0
  205. package/dist/hooks/useOverflowFocusable.js +36 -0
  206. package/dist/icons/ChevronRightIcon.d.ts +6 -0
  207. package/dist/icons/ChevronRightIcon.js +17 -0
  208. package/dist/icons/RefreshIcon.d.ts +6 -0
  209. package/dist/icons/RefreshIcon.js +22 -0
  210. package/dist/icons/SearchIcon.d.ts +9 -0
  211. package/dist/icons/SearchIcon.js +23 -0
  212. package/dist/index.d.ts +31 -0
  213. package/dist/index.js +14 -0
  214. package/dist/styles/a11y.module.js +1 -1
  215. package/dist/styles/a11y_module.css +1 -1
  216. package/dist/styles/base.css +17 -0
  217. package/dist/styles/closeCircle.module.js +5 -0
  218. package/dist/styles/closeCircle_module.css +12 -0
  219. package/dist/styles/field.module.js +14 -11
  220. package/dist/styles/field_module.css +92 -23
  221. package/dist/styles/pair.module.js +2 -2
  222. package/dist/styles/pair_module.css +5 -3
  223. package/dist/styles/popup.module.js +5 -5
  224. package/dist/styles/popup_module.css +35 -28
  225. package/dist/utils/focusInputFromPill.d.ts +12 -0
  226. package/dist/utils/focusInputFromPill.js +7 -0
  227. package/dist/utils/hasContent.d.ts +8 -0
  228. package/dist/utils/hasContent.js +4 -0
  229. package/package.json +4 -3
@@ -0,0 +1,139 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { flexRender } from "@tanstack/react-table";
3
+ import { ChevronRightIcon } from "../../icons/ChevronRightIcon.js";
4
+ import { textValueOf } from "./columns.js";
5
+ import DataGrid_module from "./DataGrid.module.js";
6
+ import { GridCheckbox } from "./GridCheckbox.js";
7
+ import { cellControlSelector } from "./useGridKeyboard.js";
8
+ function rowCellOf(event) {
9
+ let element = event.target instanceof Element ? event.target : null;
10
+ while(null !== element && element.parentElement !== event.currentTarget)element = element.parentElement;
11
+ return element instanceof HTMLTableCellElement ? element : null;
12
+ }
13
+ function isRowEvent(event) {
14
+ const cell = rowCellOf(event);
15
+ if (null === cell) return false;
16
+ const control = event.target.closest(cellControlSelector);
17
+ return null === control || control === cell || !cell.contains(control);
18
+ }
19
+ function isRowClick(event) {
20
+ return isRowEvent(event) && !rowCellOf(event)?.hasAttribute('data-toggle-cell');
21
+ }
22
+ function onlyRowClicks(handler) {
23
+ return (event)=>{
24
+ if (isRowClick(event)) handler(event);
25
+ };
26
+ }
27
+ function onlyRowEvents(handler) {
28
+ return (event)=>{
29
+ if (isRowEvent(event)) handler(event);
30
+ };
31
+ }
32
+ function compactTitle(column, row) {
33
+ const text = textValueOf(column, row);
34
+ return void 0 === text || '' === text.trim() ? void 0 : text;
35
+ }
36
+ function GridRow({ row, entryIndex, measureRef, density, columnOffset, highlighted, clickable, checkbox, expander, renderRowActions, getCellProps, onClick, onDoubleClick, onContextMenu }) {
37
+ const rowIndex = entryIndex + 1;
38
+ const selecting = void 0 !== checkbox;
39
+ const expandColumn = selecting ? 1 : 0;
40
+ const cells = row.getAllCells();
41
+ let ariaSelected;
42
+ ariaSelected = selecting ? checkbox.selectable ? checkbox.selected : void 0 : highlighted || void 0;
43
+ return /*#__PURE__*/ jsxs("tr", {
44
+ ref: measureRef,
45
+ "data-index": entryIndex,
46
+ className: DataGrid_module.row,
47
+ "aria-rowindex": rowIndex + 1,
48
+ "aria-selected": ariaSelected,
49
+ "aria-current": selecting && highlighted ? 'true' : void 0,
50
+ "data-highlighted": highlighted ? '' : void 0,
51
+ "data-clickable": clickable ? '' : void 0,
52
+ onClick: onlyRowClicks(onClick),
53
+ onDoubleClick: onDoubleClick ? onlyRowClicks(onDoubleClick) : void 0,
54
+ onContextMenu: onContextMenu ? onlyRowEvents(onContextMenu) : void 0,
55
+ children: [
56
+ checkbox ? /*#__PURE__*/ jsx("td", {
57
+ role: "gridcell",
58
+ className: `${DataGrid_module.cell} ${DataGrid_module.pinnedCell} ${DataGrid_module.selectCell}`,
59
+ "aria-colindex": 1,
60
+ "data-toggle-cell": "",
61
+ onClickCapture: checkbox.onClickCapture,
62
+ onClick: (event)=>{
63
+ if (event.target === event.currentTarget) checkbox.onCellClick(event);
64
+ },
65
+ ...getCellProps(rowIndex, 0),
66
+ children: /*#__PURE__*/ jsx(GridCheckbox, {
67
+ label: checkbox.label,
68
+ checked: checkbox.selected,
69
+ disabled: !checkbox.selectable,
70
+ onCheckedChange: checkbox.onCheckedChange,
71
+ tabIndex: -1
72
+ })
73
+ }) : null,
74
+ expander ? /*#__PURE__*/ jsx("td", {
75
+ role: "gridcell",
76
+ className: `${DataGrid_module.cell} ${DataGrid_module.pinnedCell} ${DataGrid_module.expandCell}`,
77
+ "aria-colindex": expandColumn + 1,
78
+ "data-toggle-cell": expander.expandable ? '' : void 0,
79
+ onClick: expander.expandable ? expander.onToggle : void 0,
80
+ ...getCellProps(rowIndex, expandColumn),
81
+ children: expander.expandable ? /*#__PURE__*/ jsx("button", {
82
+ type: "button",
83
+ className: DataGrid_module.expandButton,
84
+ "aria-label": expander.label,
85
+ "aria-expanded": expander.expanded,
86
+ "aria-controls": expander.expanded ? expander.panelId : void 0,
87
+ tabIndex: -1,
88
+ children: /*#__PURE__*/ jsx(ChevronRightIcon, {})
89
+ }) : null
90
+ }) : null,
91
+ cells.map((cell, columnIndex)=>/*#__PURE__*/ jsx("td", {
92
+ role: "gridcell",
93
+ className: DataGrid_module.cell,
94
+ "aria-colindex": columnIndex + 1 + columnOffset,
95
+ title: 'compact' === density ? compactTitle(cell.column.columnDef, row.original) : void 0,
96
+ ...getCellProps(rowIndex, columnIndex + columnOffset),
97
+ children: flexRender(cell.column.columnDef.cell, cell.getContext())
98
+ }, cell.id)),
99
+ renderRowActions ? /*#__PURE__*/ jsx("td", {
100
+ role: "gridcell",
101
+ className: `${DataGrid_module.cell} ${DataGrid_module.pinnedCell} ${DataGrid_module.actionsCell}`,
102
+ "aria-colindex": columnOffset + cells.length + 1,
103
+ ...getCellProps(rowIndex, columnOffset + cells.length),
104
+ children: renderRowActions(row.original)
105
+ }) : null
106
+ ]
107
+ });
108
+ }
109
+ function GridDetailRow({ entryIndex, measureRef, columnCount, panelId, getCellProps, children }) {
110
+ const rowIndex = entryIndex + 1;
111
+ return /*#__PURE__*/ jsx("tr", {
112
+ ref: measureRef,
113
+ "data-index": entryIndex,
114
+ className: DataGrid_module.detailRow,
115
+ "aria-rowindex": rowIndex + 1,
116
+ children: /*#__PURE__*/ jsx("td", {
117
+ id: panelId,
118
+ role: "gridcell",
119
+ className: DataGrid_module.detailCell,
120
+ colSpan: columnCount,
121
+ "aria-colindex": 1,
122
+ ...getCellProps(rowIndex, 0, columnCount),
123
+ children: children
124
+ })
125
+ });
126
+ }
127
+ function GridSpacerRow({ height, columnCount }) {
128
+ return /*#__PURE__*/ jsx("tr", {
129
+ "aria-hidden": "true",
130
+ children: /*#__PURE__*/ jsx("td", {
131
+ className: DataGrid_module.spacerCell,
132
+ colSpan: columnCount,
133
+ style: {
134
+ height
135
+ }
136
+ })
137
+ });
138
+ }
139
+ export { GridDetailRow, GridRow, GridSpacerRow };
@@ -0,0 +1,24 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { GetCellProps } from './useGridKeyboard.js';
3
+ export type GridStateKind = 'loading' | 'empty';
4
+ export interface GridStateRowProps {
5
+ kind: GridStateKind;
6
+ /** The message for `kind`. */
7
+ label: string;
8
+ /** Shown in place of the empty message. */
9
+ emptyState?: ReactNode;
10
+ columnCount: number;
11
+ }
12
+ /** The body's only row while it loads or has no rows: one cell across every column. */
13
+ export declare function GridStateRow({ kind, label, emptyState, columnCount }: GridStateRowProps): import("react").JSX.Element;
14
+ export interface GridErrorRowProps {
15
+ /** The row's place after the grid's entries; its keyboard row is one more. */
16
+ entryIndex: number;
17
+ columnCount: number;
18
+ message: string;
19
+ retryLabel: string;
20
+ onRetry: () => void;
21
+ getCellProps: GetCellProps;
22
+ }
23
+ /** A failed load in server mode: the error and a retry button, after the last entry. */
24
+ export declare function GridErrorRow({ entryIndex, columnCount, message, retryLabel, onRetry, getCellProps, }: GridErrorRowProps): import("react").JSX.Element;
@@ -0,0 +1,59 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Button } from "../Button/Button.js";
3
+ import { Spinner } from "../Spinner/Spinner.js";
4
+ import DataGrid_module from "./DataGrid.module.js";
5
+ function GridStateRow({ kind, label, emptyState, columnCount }) {
6
+ return /*#__PURE__*/ jsx("tr", {
7
+ "aria-rowindex": 2,
8
+ children: /*#__PURE__*/ jsx("td", {
9
+ role: "gridcell",
10
+ className: DataGrid_module.stateCell,
11
+ colSpan: columnCount,
12
+ "aria-colindex": 1,
13
+ children: 'loading' === kind ? /*#__PURE__*/ jsxs("div", {
14
+ className: DataGrid_module.state,
15
+ "aria-hidden": "true",
16
+ children: [
17
+ /*#__PURE__*/ jsx(Spinner, {
18
+ size: "md"
19
+ }),
20
+ label
21
+ ]
22
+ }) : emptyState ?? /*#__PURE__*/ jsx("div", {
23
+ className: DataGrid_module.state,
24
+ "aria-hidden": "true",
25
+ children: label
26
+ })
27
+ })
28
+ });
29
+ }
30
+ function GridErrorRow({ entryIndex, columnCount, message, retryLabel, onRetry, getCellProps }) {
31
+ const rowIndex = entryIndex + 1;
32
+ return /*#__PURE__*/ jsx("tr", {
33
+ "data-index": entryIndex,
34
+ "aria-rowindex": rowIndex + 1,
35
+ children: /*#__PURE__*/ jsx("td", {
36
+ role: "gridcell",
37
+ className: DataGrid_module.errorCell,
38
+ colSpan: columnCount,
39
+ "aria-colindex": 1,
40
+ ...getCellProps(rowIndex, 0, columnCount),
41
+ children: /*#__PURE__*/ jsxs("div", {
42
+ className: DataGrid_module.errorContent,
43
+ children: [
44
+ /*#__PURE__*/ jsx("span", {
45
+ role: "alert",
46
+ children: message
47
+ }),
48
+ /*#__PURE__*/ jsx(Button, {
49
+ variant: "secondary",
50
+ size: "sm",
51
+ onClick: onRetry,
52
+ children: retryLabel
53
+ })
54
+ ]
55
+ })
56
+ })
57
+ });
58
+ }
59
+ export { GridErrorRow, GridStateRow };
@@ -0,0 +1,40 @@
1
+ import { type AccessorFn, type AccessorFnColumnDef, type AccessorKeyColumnDef, type ColumnDef as TanStackColumnDef, type DeepKeys, type DeepValue, type DisplayColumnDef, type IdentifiedColumnDef, type RowData } from '@tanstack/react-table';
2
+ export declare const dataGridFeatures: {
3
+ rowSortingFeature: import("@tanstack/react-table").TableFeature;
4
+ rowSelectionFeature: import("@tanstack/react-table").TableFeature;
5
+ rowExpandingFeature: import("@tanstack/react-table").TableFeature;
6
+ sortedRowModel: (table: import("@tanstack/react-table").Table<any, any>) => () => import("@tanstack/react-table").RowModel<any, any>;
7
+ sortFns: {
8
+ alphanumeric: import("@tanstack/react-table").CreatedSortFn<any, any>;
9
+ text: import("@tanstack/react-table").CreatedSortFn<any, any>;
10
+ datetime: import("@tanstack/react-table").CreatedSortFn<any, any>;
11
+ };
12
+ };
13
+ export interface TextValueOption<Row extends RowData> {
14
+ /** Plain text for a cell: the row label, compact-density titles, and later search and export. */
15
+ textValue?: (row: Row) => string;
16
+ }
17
+ export type DataGridColumnDef<Row extends RowData, Value = unknown> = TanStackColumnDef<typeof dataGridFeatures, Row, Value> & TextValueOption<Row>;
18
+ export type DataGridFeatures = typeof dataGridFeatures;
19
+ type Features = DataGridFeatures;
20
+ export interface DataGridColumnHelper<Row extends RowData> {
21
+ accessor: <Accessor extends AccessorFn<Row> | DeepKeys<Row>, Value extends (Accessor extends AccessorFn<Row, infer Returned> ? Returned : Accessor extends DeepKeys<Row> ? DeepValue<Row, Accessor> : never)>(accessor: Accessor, column: (Accessor extends AccessorFn<Row> ? DisplayColumnDef<Features, Row, Value> : IdentifiedColumnDef<Features, Row, Value>) & TextValueOption<Row>) => (Accessor extends AccessorFn<Row> ? AccessorFnColumnDef<Features, Row, Value> : AccessorKeyColumnDef<Features, Row, Value>) & TextValueOption<Row>;
22
+ /**
23
+ * Wrap the array in this, not a plain literal: it keeps each column's own value type. The
24
+ * `any` is TanStack's own signature for the same helper.
25
+ */
26
+ columns: <Columns extends ReadonlyArray<DataGridColumnDef<Row, any>>>(columns: [...Columns]) => Array<DataGridColumnDef<Row, any>> & [...Columns];
27
+ display: (column: DisplayColumnDef<Features, Row> & TextValueOption<Row>) => DisplayColumnDef<Features, Row, unknown> & TextValueOption<Row>;
28
+ }
29
+ /**
30
+ * The TanStack v9 column helper, typed to the grid's feature set, with one extra column option:
31
+ * `textValue`. At runtime TanStack's helper only returns the definition objects it is given, so
32
+ * the extra option passes straight through.
33
+ */
34
+ export declare function createDataGridColumnHelper<Row extends RowData>(): DataGridColumnHelper<Row>;
35
+ /**
36
+ * The plain text a column gives for a row: its `textValue` when it has one, else the accessor
37
+ * value when that is a string, number or boolean. Anything else has no text.
38
+ */
39
+ export declare function textValueOf<Row extends RowData, Value = unknown>(column: DataGridColumnDef<Row, Value>, row: Row): string | undefined;
40
+ export {};
@@ -0,0 +1,37 @@
1
+ import { createColumnHelper, createSortedRowModel, rowExpandingFeature, rowSelectionFeature, rowSortingFeature, sortFn_alphanumeric, sortFn_datetime, sortFn_text, tableFeatures } from "@tanstack/react-table";
2
+ const dataGridFeatures = tableFeatures({
3
+ rowSortingFeature: rowSortingFeature,
4
+ rowSelectionFeature: rowSelectionFeature,
5
+ rowExpandingFeature: rowExpandingFeature,
6
+ sortedRowModel: createSortedRowModel(),
7
+ sortFns: {
8
+ alphanumeric: sortFn_alphanumeric,
9
+ text: sortFn_text,
10
+ datetime: sortFn_datetime
11
+ }
12
+ });
13
+ function createDataGridColumnHelper() {
14
+ return createColumnHelper();
15
+ }
16
+ function isText(value) {
17
+ return 'string' == typeof value || 'number' == typeof value || 'boolean' == typeof value;
18
+ }
19
+ function valueAtPath(source, path) {
20
+ let current = source;
21
+ for (const segment of path.split('.')){
22
+ if (null === current || 'object' != typeof current) return;
23
+ current = current[segment];
24
+ }
25
+ return current;
26
+ }
27
+ function textValueOf(column, row) {
28
+ if (column.textValue) return column.textValue(row);
29
+ let value;
30
+ if ('accessorFn' in column && 'function' == typeof column.accessorFn) value = column.accessorFn(row, 0);
31
+ else {
32
+ if (!('accessorKey' in column) || 'string' != typeof column.accessorKey) return;
33
+ value = row[column.accessorKey] ?? valueAtPath(row, column.accessorKey);
34
+ }
35
+ return isText(value) ? String(value) : void 0;
36
+ }
37
+ export { createDataGridColumnHelper, dataGridFeatures, textValueOf };
@@ -0,0 +1,20 @@
1
+ export interface DataGridLabels {
2
+ toolbar: string;
3
+ refresh: string;
4
+ rowCount: (count: number) => string;
5
+ loadedRowCount: (loaded: number, total: number) => string;
6
+ selectedCount: (count: number) => string;
7
+ loading: string;
8
+ loadingMore: string;
9
+ retry: string;
10
+ empty: string;
11
+ selectAll: string;
12
+ selectRow: (rowLabel: string) => string;
13
+ /** The expand column's header, which shows nothing but needs a name. */
14
+ expandColumn: string;
15
+ expandRow: (rowLabel: string) => string;
16
+ rowActions: string;
17
+ }
18
+ export declare const defaultDataGridLabels: DataGridLabels;
19
+ /** The defaults with the given labels over them; a label given as undefined keeps its default. */
20
+ export declare function resolveDataGridLabels(labels: Partial<DataGridLabels> | undefined): DataGridLabels;
@@ -0,0 +1,25 @@
1
+ const numberFormat = new Intl.NumberFormat('en-US');
2
+ const defaultDataGridLabels = {
3
+ toolbar: 'Grid tools',
4
+ refresh: 'Refresh',
5
+ rowCount: (count)=>`${numberFormat.format(count)} ${1 === count ? 'row' : 'rows'}`,
6
+ loadedRowCount: (loaded, total)=>`Showing ${numberFormat.format(loaded)} of ${numberFormat.format(total)} rows`,
7
+ selectedCount: (count)=>`${numberFormat.format(count)} selected`,
8
+ loading: 'Loading rows…',
9
+ loadingMore: 'Loading more rows…',
10
+ retry: 'Try again',
11
+ empty: 'No rows to show.',
12
+ selectAll: 'Select all rows',
13
+ selectRow: (rowLabel)=>`Select ${rowLabel}`,
14
+ expandColumn: 'Details',
15
+ expandRow: (rowLabel)=>`Show details for ${rowLabel}`,
16
+ rowActions: 'Actions'
17
+ };
18
+ function resolveDataGridLabels(labels) {
19
+ const givenLabels = Object.entries(labels ?? {}).filter(([, label])=>void 0 !== label);
20
+ return {
21
+ ...defaultDataGridLabels,
22
+ ...Object.fromEntries(givenLabels)
23
+ };
24
+ }
25
+ export { defaultDataGridLabels, resolveDataGridLabels };
@@ -0,0 +1,88 @@
1
+ import type { RowData, SortingState } from '@tanstack/react-table';
2
+ import type { KeyboardEvent, MouseEvent, ReactNode } from 'react';
3
+ import type { DataGridColumnDef } from './columns.js';
4
+ import type { DataGridLabels } from './labels.js';
5
+ export type DataGridMode = 'client' | 'server';
6
+ export type DataGridDensity = 'comfortable' | 'compact';
7
+ export type DataGridFilterValue = string | string[];
8
+ export interface DataGridQuery {
9
+ sorting: SortingState;
10
+ filters: Record<string, DataGridFilterValue>;
11
+ matchMode: 'all' | 'any';
12
+ search: string;
13
+ }
14
+ export type DataGridRowEvent = MouseEvent<HTMLElement> | KeyboardEvent<HTMLElement>;
15
+ export interface DataGridProps<Row extends RowData> {
16
+ gridId: string;
17
+ heading: string;
18
+ headingLevel?: 2 | 3 | 4 | 5 | 6;
19
+ /**
20
+ * In server mode, pass a new array only when your data changes: after a query change the grid
21
+ * waits for a new `rows` array before it asks for more, so a copy made on every render would
22
+ * end that wait early.
23
+ */
24
+ rows: Row[];
25
+ /** Build with `createDataGridColumnHelper<Row>().columns([...])`, not a plain array literal. */
26
+ columns: DataGridColumnDef<Row, unknown>[];
27
+ getRowId: (row: Row) => string;
28
+ /** Defaults to the text value of the first column. */
29
+ getRowLabel?: (row: Row) => string;
30
+ actions?: ReactNode;
31
+ /**
32
+ * `'client'` (the default) sorts the given rows itself. `'server'` leaves sorting to the app and
33
+ * asks for rows page by page; there, headers sort only when `onQueryChange` is given.
34
+ */
35
+ mode?: DataGridMode;
36
+ totalRowCount?: number;
37
+ hasMore?: boolean;
38
+ loadingMore?: boolean;
39
+ loadError?: string;
40
+ onLoadMore?: () => void;
41
+ /**
42
+ * Server mode: the user changed the sort, so load the first page of rows for this query. Without
43
+ * it, server mode's headers are not sortable and carry no `aria-sort`.
44
+ */
45
+ onQueryChange?: (query: DataGridQuery) => void;
46
+ /**
47
+ * The sort the grid starts with. The planned `initialQuery` prop will win over it when both are
48
+ * given.
49
+ */
50
+ initialSorting?: SortingState;
51
+ enableSorting?: boolean;
52
+ multiSort?: boolean;
53
+ loading?: boolean;
54
+ /**
55
+ * Replaces the default empty message. The grid announces `labels.empty` when it is empty, not
56
+ * this node, so set `labels.empty` to match your message.
57
+ */
58
+ emptyState?: ReactNode;
59
+ density?: DataGridDensity;
60
+ /**
61
+ * The tallest the scrolling body grows before it scrolls, as a CSS length. Defaults to the
62
+ * viewport height minus 16rem, which leaves room for a page header. Ignored when `fill` is set.
63
+ */
64
+ maxHeight?: string;
65
+ fill?: boolean;
66
+ hideFooter?: boolean;
67
+ onRefresh?: () => void;
68
+ refreshing?: boolean;
69
+ highlightOnClick?: boolean;
70
+ highlightedRowId?: string | null;
71
+ onHighlightChange?: (rowId: string | null) => void;
72
+ selectionMode?: 'none' | 'multiple';
73
+ selectedRowIds?: string[];
74
+ defaultSelectedRowIds?: string[];
75
+ onSelectedRowIdsChange?: (rowIds: string[]) => void;
76
+ isRowSelectable?: (row: Row) => boolean;
77
+ onRowClick?: (row: Row, event: DataGridRowEvent) => void;
78
+ onRowDoubleClick?: (row: Row, event: DataGridRowEvent) => void;
79
+ onRowContextMenu?: (row: Row, event: DataGridRowEvent) => void;
80
+ renderRowActions?: (row: Row) => ReactNode;
81
+ rowActionsHeader?: ReactNode;
82
+ renderExpandedRow?: (row: Row) => ReactNode;
83
+ isRowExpandable?: (row: Row) => boolean;
84
+ expandedRowIds?: string[];
85
+ defaultExpandedRowIds?: string[];
86
+ onExpandedRowIdsChange?: (rowIds: string[]) => void;
87
+ labels?: Partial<DataGridLabels>;
88
+ }
File without changes
@@ -0,0 +1,17 @@
1
+ export type GridEntry<Row> = {
2
+ kind: 'row';
3
+ row: Row;
4
+ rowIndex: number;
5
+ } | {
6
+ kind: 'detail';
7
+ row: Row;
8
+ rowIndex: number;
9
+ };
10
+ /**
11
+ * Flattens rows and the detail panels of expanded rows into the one list the virtualiser walks.
12
+ * `aria-rowindex` of an entry is 2 plus its position here (row 1 is the header). A row gets a panel
13
+ * when its id is in `expandedIds` and `canExpand` allows it.
14
+ */
15
+ export declare function useGridEntries<Row extends {
16
+ id: string;
17
+ }>(rows: readonly Row[], expandedIds: ReadonlySet<string>, canExpand: (row: Row) => boolean): GridEntry<Row>[];
@@ -0,0 +1,40 @@
1
+ import { useMemo } from "react";
2
+ function useGridEntries(rows, expandedIds, canExpand) {
3
+ const rowsById = useMemo(()=>new Map(rows.map((row)=>[
4
+ row.id,
5
+ row
6
+ ])), [
7
+ rows
8
+ ]);
9
+ const openIdsKey = JSON.stringify([
10
+ ...expandedIds
11
+ ].filter((rowId)=>{
12
+ const row = rowsById.get(rowId);
13
+ return void 0 !== row && canExpand(row);
14
+ }));
15
+ return useMemo(()=>{
16
+ const openIds = new Set(JSON.parse(openIdsKey));
17
+ return rows.flatMap((row, rowIndex)=>openIds.has(row.id) ? [
18
+ {
19
+ kind: 'row',
20
+ row,
21
+ rowIndex
22
+ },
23
+ {
24
+ kind: 'detail',
25
+ row,
26
+ rowIndex
27
+ }
28
+ ] : [
29
+ {
30
+ kind: 'row',
31
+ row,
32
+ rowIndex
33
+ }
34
+ ]);
35
+ }, [
36
+ rows,
37
+ openIdsKey
38
+ ]);
39
+ }
40
+ export { useGridEntries };
@@ -0,0 +1,16 @@
1
+ export interface UseGridHighlightOptions<Row> {
2
+ rows: readonly Row[];
3
+ getRowId: (row: Row) => string;
4
+ /** Rows on their way in are not yet the rows the highlight must match. */
5
+ loading: boolean;
6
+ highlightedRowId?: string | null;
7
+ onHighlightChange?: (rowId: string | null) => void;
8
+ }
9
+ /**
10
+ * The highlighted row: controlled when `highlightedRowId` is given (null included), else the
11
+ * grid's own. A highlight whose row leaves the grid is cleared, and the consumer hears of it.
12
+ */
13
+ export declare function useGridHighlight<Row>({ rows, getRowId, loading, highlightedRowId, onHighlightChange, }: UseGridHighlightOptions<Row>): {
14
+ highlightedId: string | null;
15
+ setHighlightedId: (rowId: string | null) => void;
16
+ };
@@ -0,0 +1,24 @@
1
+ import { useEffect, useState } from "react";
2
+ import { useLatest } from "./useLatest.js";
3
+ function useGridHighlight({ rows, getRowId, loading, highlightedRowId, onHighlightChange }) {
4
+ const [ownHighlightedId, setOwnHighlightedId] = useState(null);
5
+ const highlightedId = void 0 === highlightedRowId ? ownHighlightedId : highlightedRowId;
6
+ const setHighlightedId = (next)=>{
7
+ onHighlightChange?.(next);
8
+ if (void 0 === highlightedRowId) setOwnHighlightedId(next);
9
+ };
10
+ const clearHighlightRef = useLatest(()=>setHighlightedId(null));
11
+ const isStale = null !== highlightedId && !loading && !rows.some((row)=>getRowId(row) === highlightedId);
12
+ useEffect(()=>{
13
+ if (isStale) clearHighlightRef.current();
14
+ }, [
15
+ isStale,
16
+ rows,
17
+ clearHighlightRef
18
+ ]);
19
+ return {
20
+ highlightedId,
21
+ setHighlightedId
22
+ };
23
+ }
24
+ export { useGridHighlight };
@@ -0,0 +1,50 @@
1
+ import { type FocusEvent, type KeyboardEvent, type RefObject } from 'react';
2
+ export interface GridCellPosition {
3
+ /** 0 is the header row; body entry `n` is row `n + 1`. */
4
+ rowIndex: number;
5
+ /** Counts every rendered column. */
6
+ columnIndex: number;
7
+ }
8
+ export type GridCellKeyHandler = (rowIndex: number, columnIndex: number, event: KeyboardEvent<HTMLElement>) => void;
9
+ export interface UseGridKeyboardOptions {
10
+ /** The rows focus can reach, the header row included. */
11
+ rowCount: number;
12
+ columnCount: number;
13
+ /** How many rows Page Up and Page Down move; called from key handlers only. */
14
+ getPageSize: () => number;
15
+ /**
16
+ * Enter or Space on a focused cell. Calling `event.preventDefault()` claims the key; an Enter left
17
+ * unclaimed moves focus into the cell's controls, if it has any. Space is claimed afterwards
18
+ * either way, so that it never scrolls the body.
19
+ */
20
+ onActivate: GridCellKeyHandler;
21
+ /** The context menu key or Shift+F10 on a focused cell. */
22
+ onContextMenu: GridCellKeyHandler;
23
+ /** Scrolls a body entry (`rowIndex - 1`) into view, so that it renders. */
24
+ scrollToEntry: (entryIndex: number) => void;
25
+ }
26
+ export interface GridCellProps {
27
+ tabIndex: number;
28
+ onKeyDown: (event: KeyboardEvent<HTMLElement>) => void;
29
+ onFocus: (event: FocusEvent<HTMLElement>) => void;
30
+ onBlur: (event: FocusEvent<HTMLElement>) => void;
31
+ 'data-focused': '' | undefined;
32
+ }
33
+ /** The props of the cell at a position; a cell spanning several columns gives its `columnSpan`. */
34
+ export type GetCellProps = (rowIndex: number, columnIndex: number, columnSpan?: number) => GridCellProps;
35
+ /**
36
+ * What counts as a control inside a cell. Controls are out of the tab order until the user enters
37
+ * their cell, and a click on one is not a click on its row.
38
+ */
39
+ export declare const cellControlSelector = "button, a[href], input, select, textarea, [role=\"button\"], [tabindex]";
40
+ /**
41
+ * Roving focus for a grid, per the WAI-ARIA data grid pattern: one cell is the tab stop, the arrow
42
+ * keys, Home, End and the page keys move it, and Enter or F2 moves into a cell's controls, from
43
+ * which Escape returns. The focused position is clamped to the grid's bounds on every render, so
44
+ * rows or columns going away leave focus at the same position.
45
+ */
46
+ export declare function useGridKeyboard({ rowCount, columnCount, getPageSize, onActivate, onContextMenu, scrollToEntry, }: UseGridKeyboardOptions): {
47
+ focusedCell: GridCellPosition;
48
+ getCellProps: GetCellProps;
49
+ gridRef: RefObject<HTMLTableElement | null>;
50
+ };