@calcifer-design/ui 0.7.0 → 0.9.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 (154) hide show
  1. package/dist/components/Alert/Alert.module.js +5 -5
  2. package/dist/components/Alert/Alert_module.css +14 -14
  3. package/dist/components/Avatar/Avatar.module.js +3 -3
  4. package/dist/components/Avatar/Avatar_module.css +15 -15
  5. package/dist/components/AvatarGroup/AvatarGroup.module.js +4 -4
  6. package/dist/components/AvatarGroup/AvatarGroup_module.css +10 -10
  7. package/dist/components/Breadcrumb/Breadcrumb.module.js +6 -6
  8. package/dist/components/Breadcrumb/Breadcrumb_module.css +7 -7
  9. package/dist/components/Button/Button.module.js +6 -6
  10. package/dist/components/Button/Button_module.css +32 -32
  11. package/dist/components/Card/Card.module.js +5 -5
  12. package/dist/components/Card/Card_module.css +7 -7
  13. package/dist/components/CardList/CardList.module.js +3 -3
  14. package/dist/components/CardList/CardList_module.css +3 -3
  15. package/dist/components/Checkbox/Checkbox.module.js +2 -2
  16. package/dist/components/Checkbox/Checkbox_module.css +3 -3
  17. package/dist/components/ChoiceCard/ChoiceCard.module.js +8 -8
  18. package/dist/components/ChoiceCard/ChoiceCard_module.css +25 -25
  19. package/dist/components/Collapsible/Collapsible.module.js +6 -6
  20. package/dist/components/Collapsible/Collapsible_module.css +11 -11
  21. package/dist/components/DataGrid/DataGrid.d.ts +1 -1
  22. package/dist/components/DataGrid/DataGrid.js +149 -64
  23. package/dist/components/DataGrid/DataGrid.module.js +45 -32
  24. package/dist/components/DataGrid/DataGrid_module.css +202 -70
  25. package/dist/components/DataGrid/GridCardHeader.d.ts +40 -4
  26. package/dist/components/DataGrid/GridCardHeader.js +79 -11
  27. package/dist/components/DataGrid/GridChoiceFilter.d.ts +21 -0
  28. package/dist/components/DataGrid/GridChoiceFilter.js +157 -0
  29. package/dist/components/DataGrid/GridFilterRow.d.ts +22 -0
  30. package/dist/components/DataGrid/GridFilterRow.js +66 -0
  31. package/dist/components/DataGrid/GridHeaderCell.d.ts +5 -2
  32. package/dist/components/DataGrid/GridHeaderCell.js +4 -3
  33. package/dist/components/DataGrid/GridHeaderRow.d.ts +3 -1
  34. package/dist/components/DataGrid/GridHeaderRow.js +2 -1
  35. package/dist/components/DataGrid/GridRow.d.ts +8 -4
  36. package/dist/components/DataGrid/GridRow.js +4 -4
  37. package/dist/components/DataGrid/GridSearch.d.ts +19 -0
  38. package/dist/components/DataGrid/GridSearch.js +32 -0
  39. package/dist/components/DataGrid/GridStateRows.d.ts +36 -9
  40. package/dist/components/DataGrid/GridStateRows.js +34 -18
  41. package/dist/components/DataGrid/GridTextFilter.d.ts +14 -0
  42. package/dist/components/DataGrid/GridTextFilter.js +21 -0
  43. package/dist/components/DataGrid/columns.d.ts +31 -8
  44. package/dist/components/DataGrid/labels.d.ts +24 -0
  45. package/dist/components/DataGrid/labels.js +14 -0
  46. package/dist/components/DataGrid/query.d.ts +40 -0
  47. package/dist/components/DataGrid/query.js +128 -0
  48. package/dist/components/DataGrid/types.d.ts +52 -7
  49. package/dist/components/DataGrid/useDebouncedDraft.d.ts +20 -0
  50. package/dist/components/DataGrid/useDebouncedDraft.js +71 -0
  51. package/dist/components/DataGrid/useGridEntries.d.ts +3 -2
  52. package/dist/components/DataGrid/useGridKeyboard.d.ts +17 -7
  53. package/dist/components/DataGrid/useGridKeyboard.js +18 -8
  54. package/dist/components/DataGrid/useGridMetrics.d.ts +4 -1
  55. package/dist/components/DataGrid/useGridMetrics.js +4 -0
  56. package/dist/components/DataGrid/useGridQuery.d.ts +48 -0
  57. package/dist/components/DataGrid/useGridQuery.js +71 -0
  58. package/dist/components/DataTable/DataTable.module.js +9 -9
  59. package/dist/components/DataTable/DataTable_module.css +19 -19
  60. package/dist/components/DatePicker/DatePicker.js +3 -0
  61. package/dist/components/DatePicker/DatePicker.module.js +10 -10
  62. package/dist/components/DatePicker/DatePicker_module.css +18 -18
  63. package/dist/components/Descriptions/Descriptions.module.js +4 -4
  64. package/dist/components/Descriptions/Descriptions_module.css +8 -8
  65. package/dist/components/Dialog/Dialog.js +1 -0
  66. package/dist/components/Dialog/Dialog.module.js +8 -8
  67. package/dist/components/Dialog/Dialog_module.css +15 -15
  68. package/dist/components/EmptyState/EmptyState.module.js +5 -5
  69. package/dist/components/EmptyState/EmptyState_module.css +10 -10
  70. package/dist/components/ErrorBoundary/ErrorBoundary.module.js +1 -1
  71. package/dist/components/ErrorBoundary/ErrorBoundary_module.css +1 -1
  72. package/dist/components/Field/PickerField.module.js +4 -4
  73. package/dist/components/Field/PickerField_module.css +7 -7
  74. package/dist/components/FilterBar/FilterBar.module.js +9 -9
  75. package/dist/components/FilterBar/FilterBar_module.css +13 -13
  76. package/dist/components/Form/Form.module.js +1 -1
  77. package/dist/components/Form/Form_module.css +1 -1
  78. package/dist/components/IconButton/IconButton.d.ts +12 -1
  79. package/dist/components/IconButton/IconButton.js +19 -9
  80. package/dist/components/IconButton/IconButton.module.js +3 -2
  81. package/dist/components/IconButton/IconButton_module.css +68 -14
  82. package/dist/components/Menu/Menu.module.js +2 -2
  83. package/dist/components/Menu/Menu_module.css +4 -4
  84. package/dist/components/NavMenu/NavMenu.module.js +6 -6
  85. package/dist/components/NavMenu/NavMenu_module.css +12 -12
  86. package/dist/components/PageHeading/PageHeading.module.js +3 -3
  87. package/dist/components/PageHeading/PageHeading_module.css +8 -8
  88. package/dist/components/PageShell/PageShell.module.js +5 -5
  89. package/dist/components/PageShell/PageShell_module.css +9 -9
  90. package/dist/components/Popover/Popover.module.js +2 -2
  91. package/dist/components/Popover/Popover_module.css +2 -2
  92. package/dist/components/ProgressBar/ProgressBar.module.js +8 -8
  93. package/dist/components/ProgressBar/ProgressBar_module.css +19 -19
  94. package/dist/components/RadioGroup/RadioGroup.module.js +2 -2
  95. package/dist/components/RadioGroup/RadioGroup_module.css +2 -2
  96. package/dist/components/SearchField/SearchField.module.js +4 -4
  97. package/dist/components/SearchField/SearchField_module.css +7 -7
  98. package/dist/components/Segmented/Segmented.module.js +4 -4
  99. package/dist/components/Segmented/Segmented_module.css +13 -13
  100. package/dist/components/Select/Select.module.js +5 -5
  101. package/dist/components/Select/Select_module.css +11 -11
  102. package/dist/components/Skeleton/Skeleton.module.js +3 -3
  103. package/dist/components/Skeleton/Skeleton_module.css +7 -7
  104. package/dist/components/SkipLink/SkipLink.module.js +1 -1
  105. package/dist/components/SkipLink/SkipLink_module.css +2 -2
  106. package/dist/components/Spinner/Spinner.module.js +3 -3
  107. package/dist/components/Spinner/Spinner_module.css +7 -7
  108. package/dist/components/StatusDot/StatusDot.module.js +5 -5
  109. package/dist/components/StatusDot/StatusDot_module.css +11 -11
  110. package/dist/components/Steps/Steps.module.js +6 -6
  111. package/dist/components/Steps/Steps_module.css +19 -19
  112. package/dist/components/Switch/Switch.module.js +2 -2
  113. package/dist/components/Switch/Switch_module.css +5 -5
  114. package/dist/components/TabBar/TabBar.module.js +7 -7
  115. package/dist/components/TabBar/TabBar_module.css +13 -13
  116. package/dist/components/Tabs/Tabs.module.js +4 -4
  117. package/dist/components/Tabs/Tabs_module.css +6 -6
  118. package/dist/components/Tag/Tag.module.js +1 -1
  119. package/dist/components/Tag/Tag_module.css +2 -2
  120. package/dist/components/TextArea/TextArea.module.js +1 -1
  121. package/dist/components/TextArea/TextArea_module.css +3 -3
  122. package/dist/components/ThemeScope/ThemeScope.module.js +2 -2
  123. package/dist/components/ThemeScope/ThemeScope_module.css +2 -2
  124. package/dist/components/Timeline/Timeline.module.js +8 -8
  125. package/dist/components/Timeline/Timeline_module.css +13 -13
  126. package/dist/components/ToastRegion/ToastRegion.module.js +6 -6
  127. package/dist/components/ToastRegion/ToastRegion_module.css +15 -15
  128. package/dist/components/ToggleChip/ToggleChip.module.js +5 -5
  129. package/dist/components/ToggleChip/ToggleChip_module.css +14 -14
  130. package/dist/components/Toolbar/Toolbar.module.js +3 -3
  131. package/dist/components/Toolbar/Toolbar_module.css +5 -5
  132. package/dist/components/Tree/Tree.module.js +8 -8
  133. package/dist/components/Tree/Tree_module.css +20 -20
  134. package/dist/components/TreeSelect/TreeSelect.module.js +3 -3
  135. package/dist/components/TreeSelect/TreeSelect_module.css +4 -4
  136. package/dist/components/Upload/Upload.module.js +8 -8
  137. package/dist/components/Upload/Upload_module.css +16 -16
  138. package/dist/components/ViewField/ViewField.module.js +2 -2
  139. package/dist/components/ViewField/ViewField_module.css +3 -3
  140. package/dist/icons/FilterIcon.d.ts +6 -0
  141. package/dist/icons/FilterIcon.js +17 -0
  142. package/dist/index.d.ts +2 -1
  143. package/dist/index.js +1 -0
  144. package/dist/styles/a11y.module.js +1 -1
  145. package/dist/styles/a11y_module.css +1 -1
  146. package/dist/styles/closeCircle.module.js +1 -1
  147. package/dist/styles/closeCircle_module.css +2 -2
  148. package/dist/styles/field.module.js +14 -14
  149. package/dist/styles/field_module.css +35 -35
  150. package/dist/styles/pair.module.js +2 -2
  151. package/dist/styles/pair_module.css +3 -3
  152. package/dist/styles/popup.module.js +5 -5
  153. package/dist/styles/popup_module.css +17 -17
  154. package/package.json +2 -2
@@ -1,10 +1,25 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useLayoutEffect, useRef } from "react";
3
+ import { FilterIcon } from "../../icons/FilterIcon.js";
2
4
  import { RefreshIcon } from "../../icons/RefreshIcon.js";
5
+ import { SearchIcon } from "../../icons/SearchIcon.js";
3
6
  import { IconButton } from "../IconButton/IconButton.js";
7
+ import { Segmented } from "../Segmented/Segmented.js";
4
8
  import { Toolbar, ToolbarButton } from "../Toolbar/Toolbar.js";
5
9
  import DataGrid_module from "./DataGrid.module.js";
6
- function GridCardHeader({ heading, headingLevel, headingId, actions, onRefresh, refreshing, toolbarLabel, refreshLabel }) {
10
+ import { GridSearch } from "./GridSearch.js";
11
+ function GridCardHeader({ heading, headingLevel, headingId, actions, onRefresh, refreshing, toolbarLabel, refreshLabel, search, onToggleFilters, filtersOpen, filtersLabel, filterCount, showMatchMode, matchMode, onMatchModeChange, matchModeLabel, matchAllLabel, matchAnyLabel }) {
7
12
  const HeadingTag = `h${headingLevel}`;
13
+ const hasToolbar = void 0 !== search || void 0 !== onToggleFilters || void 0 !== onRefresh;
14
+ const clusterRef = useRef(null);
15
+ const pendingFocusRef = useRef(null);
16
+ useLayoutEffect(()=>{
17
+ const target = pendingFocusRef.current;
18
+ if (null === target) return;
19
+ pendingFocusRef.current = null;
20
+ const selector = 'field' === target ? '[data-grid-search-field]' : '[data-grid-search-button]';
21
+ clusterRef.current?.querySelector(selector)?.focus();
22
+ });
8
23
  return /*#__PURE__*/ jsxs("header", {
9
24
  className: DataGrid_module.header,
10
25
  children: [
@@ -13,20 +28,73 @@ function GridCardHeader({ heading, headingLevel, headingId, actions, onRefresh,
13
28
  className: DataGrid_module.heading,
14
29
  children: heading
15
30
  }),
16
- onRefresh || actions ? /*#__PURE__*/ jsxs("div", {
31
+ hasToolbar || actions ? /*#__PURE__*/ jsxs("div", {
32
+ ref: clusterRef,
17
33
  className: DataGrid_module.cluster,
18
34
  children: [
19
- onRefresh ? /*#__PURE__*/ jsx(Toolbar, {
35
+ search?.open ? /*#__PURE__*/ jsx(GridSearch, {
36
+ label: search.fieldLabel,
37
+ clearLabel: search.clearLabel,
38
+ value: search.value,
39
+ onSearchChange: search.onSearchChange,
40
+ onClose: ()=>{
41
+ pendingFocusRef.current = 'button';
42
+ search.onClose();
43
+ },
44
+ onFocus: search.onFieldFocus
45
+ }) : null,
46
+ hasToolbar ? /*#__PURE__*/ jsxs(Toolbar, {
20
47
  "aria-label": toolbarLabel,
21
- children: /*#__PURE__*/ jsx(ToolbarButton, {
22
- loading: refreshing,
23
- onClick: ()=>onRefresh(),
24
- render: /*#__PURE__*/ jsx(IconButton, {
25
- label: refreshLabel,
48
+ children: [
49
+ search ? /*#__PURE__*/ jsx(ToolbarButton, {
50
+ "data-grid-search-button": "",
51
+ onClick: ()=>{
52
+ if (!search.open) pendingFocusRef.current = 'field';
53
+ search.onToggle();
54
+ },
55
+ render: /*#__PURE__*/ jsx(IconButton, {
56
+ label: search.buttonLabel,
57
+ size: "sm",
58
+ pressed: search.open,
59
+ children: /*#__PURE__*/ jsx(SearchIcon, {})
60
+ })
61
+ }) : null,
62
+ showMatchMode ? /*#__PURE__*/ jsx(Segmented, {
63
+ "aria-label": matchModeLabel,
26
64
  size: "sm",
27
- children: /*#__PURE__*/ jsx(RefreshIcon, {})
28
- })
29
- })
65
+ options: [
66
+ {
67
+ value: 'all',
68
+ label: matchAllLabel
69
+ },
70
+ {
71
+ value: 'any',
72
+ label: matchAnyLabel
73
+ }
74
+ ],
75
+ value: matchMode,
76
+ onValueChange: (value)=>onMatchModeChange('any' === value ? 'any' : 'all')
77
+ }) : null,
78
+ onToggleFilters ? /*#__PURE__*/ jsx(ToolbarButton, {
79
+ onClick: ()=>onToggleFilters(),
80
+ render: /*#__PURE__*/ jsx(IconButton, {
81
+ label: filtersLabel,
82
+ size: "sm",
83
+ pressed: filtersOpen,
84
+ badge: filterCount,
85
+ children: /*#__PURE__*/ jsx(FilterIcon, {})
86
+ })
87
+ }) : null,
88
+ onRefresh ? /*#__PURE__*/ jsx(ToolbarButton, {
89
+ loading: refreshing,
90
+ onClick: ()=>onRefresh(),
91
+ render: /*#__PURE__*/ jsx(IconButton, {
92
+ label: refreshLabel,
93
+ size: "sm",
94
+ children: /*#__PURE__*/ jsx(RefreshIcon, {})
95
+ })
96
+ }) : null
97
+ ]
30
98
  }) : null,
31
99
  actions ? /*#__PURE__*/ jsx("div", {
32
100
  className: DataGrid_module.actions,
@@ -0,0 +1,21 @@
1
+ import type { DataGridFilterOption } from './columns.js';
2
+ export interface GridChoiceFilterProps {
3
+ /** "Filter by <column>". */
4
+ label: string;
5
+ options: readonly DataGridFilterOption[];
6
+ multiple: boolean;
7
+ /** One value, several, or none. */
8
+ value: string | readonly string[] | undefined;
9
+ /** Called at once, with undefined for "All". */
10
+ onValueChange: (value: string | string[] | undefined) => void;
11
+ allLabel: string;
12
+ selectedCountLabel: (count: number) => string;
13
+ noOptionsLabel: string;
14
+ }
15
+ /**
16
+ * A column's select or multi-select filter in the filter strip: a combobox whose list starts with
17
+ * "All". Typing narrows the list; choosing an item applies at once. A select's input shows its
18
+ * choice; a multi-select's input holds what is typed, and its placeholder, which is also its
19
+ * description, sums up the choice.
20
+ */
21
+ export declare function GridChoiceFilter({ label, options, multiple, value, onValueChange, allLabel, selectedCountLabel, noOptionsLabel, }: GridChoiceFilterProps): import("react").JSX.Element;
@@ -0,0 +1,157 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Combobox } from "@base-ui/react/combobox";
3
+ import { useId, useMemo, useRef, useState } from "react";
4
+ import { CheckIcon } from "../../icons/CheckIcon.js";
5
+ import { ChevronDownIcon } from "../../icons/ChevronDownIcon.js";
6
+ import a11y_module from "../../styles/a11y.module.js";
7
+ import field_module from "../../styles/field.module.js";
8
+ import popup_module from "../../styles/popup.module.js";
9
+ import { usePortalContainer } from "../ThemeScope/PortalContainerContext.js";
10
+ import DataGrid_module from "./DataGrid.module.js";
11
+ function isSameItem(first, second) {
12
+ return first.value === second.value;
13
+ }
14
+ function GridChoiceFilter({ label, options, multiple, value, onValueChange, allLabel, selectedCountLabel, noOptionsLabel }) {
15
+ const summaryId = useId();
16
+ const container = usePortalContainer();
17
+ const [open, setOpen] = useState(false);
18
+ const { contains } = Combobox.useFilter();
19
+ const allItem = useMemo(()=>({
20
+ value: null,
21
+ label: allLabel
22
+ }), [
23
+ allLabel
24
+ ]);
25
+ const items = useMemo(()=>[
26
+ allItem,
27
+ ...options
28
+ ], [
29
+ allItem,
30
+ options
31
+ ]);
32
+ const chosenItems = useMemo(()=>{
33
+ const chosenValues = void 0 === value ? [] : 'string' == typeof value ? [
34
+ value
35
+ ] : value;
36
+ return chosenValues.map((chosenValue)=>options.find((option)=>option.value === chosenValue) ?? {
37
+ value: chosenValue,
38
+ label: chosenValue
39
+ });
40
+ }, [
41
+ value,
42
+ options
43
+ ]);
44
+ const [firstChosen] = chosenItems;
45
+ const summary = void 0 === firstChosen ? allLabel : 1 === chosenItems.length ? firstChosen.label : selectedCountLabel(chosenItems.length);
46
+ const selected = useMemo(()=>{
47
+ if (!multiple) return chosenItems[0] ?? allItem;
48
+ return 0 === chosenItems.length ? [
49
+ allItem
50
+ ] : chosenItems;
51
+ }, [
52
+ multiple,
53
+ chosenItems,
54
+ allItem
55
+ ]);
56
+ const pointerFocusingRef = useRef(false);
57
+ const reportChoice = (next)=>{
58
+ if (!Array.isArray(next)) return void onValueChange(next?.value ?? void 0);
59
+ const pickedAll = chosenItems.length > 0 && next.some((item)=>null === item.value);
60
+ const nextValues = next.flatMap((item)=>null === item.value ? [] : [
61
+ item.value
62
+ ]);
63
+ onValueChange(pickedAll || 0 === nextValues.length ? void 0 : nextValues);
64
+ };
65
+ return /*#__PURE__*/ jsxs(Combobox.Root, {
66
+ multiple: multiple,
67
+ items: items,
68
+ value: selected,
69
+ onValueChange: (next, eventDetails)=>{
70
+ if ('item-press' !== eventDetails.reason) return void eventDetails.cancel();
71
+ reportChoice(next);
72
+ },
73
+ open: open,
74
+ onOpenChange: (nextOpen, eventDetails)=>{
75
+ if (!nextOpen && multiple && 'item-press' === eventDetails.reason) return void eventDetails.cancel();
76
+ setOpen(nextOpen);
77
+ },
78
+ itemToStringLabel: (item)=>item.label,
79
+ isItemEqualToValue: isSameItem,
80
+ filter: (item, query)=>null !== item.value && contains(item.label, query),
81
+ children: [
82
+ /*#__PURE__*/ jsxs("div", {
83
+ className: DataGrid_module.choiceFilter,
84
+ children: [
85
+ /*#__PURE__*/ jsx(Combobox.Input, {
86
+ className: `${field_module.control} ${DataGrid_module.choiceInput}`,
87
+ "aria-label": label,
88
+ size: 1,
89
+ placeholder: multiple ? summary : void 0,
90
+ "aria-describedby": multiple ? summaryId : void 0,
91
+ onPointerDown: (event)=>{
92
+ pointerFocusingRef.current = document.activeElement !== event.currentTarget;
93
+ },
94
+ onFocus: (event)=>{
95
+ const focusedByPointer = pointerFocusingRef.current;
96
+ pointerFocusingRef.current = false;
97
+ if (multiple) return;
98
+ const input = event.currentTarget;
99
+ input.select();
100
+ if (!focusedByPointer) return;
101
+ const textAtFocus = input.value;
102
+ requestAnimationFrame(()=>{
103
+ if (document.activeElement === input && input.value === textAtFocus) input.select();
104
+ });
105
+ },
106
+ onKeyDown: (event)=>{
107
+ if ('Enter' === event.key) event.preventDefault();
108
+ if ('Escape' === event.key && !open) event.preventBaseUIHandler();
109
+ }
110
+ }),
111
+ /*#__PURE__*/ jsx(Combobox.Trigger, {
112
+ className: DataGrid_module.choiceTrigger,
113
+ "aria-hidden": "true",
114
+ children: /*#__PURE__*/ jsx(ChevronDownIcon, {})
115
+ })
116
+ ]
117
+ }),
118
+ multiple ? /*#__PURE__*/ jsx("span", {
119
+ id: summaryId,
120
+ className: a11y_module.visuallyHidden,
121
+ children: summary
122
+ }) : null,
123
+ /*#__PURE__*/ jsx(Combobox.Portal, {
124
+ container: container,
125
+ children: /*#__PURE__*/ jsx(Combobox.Positioner, {
126
+ className: popup_module.layer,
127
+ align: "start",
128
+ sideOffset: 8,
129
+ children: /*#__PURE__*/ jsxs(Combobox.Popup, {
130
+ className: popup_module.surface,
131
+ "data-popup": "select",
132
+ children: [
133
+ /*#__PURE__*/ jsx(Combobox.Empty, {
134
+ className: DataGrid_module.choiceEmpty,
135
+ children: noOptionsLabel
136
+ }),
137
+ /*#__PURE__*/ jsx(Combobox.List, {
138
+ children: (item)=>/*#__PURE__*/ jsxs(Combobox.Item, {
139
+ className: DataGrid_module.choiceOption,
140
+ value: item,
141
+ children: [
142
+ item.label,
143
+ /*#__PURE__*/ jsx(Combobox.ItemIndicator, {
144
+ className: DataGrid_module.choiceIndicator,
145
+ children: /*#__PURE__*/ jsx(CheckIcon, {})
146
+ })
147
+ ]
148
+ }, null === item.value ? 'all' : `option-${item.value}`)
149
+ })
150
+ ]
151
+ })
152
+ })
153
+ })
154
+ ]
155
+ });
156
+ }
157
+ export { GridChoiceFilter };
@@ -0,0 +1,22 @@
1
+ import type { Header, RowData } from '@tanstack/react-table';
2
+ import type { DataGridFeatures } from './columns.js';
3
+ import type { DataGridLabels } from './labels.js';
4
+ import type { GetCellProps } from './useGridKeyboard.js';
5
+ import type { GridQuery } from './useGridQuery.js';
6
+ export interface GridFilterRowProps<Row extends RowData> {
7
+ headers: Header<DataGridFeatures, Row, unknown>[];
8
+ columnCount: number;
9
+ /** The columns the grid renders before the columns' own cells. */
10
+ columnOffset: number;
11
+ /** Whether the row actions column follows the columns' own cells. */
12
+ hasRowActions: boolean;
13
+ query: GridQuery;
14
+ labels: DataGridLabels;
15
+ getCellProps: GetCellProps;
16
+ }
17
+ /**
18
+ * The filter strip, the second row of the header band and keyboard row 1: a cell for every column,
19
+ * holding the column's text or choice filter, or nothing for the checkbox, expand and row actions
20
+ * columns and for columns without a filter.
21
+ */
22
+ export declare function GridFilterRow<Row extends RowData>({ headers, columnCount, columnOffset, hasRowActions, query, labels, getCellProps, }: GridFilterRowProps<Row>): import("react").JSX.Element;
@@ -0,0 +1,66 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import DataGrid_module from "./DataGrid.module.js";
3
+ import { GridChoiceFilter } from "./GridChoiceFilter.js";
4
+ import { GridTextFilter } from "./GridTextFilter.js";
5
+ import { columnNameOf } from "./query.js";
6
+ const stripRow = 1;
7
+ function textFilterValueOf(value) {
8
+ return 'string' == typeof value ? value : '';
9
+ }
10
+ function ColumnFilter({ filter, label, value, onValueChange, labels }) {
11
+ if ('text' === filter.type) return /*#__PURE__*/ jsx(GridTextFilter, {
12
+ label: label,
13
+ value: textFilterValueOf(value),
14
+ onValueChange: onValueChange
15
+ });
16
+ return /*#__PURE__*/ jsx(GridChoiceFilter, {
17
+ label: label,
18
+ options: filter.options,
19
+ multiple: 'multiSelect' === filter.type,
20
+ value: value,
21
+ onValueChange: onValueChange,
22
+ allLabel: labels.filterAll,
23
+ selectedCountLabel: labels.filterSelectedCount,
24
+ noOptionsLabel: labels.filterNoOptions
25
+ });
26
+ }
27
+ function GridFilterRow({ headers, columnCount, columnOffset, hasRowActions, query, labels, getCellProps }) {
28
+ return /*#__PURE__*/ jsxs("tr", {
29
+ "aria-rowindex": stripRow + 1,
30
+ children: [
31
+ Array.from({
32
+ length: columnOffset
33
+ }, (_unused, columnIndex)=>/*#__PURE__*/ jsx("td", {
34
+ role: "gridcell",
35
+ className: `${DataGrid_module.filterCell} ${DataGrid_module.pinnedFilter} ${DataGrid_module.leadingFilter}`,
36
+ "aria-colindex": columnIndex + 1,
37
+ ...getCellProps(stripRow, columnIndex)
38
+ }, `leading-${columnIndex}`)),
39
+ headers.map((header, index)=>{
40
+ const columnIndex = index + columnOffset;
41
+ const column = header.column.columnDef;
42
+ const columnId = header.column.id;
43
+ return /*#__PURE__*/ jsx("td", {
44
+ role: "gridcell",
45
+ className: DataGrid_module.filterCell,
46
+ "aria-colindex": columnIndex + 1,
47
+ ...getCellProps(stripRow, columnIndex),
48
+ children: void 0 !== column.filter ? /*#__PURE__*/ jsx(ColumnFilter, {
49
+ filter: column.filter,
50
+ label: labels.filterBy(columnNameOf(column)),
51
+ value: query.query.filters[columnId],
52
+ onValueChange: (value)=>query.setFilter(columnId, value),
53
+ labels: labels
54
+ }) : null
55
+ }, header.id);
56
+ }),
57
+ hasRowActions ? /*#__PURE__*/ jsx("td", {
58
+ role: "gridcell",
59
+ className: `${DataGrid_module.filterCell} ${DataGrid_module.pinnedFilter} ${DataGrid_module.actionsFilter}`,
60
+ "aria-colindex": columnCount,
61
+ ...getCellProps(stripRow, columnCount - 1)
62
+ }) : null
63
+ ]
64
+ });
65
+ }
66
+ export { GridFilterRow };
@@ -3,12 +3,15 @@ import type { DataGridFeatures } from './columns.js';
3
3
  import type { GridCellProps } from './useGridKeyboard.js';
4
4
  export interface GridHeaderCellProps<Row extends RowData> {
5
5
  header: Header<DataGridFeatures, Row, unknown>;
6
+ /** Whether a press sorts; without it the cell still reports the column's sort. */
7
+ sortable: boolean;
6
8
  /** Counted from 1 across every rendered column. */
7
9
  ariaColIndex: number;
8
10
  cellProps: GridCellProps;
9
11
  }
10
12
  /**
11
13
  * A column's header cell. The cell is the sort control: a click sorts, and so does Enter. A column
12
- * that cannot sort claims no sort order, whatever the sorting state says.
14
+ * that cannot sort claims no sort order, whatever the sorting state says. A column the query sorts
15
+ * but the user may not (a read-only query) reports its order and offers no control.
13
16
  */
14
- export declare function GridHeaderCell<Row extends RowData>({ header, ariaColIndex, cellProps, }: GridHeaderCellProps<Row>): import("react").JSX.Element;
17
+ export declare function GridHeaderCell<Row extends RowData>({ header, sortable, ariaColIndex, cellProps, }: GridHeaderCellProps<Row>): import("react").JSX.Element;
@@ -5,9 +5,10 @@ const ariaSortByDirection = {
5
5
  asc: 'ascending',
6
6
  desc: 'descending'
7
7
  };
8
- function GridHeaderCell({ header, ariaColIndex, cellProps }) {
9
- const canSort = header.column.getCanSort();
10
- const sortDirection = canSort && header.column.getIsSorted();
8
+ function GridHeaderCell({ header, sortable, ariaColIndex, cellProps }) {
9
+ const sortApplies = header.column.getCanSort();
10
+ const sortDirection = sortApplies && header.column.getIsSorted();
11
+ const canSort = sortable && sortApplies;
11
12
  return /*#__PURE__*/ jsxs("th", {
12
13
  scope: "col",
13
14
  className: DataGrid_module.headerCell,
@@ -20,6 +20,8 @@ export interface GridHeaderRowProps<Row extends RowData> {
20
20
  columnCount: number;
21
21
  /** The columns the grid renders before the row's own cells. */
22
22
  columnOffset: number;
23
+ /** Whether the headers sort when pressed; a read-only query still shows its sort. */
24
+ sortable: boolean;
23
25
  /** The checkbox column's select-all cell; absent without checkbox selection. */
24
26
  selectAll?: GridHeaderSelectAll;
25
27
  /** The expand column's unseen name; absent without expandable rows. */
@@ -32,4 +34,4 @@ export interface GridHeaderRowProps<Row extends RowData> {
32
34
  * The header row, keyboard row 0: the select-all cell when rows are selectable, the expand column's
33
35
  * header when they expand, the columns' own headers, then the row actions header.
34
36
  */
35
- export declare function GridHeaderRow<Row extends RowData>({ headers, columnCount, columnOffset, selectAll, expandLabel, rowActions, getCellProps, }: GridHeaderRowProps<Row>): import("react").JSX.Element;
37
+ export declare function GridHeaderRow<Row extends RowData>({ headers, columnCount, columnOffset, sortable, selectAll, expandLabel, rowActions, getCellProps, }: GridHeaderRowProps<Row>): import("react").JSX.Element;
@@ -6,7 +6,7 @@ import { GridHeaderCell } from "./GridHeaderCell.js";
6
6
  function isEmptyNode(node) {
7
7
  return null == node || false === node || '' === node;
8
8
  }
9
- function GridHeaderRow({ headers, columnCount, columnOffset, selectAll, expandLabel, rowActions, getCellProps }) {
9
+ function GridHeaderRow({ headers, columnCount, columnOffset, sortable, selectAll, expandLabel, rowActions, getCellProps }) {
10
10
  const expandColumn = selectAll ? 1 : 0;
11
11
  return /*#__PURE__*/ jsxs("tr", {
12
12
  "aria-rowindex": 1,
@@ -37,6 +37,7 @@ function GridHeaderRow({ headers, columnCount, columnOffset, selectAll, expandLa
37
37
  }) : null,
38
38
  headers.map((header, columnIndex)=>/*#__PURE__*/ jsx(GridHeaderCell, {
39
39
  header: header,
40
+ sortable: sortable,
40
41
  ariaColIndex: columnIndex + 1 + columnOffset,
41
42
  cellProps: getCellProps(0, columnIndex + columnOffset)
42
43
  }, header.id)),
@@ -24,8 +24,10 @@ export interface GridRowExpander {
24
24
  }
25
25
  export interface GridRowProps<Row extends RowData> {
26
26
  row: TableRow<DataGridFeatures, Row>;
27
- /** The row's place among the grid's entries; its keyboard row is one more. */
27
+ /** The row's place among the grid's entries; its keyboard row is `firstEntryRow` more. */
28
28
  entryIndex: number;
29
+ /** The keyboard row of entry 0: the grid's `headRowCount`. */
30
+ firstEntryRow: number;
29
31
  measureRef: (element: HTMLTableRowElement | null) => void;
30
32
  density: DataGridDensity;
31
33
  /** The columns the grid renders before the row's own cells. */
@@ -49,10 +51,12 @@ export interface GridRowProps<Row extends RowData> {
49
51
  * One body row: the checkbox cell when rows are selectable, the expand cell when they expand, the
50
52
  * row's own cells, then the row actions cell.
51
53
  */
52
- export declare function GridRow<Row extends RowData>({ row, entryIndex, measureRef, density, columnOffset, highlighted, clickable, checkbox, expander, renderRowActions, getCellProps, onClick, onDoubleClick, onContextMenu, }: GridRowProps<Row>): import("react").JSX.Element;
54
+ export declare function GridRow<Row extends RowData>({ row, entryIndex, firstEntryRow, measureRef, density, columnOffset, highlighted, clickable, checkbox, expander, renderRowActions, getCellProps, onClick, onDoubleClick, onContextMenu, }: GridRowProps<Row>): import("react").JSX.Element;
53
55
  export interface GridDetailRowProps {
54
- /** The panel's place among the grid's entries; its keyboard row is one more. */
56
+ /** The panel's place among the grid's entries; its keyboard row is `firstEntryRow` more. */
55
57
  entryIndex: number;
58
+ /** The keyboard row of entry 0: the grid's `headRowCount`. */
59
+ firstEntryRow: number;
56
60
  measureRef: (element: HTMLTableRowElement | null) => void;
57
61
  columnCount: number;
58
62
  panelId: string;
@@ -60,7 +64,7 @@ export interface GridDetailRowProps {
60
64
  children: ReactNode;
61
65
  }
62
66
  /** An expanded row's detail panel: one cell across every column, measured like any row. */
63
- export declare function GridDetailRow({ entryIndex, measureRef, columnCount, panelId, getCellProps, children, }: GridDetailRowProps): import("react").JSX.Element;
67
+ export declare function GridDetailRow({ entryIndex, firstEntryRow, measureRef, columnCount, panelId, getCellProps, children, }: GridDetailRowProps): import("react").JSX.Element;
64
68
  export interface GridSpacerRowProps {
65
69
  height: number;
66
70
  columnCount: number;
@@ -33,8 +33,8 @@ function compactTitle(column, row) {
33
33
  const text = textValueOf(column, row);
34
34
  return void 0 === text || '' === text.trim() ? void 0 : text;
35
35
  }
36
- function GridRow({ row, entryIndex, measureRef, density, columnOffset, highlighted, clickable, checkbox, expander, renderRowActions, getCellProps, onClick, onDoubleClick, onContextMenu }) {
37
- const rowIndex = entryIndex + 1;
36
+ function GridRow({ row, entryIndex, firstEntryRow, measureRef, density, columnOffset, highlighted, clickable, checkbox, expander, renderRowActions, getCellProps, onClick, onDoubleClick, onContextMenu }) {
37
+ const rowIndex = entryIndex + firstEntryRow;
38
38
  const selecting = void 0 !== checkbox;
39
39
  const expandColumn = selecting ? 1 : 0;
40
40
  const cells = row.getAllCells();
@@ -106,8 +106,8 @@ function GridRow({ row, entryIndex, measureRef, density, columnOffset, highlight
106
106
  ]
107
107
  });
108
108
  }
109
- function GridDetailRow({ entryIndex, measureRef, columnCount, panelId, getCellProps, children }) {
110
- const rowIndex = entryIndex + 1;
109
+ function GridDetailRow({ entryIndex, firstEntryRow, measureRef, columnCount, panelId, getCellProps, children }) {
110
+ const rowIndex = entryIndex + firstEntryRow;
111
111
  return /*#__PURE__*/ jsx("tr", {
112
112
  ref: measureRef,
113
113
  "data-index": entryIndex,
@@ -0,0 +1,19 @@
1
+ export interface GridSearchProps {
2
+ /** The field's name. */
3
+ label: string;
4
+ clearLabel: string;
5
+ /** The search in the query. */
6
+ value: string;
7
+ /** Called once typing pauses, on Enter, on clearing, and when focus leaves with a change pending. */
8
+ onSearchChange: (term: string) => void;
9
+ /** Escape in the empty field: the grid closes the field. */
10
+ onClose: () => void;
11
+ onFocus: () => void;
12
+ }
13
+ /**
14
+ * The toolbar's search field, on the library's `SearchField`. What is typed applies 400ms after
15
+ * typing stops, or at once on Enter; the clear button, and Escape with text, clear it at once.
16
+ * Escape in the empty field closes it. Leaving the field applies a pending change, so that a click
17
+ * elsewhere, such as on Clear filters, acts on the query with it, as a text filter does.
18
+ */
19
+ export declare function GridSearch({ label, clearLabel, value, onSearchChange, onClose, onFocus, }: GridSearchProps): import("react").JSX.Element;
@@ -0,0 +1,32 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { SearchField } from "../SearchField/SearchField.js";
3
+ import DataGrid_module from "./DataGrid.module.js";
4
+ import { useDebouncedDraft } from "./useDebouncedDraft.js";
5
+ const searchDelayMs = 400;
6
+ function GridSearch({ label, clearLabel, value, onSearchChange, onClose, onFocus }) {
7
+ const { draft, change, flush, commitNow } = useDebouncedDraft(value, onSearchChange, searchDelayMs);
8
+ return /*#__PURE__*/ jsx(SearchField, {
9
+ label: label,
10
+ hideLabel: true,
11
+ size: "sm",
12
+ clearLabel: clearLabel,
13
+ className: DataGrid_module.search,
14
+ value: draft,
15
+ onValueChange: change,
16
+ onSubmit: (term)=>'' === term ? commitNow('') : flush(),
17
+ onKeyDown: (event)=>{
18
+ if (event.nativeEvent.isComposing || 229 === event.keyCode) return;
19
+ if ('Enter' === event.key) event.preventDefault();
20
+ if ('Escape' === event.key && '' === event.currentTarget.value) {
21
+ event.preventDefault();
22
+ event.stopPropagation();
23
+ flush();
24
+ onClose();
25
+ }
26
+ },
27
+ onFocus: onFocus,
28
+ onBlur: flush,
29
+ "data-grid-search-field": ""
30
+ });
31
+ }
32
+ export { GridSearch };
@@ -1,24 +1,51 @@
1
1
  import type { ReactNode } from 'react';
2
+ import { type EmptyStateProps } from '../EmptyState/EmptyState.js';
2
3
  import type { GetCellProps } from './useGridKeyboard.js';
3
- export type GridStateKind = 'loading' | 'empty';
4
+ /** `filteredEmpty`: there are rows, or may be, but the filters and search match none of them. */
5
+ export type GridStateKind = 'loading' | 'empty' | 'filteredEmpty';
4
6
  export interface GridStateRowProps {
5
7
  kind: GridStateKind;
6
- /** The message for `kind`. */
8
+ /** The message for `kind`, which the grid also announces. */
7
9
  label: string;
8
- /** Shown in place of the empty message. */
9
- emptyState?: ReactNode;
10
+ /** For the empty kinds: the app's own content in place of the message. */
11
+ replacement?: ReactNode;
12
+ /** For `filteredEmpty`: the button beside the message. Without it the message shows alone. */
13
+ clearFilters?: {
14
+ label: string;
15
+ onClick: () => void;
16
+ };
17
+ /**
18
+ * For `filteredEmpty`: the level of the empty state's heading. The grid passes one below an h2
19
+ * card heading and 4 under any other, the deepest the empty state takes.
20
+ */
21
+ headingLevel?: EmptyStateProps['headingLevel'];
10
22
  columnCount: number;
23
+ /** The keyboard row of entry 0: the grid's `headRowCount`. The state row sits where it would. */
24
+ firstEntryRow: number;
11
25
  }
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;
26
+ /**
27
+ * The body's only row while it loads, has no rows or shows none: one cell across every column.
28
+ * The live region speaks the message, so the visible copy of the loading and empty states is
29
+ * hidden from assistive technology. The filtered-empty state is the library's `EmptyState`, whose
30
+ * message is a heading and stays readable (a hidden heading would be an empty one), with the Clear
31
+ * filters button as its action; the button stays a tab stop, as the row is no keyboard row. The
32
+ * cell spans a table that can be wider than the scroll area, so its content keeps to the scroll
33
+ * area's width and stays in view while the body scrolls sideways.
34
+ */
35
+ export declare function GridStateRow({ kind, label, replacement, clearFilters, headingLevel, columnCount, firstEntryRow, }: GridStateRowProps): import("react").JSX.Element;
14
36
  export interface GridErrorRowProps {
15
- /** The row's place after the grid's entries; its keyboard row is one more. */
37
+ /** The row's place after the grid's entries; its keyboard row is `firstEntryRow` more. */
16
38
  entryIndex: number;
39
+ /** The keyboard row of entry 0: the grid's `headRowCount`. */
40
+ firstEntryRow: number;
17
41
  columnCount: number;
18
42
  message: string;
19
43
  retryLabel: string;
20
44
  onRetry: () => void;
21
45
  getCellProps: GetCellProps;
22
46
  }
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;
47
+ /**
48
+ * A failed load in server mode: the error and a retry button, after the last entry. As in the
49
+ * state row, the content keeps to the scroll area's width so that it stays in view.
50
+ */
51
+ export declare function GridErrorRow({ entryIndex, firstEntryRow, columnCount, message, retryLabel, onRetry, getCellProps, }: GridErrorRowProps): import("react").JSX.Element;