@navikt/ds-react 8.10.6 → 8.11.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.
- package/cjs/data/drag-and-drop/root/DragAndDropRoot.d.ts +1 -1
- package/cjs/data/drag-and-drop/root/DragAndDropRoot.js +2 -2
- package/cjs/data/drag-and-drop/root/DragAndDropRoot.js.map +1 -1
- package/cjs/data/stories/Data.test-data.d.ts +2 -2
- package/cjs/data/stories/Data.test-data.js +37 -42
- package/cjs/data/stories/Data.test-data.js.map +1 -1
- package/cjs/data/table/base-cell/DataTableBaseCell.d.ts +4 -4
- package/cjs/data/table/base-cell/DataTableBaseCell.js +2 -2
- package/cjs/data/table/base-cell/DataTableBaseCell.js.map +1 -1
- package/cjs/data/table/column-header/DataTableColumnHeader.d.ts +3 -15
- package/cjs/data/table/column-header/DataTableColumnHeader.js +8 -5
- package/cjs/data/table/column-header/DataTableColumnHeader.js.map +1 -1
- package/cjs/data/table/column-header/useTableColumnResize.d.ts +2 -2
- package/cjs/data/table/column-header/useTableColumnResize.js +10 -10
- package/cjs/data/table/column-header/useTableColumnResize.js.map +1 -1
- package/cjs/data/table/helpers/collectTableRowEntries.d.ts +1 -1
- package/cjs/data/table/helpers/selection/getMultipleSelectProps.d.ts +6 -5
- package/cjs/data/table/helpers/selection/getMultipleSelectProps.js +6 -2
- package/cjs/data/table/helpers/selection/getMultipleSelectProps.js.map +1 -1
- package/cjs/data/table/helpers/selection/getSingleSelectProps.d.ts +3 -3
- package/cjs/data/table/helpers/selection/getSingleSelectProps.js +1 -1
- package/cjs/data/table/helpers/selection/getSingleSelectProps.js.map +1 -1
- package/cjs/data/table/helpers/selection/selection.types.d.ts +19 -27
- package/cjs/data/table/helpers/selection/selection.utils.d.ts +1 -1
- package/cjs/data/table/hooks/useColumnOptions.d.ts +3 -3
- package/cjs/data/table/hooks/useColumnOptions.js +2 -2
- package/cjs/data/table/hooks/useColumnOptions.js.map +1 -1
- package/cjs/data/table/hooks/useTableDetailsPanel.d.ts +8 -9
- package/cjs/data/table/hooks/useTableDetailsPanel.js.map +1 -1
- package/cjs/data/table/hooks/useTableItems.d.ts +10 -11
- package/cjs/data/table/hooks/useTableItems.js +11 -3
- package/cjs/data/table/hooks/useTableItems.js.map +1 -1
- package/cjs/data/table/hooks/useTableSelection.d.ts +2 -1
- package/cjs/data/table/hooks/useTableSelection.js +46 -29
- package/cjs/data/table/hooks/useTableSelection.js.map +1 -1
- package/cjs/data/table/hooks/useTableSort.d.ts +13 -7
- package/cjs/data/table/hooks/useTableSort.js +8 -9
- package/cjs/data/table/hooks/useTableSort.js.map +1 -1
- package/cjs/data/table/index.d.ts +1 -1
- package/cjs/data/table/index.js +3 -23
- package/cjs/data/table/index.js.map +1 -1
- package/cjs/data/table/root/{DataTable.types.d.ts → DataGridTable.types.d.ts} +16 -26
- package/cjs/data/table/root/DataGridTable.types.js +3 -0
- package/cjs/data/table/root/DataGridTable.types.js.map +1 -0
- package/cjs/data/table/root/DataGridTableRoot.d.ts +104 -0
- package/cjs/data/table/root/{DataTableRoot.js → DataGridTableRoot.js} +57 -37
- package/cjs/data/table/root/DataGridTableRoot.js.map +1 -0
- package/cjs/data/table/root/DataTableRoot.context.d.ts +6 -2
- package/cjs/data/table/root/DataTableRoot.context.js.map +1 -1
- package/cjs/data/table/tbody/DataTableTbody.js +3 -3
- package/cjs/data/table/tbody/DataTableTbody.js.map +1 -1
- package/cjs/data/table/tr/DataTableTr.d.ts +3 -3
- package/cjs/data/table/tr/DataTableTr.js +44 -20
- package/cjs/data/table/tr/DataTableTr.js.map +1 -1
- package/cjs/data/token-filter/TokenFilter.d.ts +0 -6
- package/cjs/data/token-filter/TokenFilter.js +1 -1
- package/cjs/data-grid/index.d.ts +2 -0
- package/cjs/data-grid/index.js +9 -0
- package/cjs/data-grid/index.js.map +1 -0
- package/cjs/data-grid/root/DataGrid.types.d.ts +35 -0
- package/cjs/{data/table/root/DataTable.types.js → data-grid/root/DataGrid.types.js} +1 -1
- package/cjs/data-grid/root/DataGrid.types.js.map +1 -0
- package/cjs/data-grid/root/DataGridRoot.context.d.ts +16 -0
- package/cjs/{data/data-grid → data-grid}/root/DataGridRoot.context.js +1 -1
- package/cjs/data-grid/root/DataGridRoot.context.js.map +1 -0
- package/cjs/data-grid/root/DataGridRoot.d.ts +89 -0
- package/cjs/{data/data-grid → data-grid}/root/DataGridRoot.js +33 -8
- package/cjs/data-grid/root/DataGridRoot.js.map +1 -0
- package/cjs/preview.d.ts +1 -0
- package/cjs/{data/data-grid/index.js → preview.js} +3 -3
- package/cjs/preview.js.map +1 -0
- package/cjs/table/ColumnHeader.js.map +1 -1
- package/esm/data/drag-and-drop/root/DragAndDropRoot.d.ts +1 -1
- package/esm/data/drag-and-drop/root/DragAndDropRoot.js +2 -2
- package/esm/data/drag-and-drop/root/DragAndDropRoot.js.map +1 -1
- package/esm/data/stories/Data.test-data.d.ts +2 -2
- package/esm/data/stories/Data.test-data.js +37 -42
- package/esm/data/stories/Data.test-data.js.map +1 -1
- package/esm/data/table/base-cell/DataTableBaseCell.d.ts +4 -4
- package/esm/data/table/base-cell/DataTableBaseCell.js +2 -2
- package/esm/data/table/base-cell/DataTableBaseCell.js.map +1 -1
- package/esm/data/table/column-header/DataTableColumnHeader.d.ts +3 -15
- package/esm/data/table/column-header/DataTableColumnHeader.js +8 -5
- package/esm/data/table/column-header/DataTableColumnHeader.js.map +1 -1
- package/esm/data/table/column-header/useTableColumnResize.d.ts +2 -2
- package/esm/data/table/column-header/useTableColumnResize.js +10 -10
- package/esm/data/table/column-header/useTableColumnResize.js.map +1 -1
- package/esm/data/table/helpers/collectTableRowEntries.d.ts +1 -1
- package/esm/data/table/helpers/selection/getMultipleSelectProps.d.ts +6 -5
- package/esm/data/table/helpers/selection/getMultipleSelectProps.js +6 -2
- package/esm/data/table/helpers/selection/getMultipleSelectProps.js.map +1 -1
- package/esm/data/table/helpers/selection/getSingleSelectProps.d.ts +3 -3
- package/esm/data/table/helpers/selection/getSingleSelectProps.js +1 -1
- package/esm/data/table/helpers/selection/getSingleSelectProps.js.map +1 -1
- package/esm/data/table/helpers/selection/selection.types.d.ts +19 -27
- package/esm/data/table/helpers/selection/selection.utils.d.ts +1 -1
- package/esm/data/table/hooks/useColumnOptions.d.ts +3 -3
- package/esm/data/table/hooks/useColumnOptions.js +2 -2
- package/esm/data/table/hooks/useColumnOptions.js.map +1 -1
- package/esm/data/table/hooks/useTableDetailsPanel.d.ts +8 -9
- package/esm/data/table/hooks/useTableDetailsPanel.js.map +1 -1
- package/esm/data/table/hooks/useTableItems.d.ts +10 -11
- package/esm/data/table/hooks/useTableItems.js +11 -3
- package/esm/data/table/hooks/useTableItems.js.map +1 -1
- package/esm/data/table/hooks/useTableSelection.d.ts +2 -1
- package/esm/data/table/hooks/useTableSelection.js +46 -29
- package/esm/data/table/hooks/useTableSelection.js.map +1 -1
- package/esm/data/table/hooks/useTableSort.d.ts +13 -7
- package/esm/data/table/hooks/useTableSort.js +9 -10
- package/esm/data/table/hooks/useTableSort.js.map +1 -1
- package/esm/data/table/index.d.ts +1 -1
- package/esm/data/table/index.js +1 -21
- package/esm/data/table/index.js.map +1 -1
- package/esm/data/table/root/{DataTable.types.d.ts → DataGridTable.types.d.ts} +16 -26
- package/esm/data/table/root/DataGridTable.types.js +2 -0
- package/esm/data/table/root/DataGridTable.types.js.map +1 -0
- package/esm/data/table/root/DataGridTableRoot.d.ts +104 -0
- package/esm/data/table/root/{DataTableRoot.js → DataGridTableRoot.js} +59 -38
- package/esm/data/table/root/DataGridTableRoot.js.map +1 -0
- package/esm/data/table/root/DataTableRoot.context.d.ts +6 -2
- package/esm/data/table/root/DataTableRoot.context.js.map +1 -1
- package/esm/data/table/tbody/DataTableTbody.js +3 -3
- package/esm/data/table/tbody/DataTableTbody.js.map +1 -1
- package/esm/data/table/tr/DataTableTr.d.ts +3 -3
- package/esm/data/table/tr/DataTableTr.js +44 -20
- package/esm/data/table/tr/DataTableTr.js.map +1 -1
- package/esm/data/token-filter/TokenFilter.d.ts +0 -6
- package/esm/data/token-filter/TokenFilter.js +1 -1
- package/esm/data-grid/index.d.ts +2 -0
- package/esm/data-grid/index.js +4 -0
- package/esm/data-grid/index.js.map +1 -0
- package/esm/data-grid/root/DataGrid.types.d.ts +35 -0
- package/esm/data-grid/root/DataGrid.types.js +2 -0
- package/esm/data-grid/root/DataGrid.types.js.map +1 -0
- package/esm/data-grid/root/DataGridRoot.context.d.ts +16 -0
- package/esm/{data/data-grid → data-grid}/root/DataGridRoot.context.js +1 -1
- package/esm/data-grid/root/DataGridRoot.context.js.map +1 -0
- package/esm/data-grid/root/DataGridRoot.d.ts +89 -0
- package/esm/data-grid/root/DataGridRoot.js +57 -0
- package/esm/data-grid/root/DataGridRoot.js.map +1 -0
- package/esm/preview.d.ts +1 -0
- package/esm/preview.js +3 -0
- package/esm/preview.js.map +1 -0
- package/esm/table/ColumnHeader.js.map +1 -1
- package/package.json +23 -3
- package/src/data/drag-and-drop/root/DragAndDropRoot.tsx +3 -3
- package/src/data/stories/Data.test-data.tsx +53 -51
- package/src/data/table/base-cell/DataTableBaseCell.tsx +6 -6
- package/src/data/table/column-header/DataTableColumnHeader.tsx +17 -20
- package/src/data/table/column-header/useTableColumnResize.ts +14 -14
- package/src/data/table/helpers/collectTableRowEntries.ts +1 -1
- package/src/data/table/helpers/selection/getMultipleSelectProps.ts +11 -5
- package/src/data/table/helpers/selection/getSingleSelectProps.ts +4 -4
- package/src/data/table/helpers/selection/selection.types.ts +19 -29
- package/src/data/table/helpers/selection/selection.utils.test.ts +1 -1
- package/src/data/table/helpers/selection/selection.utils.ts +1 -1
- package/src/data/table/hooks/__tests__/useTableItems.test.ts +1 -1
- package/src/data/table/hooks/useColumnOptions.ts +5 -5
- package/src/data/table/hooks/useTableDetailsPanel.tsx +14 -18
- package/src/data/table/hooks/useTableItems.ts +37 -23
- package/src/data/table/hooks/useTableSelection.ts +62 -45
- package/src/data/table/hooks/useTableSort.ts +29 -17
- package/src/data/table/index.tsx +4 -21
- package/src/data/table/root/{DataTable.types.ts → DataGridTable.types.ts} +17 -30
- package/src/data/table/root/{DataTableRoot.tsx → DataGridTableRoot.tsx} +196 -143
- package/src/data/table/root/DataTableRoot.context.ts +10 -8
- package/src/data/table/sub-row-toggle/DataTableSubRowToggle.tsx +1 -1
- package/src/data/table/tbody/DataTableTbody.tsx +3 -3
- package/src/data/table/tr/DataTableTr.tsx +51 -16
- package/src/data/token-filter/TokenFilter.tsx +1 -1
- package/src/data-grid/index.ts +3 -0
- package/src/data-grid/root/DataGrid.types.ts +36 -0
- package/src/data-grid/root/DataGridRoot.context.ts +21 -0
- package/src/data-grid/root/DataGridRoot.tsx +152 -0
- package/src/preview.ts +2 -0
- package/src/table/ColumnHeader.tsx +1 -0
- package/cjs/data/data-grid/index.d.ts +0 -2
- package/cjs/data/data-grid/index.js.map +0 -1
- package/cjs/data/data-grid/root/DataGridRoot.context.d.ts +0 -11
- package/cjs/data/data-grid/root/DataGridRoot.context.js.map +0 -1
- package/cjs/data/data-grid/root/DataGridRoot.d.ts +0 -38
- package/cjs/data/data-grid/root/DataGridRoot.js.map +0 -1
- package/cjs/data/table/root/DataTable.types.js.map +0 -1
- package/cjs/data/table/root/DataTableRoot.d.ts +0 -118
- package/cjs/data/table/root/DataTableRoot.js.map +0 -1
- package/cjs/data/table/root/DataTableRoot.legacy.d.ts +0 -172
- package/cjs/data/table/root/DataTableRoot.legacy.js +0 -118
- package/cjs/data/table/root/DataTableRoot.legacy.js.map +0 -1
- package/esm/data/data-grid/index.d.ts +0 -2
- package/esm/data/data-grid/index.js +0 -3
- package/esm/data/data-grid/index.js.map +0 -1
- package/esm/data/data-grid/root/DataGridRoot.context.d.ts +0 -11
- package/esm/data/data-grid/root/DataGridRoot.context.js.map +0 -1
- package/esm/data/data-grid/root/DataGridRoot.d.ts +0 -38
- package/esm/data/data-grid/root/DataGridRoot.js +0 -32
- package/esm/data/data-grid/root/DataGridRoot.js.map +0 -1
- package/esm/data/table/root/DataTable.types.js +0 -2
- package/esm/data/table/root/DataTable.types.js.map +0 -1
- package/esm/data/table/root/DataTableRoot.d.ts +0 -118
- package/esm/data/table/root/DataTableRoot.js.map +0 -1
- package/esm/data/table/root/DataTableRoot.legacy.d.ts +0 -172
- package/esm/data/table/root/DataTableRoot.legacy.js +0 -73
- package/esm/data/table/root/DataTableRoot.legacy.js.map +0 -1
- package/src/data/data-grid/index.ts +0 -3
- package/src/data/data-grid/root/DataGridRoot.context.ts +0 -16
- package/src/data/data-grid/root/DataGridRoot.tsx +0 -71
- package/src/data/table/Readme.md +0 -11
- package/src/data/table/agent-component-review.md +0 -175
- package/src/data/table/root/DataTableRoot.legacy.tsx +0 -305
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React, { useCallback } from "react";
|
|
2
2
|
import { createStrictContext } from "../../../utils/helpers";
|
|
3
3
|
import { useControllableState } from "../../../utils/hooks";
|
|
4
|
-
import type { TableRowEntryId } from "../root/DataTable.types";
|
|
5
4
|
import { useDataTableContext } from "../root/DataTableRoot.context";
|
|
6
5
|
|
|
7
6
|
type DetailsPanelProps<T> = {
|
|
@@ -17,18 +16,18 @@ type DetailsPanelProps<T> = {
|
|
|
17
16
|
isRowExpandable?: (rowData: T) => boolean;
|
|
18
17
|
/**
|
|
19
18
|
* Controlled list of expanded row IDs.
|
|
20
|
-
* Use with `
|
|
19
|
+
* Use with `onExpandedRowIdsChange` for controlled usage, or `defaultExpandedRowIds` for uncontrolled.
|
|
21
20
|
*/
|
|
22
|
-
expandedRowIds?:
|
|
21
|
+
expandedRowIds?: string[];
|
|
23
22
|
/**
|
|
24
23
|
* Initial list of expanded row IDs for uncontrolled usage.
|
|
25
24
|
* @default []
|
|
26
25
|
*/
|
|
27
|
-
defaultExpandedRowIds?:
|
|
26
|
+
defaultExpandedRowIds?: string[];
|
|
28
27
|
/**
|
|
29
28
|
* Called when the list of expanded row IDs changes.
|
|
30
29
|
*/
|
|
31
|
-
onExpandedRowIdsChange?: (ids:
|
|
30
|
+
onExpandedRowIdsChange?: (ids: string[]) => void; // TODO: Docs: This pattern is called "Master / Detail" in general terms
|
|
32
31
|
/**
|
|
33
32
|
* Returns the height (in px) or `"auto"` for a row's details panel.
|
|
34
33
|
* When a number is returned, the panel scrolls within that fixed height.
|
|
@@ -43,9 +42,9 @@ type DetailsPanelProps<T> = {
|
|
|
43
42
|
};
|
|
44
43
|
|
|
45
44
|
type DataTableDetailsPanelContextT = {
|
|
46
|
-
isExpanded: (id:
|
|
47
|
-
isDetailsPanelExpandable: (id:
|
|
48
|
-
toggleExpansion: (id:
|
|
45
|
+
isExpanded: (id: string) => boolean;
|
|
46
|
+
isDetailsPanelExpandable: (id: string) => boolean;
|
|
47
|
+
toggleExpansion: (id: string) => void;
|
|
49
48
|
toggleAll: () => void;
|
|
50
49
|
isAllExpanded: boolean;
|
|
51
50
|
getDetailsPanelContent?: (row: unknown) => React.ReactNode;
|
|
@@ -87,18 +86,15 @@ function DataTableDetailsPanelProvider<T>({
|
|
|
87
86
|
const tableContext = useDataTableContext(false);
|
|
88
87
|
|
|
89
88
|
const { itemDetails } = tableContext?.tableItems ?? {
|
|
90
|
-
itemDetails: new Map<
|
|
91
|
-
TableRowEntryId,
|
|
92
|
-
{ rowData: T; id: TableRowEntryId; level: number }
|
|
93
|
-
>(),
|
|
89
|
+
itemDetails: new Map<string, { rowData: T; id: string; level: number }>(),
|
|
94
90
|
};
|
|
95
91
|
|
|
96
92
|
const expandableIds = React.useMemo(() => {
|
|
97
93
|
if (!getContent) {
|
|
98
|
-
return new Set<
|
|
94
|
+
return new Set<string>();
|
|
99
95
|
}
|
|
100
96
|
|
|
101
|
-
const ids = new Set<
|
|
97
|
+
const ids = new Set<string>();
|
|
102
98
|
|
|
103
99
|
for (const { rowData, id, level } of itemDetails.values()) {
|
|
104
100
|
/* We only allow Master - Details pattern on top level rows */
|
|
@@ -115,18 +111,18 @@ function DataTableDetailsPanelProvider<T>({
|
|
|
115
111
|
}, [getContent, isRowExpandable, itemDetails]);
|
|
116
112
|
|
|
117
113
|
const isDetailsPanelExpandableById = useCallback(
|
|
118
|
-
(id:
|
|
114
|
+
(id: string) => expandableIds.has(id),
|
|
119
115
|
[expandableIds],
|
|
120
116
|
);
|
|
121
117
|
|
|
122
118
|
const isExpanded = useCallback(
|
|
123
|
-
(id:
|
|
119
|
+
(id: string) =>
|
|
124
120
|
isDetailsPanelExpandableById(id) && expandedIds.includes(id),
|
|
125
121
|
[expandedIds, isDetailsPanelExpandableById],
|
|
126
122
|
);
|
|
127
123
|
|
|
128
124
|
const toggleExpansion = useCallback(
|
|
129
|
-
(id:
|
|
125
|
+
(id: string) => {
|
|
130
126
|
if (!isDetailsPanelExpandableById(id)) {
|
|
131
127
|
return;
|
|
132
128
|
}
|
|
@@ -169,7 +165,7 @@ function DataTableDetailsPanelProvider<T>({
|
|
|
169
165
|
);
|
|
170
166
|
}
|
|
171
167
|
|
|
172
|
-
function getDataTableDetailsPanelId(tableId: string, rowId:
|
|
168
|
+
function getDataTableDetailsPanelId(tableId: string, rowId: string) {
|
|
173
169
|
return `${tableId}-expansion-${rowId}`;
|
|
174
170
|
}
|
|
175
171
|
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
type ItemDetail,
|
|
5
5
|
collectTableRowEntries,
|
|
6
6
|
} from "../helpers/collectTableRowEntries";
|
|
7
|
-
import type { TableRowEntryId } from "../root/DataTable.types";
|
|
8
7
|
|
|
9
8
|
type SubRowsProps<T> = {
|
|
10
9
|
/**
|
|
@@ -14,18 +13,18 @@ type SubRowsProps<T> = {
|
|
|
14
13
|
/**
|
|
15
14
|
* Controlled list of IDs of rows that should be expanded.
|
|
16
15
|
*/
|
|
17
|
-
expandedRowIds?:
|
|
16
|
+
expandedRowIds?: string[];
|
|
18
17
|
/**
|
|
19
18
|
* IDs of rows that should be initially expanded.
|
|
20
19
|
* Only used when `expandedRowIds` is not provided, i.e. when the expanded state is uncontrolled.
|
|
21
20
|
*/
|
|
22
|
-
defaultExpandedRowIds?:
|
|
21
|
+
defaultExpandedRowIds?: string[];
|
|
23
22
|
/**
|
|
24
23
|
* Called when the list of expanded row IDs changes.
|
|
25
24
|
*/
|
|
26
|
-
onExpandedRowIdsChange?: (ids:
|
|
25
|
+
onExpandedRowIdsChange?: (ids: string[]) => void;
|
|
27
26
|
/**
|
|
28
|
-
*
|
|
27
|
+
* Determines whether a row should be expandable.
|
|
29
28
|
* By default, all rows are expandable when `getRows` is provided.
|
|
30
29
|
*/
|
|
31
30
|
isRowExpandable?: (rowData: T) => boolean;
|
|
@@ -33,19 +32,19 @@ type SubRowsProps<T> = {
|
|
|
33
32
|
|
|
34
33
|
type UseTableItemsArgs<T> = {
|
|
35
34
|
items: T[];
|
|
36
|
-
getRowId?: (rowData: T) =>
|
|
35
|
+
getRowId?: (rowData: T) => string;
|
|
37
36
|
subRows?: SubRowsProps<T>;
|
|
38
37
|
};
|
|
39
38
|
|
|
40
39
|
type UseTableItemsReturn<T> = {
|
|
41
40
|
items: T[];
|
|
42
|
-
itemDetails: Map<
|
|
41
|
+
itemDetails: Map<string, ItemDetail<T>>;
|
|
43
42
|
/** Row ids for the rows currently rendered in the table body. */
|
|
44
|
-
visibleRowIds:
|
|
43
|
+
visibleRowIds: string[];
|
|
45
44
|
/** Direct child ids for each row, used to traverse selection groups lazily. */
|
|
46
|
-
childRowIdsById: Map<
|
|
47
|
-
onExpandedRowIdsChange: (id:
|
|
48
|
-
isSubRowExpanded: (id:
|
|
45
|
+
childRowIdsById: Map<string, string[]>;
|
|
46
|
+
onExpandedRowIdsChange: (id: string) => void;
|
|
47
|
+
isSubRowExpanded: (id: string) => boolean;
|
|
49
48
|
};
|
|
50
49
|
|
|
51
50
|
function useTableItems<T>(args: UseTableItemsArgs<T>): UseTableItemsReturn<T> {
|
|
@@ -85,9 +84,9 @@ function useTableItems<T>(args: UseTableItemsArgs<T>): UseTableItemsReturn<T> {
|
|
|
85
84
|
});
|
|
86
85
|
|
|
87
86
|
const localVisibleItems: T[] = [];
|
|
88
|
-
const localVisibleRowIds:
|
|
87
|
+
const localVisibleRowIds: string[] = [];
|
|
89
88
|
|
|
90
|
-
const addVisibleRows = (rowId:
|
|
89
|
+
const addVisibleRows = (rowId: string): string[] => {
|
|
91
90
|
const details = rowEntriesMap.get(rowId);
|
|
92
91
|
|
|
93
92
|
if (!details) {
|
|
@@ -97,7 +96,7 @@ function useTableItems<T>(args: UseTableItemsArgs<T>): UseTableItemsReturn<T> {
|
|
|
97
96
|
localVisibleItems.push(details.rowData);
|
|
98
97
|
localVisibleRowIds.push(details.id);
|
|
99
98
|
|
|
100
|
-
const visibleDescendantRowIds:
|
|
99
|
+
const visibleDescendantRowIds: string[] = [];
|
|
101
100
|
|
|
102
101
|
if (expandedIdsSet.has(details.id)) {
|
|
103
102
|
for (const childRowId of details.children) {
|
|
@@ -122,7 +121,7 @@ function useTableItems<T>(args: UseTableItemsArgs<T>): UseTableItemsReturn<T> {
|
|
|
122
121
|
}, [getRows, items, getRowId, isRowExpandable, expandedIdsSet]);
|
|
123
122
|
|
|
124
123
|
const handleExpandedSubRowIdChange = useCallback(
|
|
125
|
-
(id:
|
|
124
|
+
(id: string) => {
|
|
126
125
|
setNestedSubRowsExpandedIds((prev) =>
|
|
127
126
|
prev.includes(id)
|
|
128
127
|
? prev.filter((expandedId) => expandedId !== id)
|
|
@@ -132,14 +131,29 @@ function useTableItems<T>(args: UseTableItemsArgs<T>): UseTableItemsReturn<T> {
|
|
|
132
131
|
[setNestedSubRowsExpandedIds],
|
|
133
132
|
);
|
|
134
133
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
134
|
+
const isSubRowExpanded = useCallback(
|
|
135
|
+
(id: string) => expandedIdsSet.has(id),
|
|
136
|
+
[expandedIdsSet],
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
return useMemo(
|
|
140
|
+
() => ({
|
|
141
|
+
items: visibleItems,
|
|
142
|
+
itemDetails,
|
|
143
|
+
visibleRowIds,
|
|
144
|
+
childRowIdsById,
|
|
145
|
+
onExpandedRowIdsChange: handleExpandedSubRowIdChange,
|
|
146
|
+
isSubRowExpanded,
|
|
147
|
+
}),
|
|
148
|
+
[
|
|
149
|
+
visibleItems,
|
|
150
|
+
itemDetails,
|
|
151
|
+
visibleRowIds,
|
|
152
|
+
childRowIdsById,
|
|
153
|
+
handleExpandedSubRowIdChange,
|
|
154
|
+
isSubRowExpanded,
|
|
155
|
+
],
|
|
156
|
+
);
|
|
143
157
|
}
|
|
144
158
|
|
|
145
159
|
export { useTableItems };
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { useCallback, useMemo } from "react";
|
|
2
|
+
import { useDataGridContext } from "../../../data-grid/root/DataGridRoot.context";
|
|
2
3
|
import { useId } from "../../../utils-external";
|
|
3
4
|
import { useControllableState } from "../../../utils/hooks";
|
|
4
5
|
import { getMultipleSelectProps } from "../helpers/selection/getMultipleSelectProps";
|
|
5
6
|
import { getSingleSelectProps } from "../helpers/selection/getSingleSelectProps";
|
|
6
7
|
import type {
|
|
7
|
-
SelectedKeysT,
|
|
8
8
|
SelectionProps,
|
|
9
9
|
TableSelection,
|
|
10
10
|
} from "../helpers/selection/selection.types";
|
|
11
|
-
import type { TableRowEntryId } from "../root/
|
|
11
|
+
import type { TableRowEntryId } from "../root/DataGridTable.types";
|
|
12
12
|
import type { UseTableItemsReturn } from "./useTableItems";
|
|
13
13
|
|
|
14
14
|
type UseTableSelectionArgs<T> = {
|
|
15
15
|
selection?: SelectionProps<T>;
|
|
16
|
+
selectionTrigger: "row" | "control";
|
|
16
17
|
tableItems: UseTableItemsReturn<T>;
|
|
17
18
|
};
|
|
18
19
|
|
|
@@ -24,27 +25,28 @@ type UseTableSelectionReturn = {
|
|
|
24
25
|
|
|
25
26
|
function useTableSelection<T>({
|
|
26
27
|
selection = {
|
|
27
|
-
|
|
28
|
+
mode: "none",
|
|
28
29
|
},
|
|
30
|
+
selectionTrigger = "row",
|
|
29
31
|
tableItems,
|
|
30
32
|
}: UseTableSelectionArgs<T>): UseTableSelectionReturn {
|
|
33
|
+
const { isLoading } = useDataGridContext();
|
|
31
34
|
const {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
mode,
|
|
36
|
+
defaultSelectedRowIds,
|
|
37
|
+
selectedRowIds: selectedRowIdsProp,
|
|
38
|
+
onSelectedRowIdsChange,
|
|
36
39
|
enableRowSelection,
|
|
37
|
-
selectionTrigger = "row",
|
|
38
40
|
} = selection;
|
|
39
41
|
|
|
40
42
|
const { visibleRowIds = [] } = tableItems;
|
|
41
43
|
|
|
42
44
|
const radioGroupName = useId();
|
|
43
45
|
|
|
44
|
-
const [selectedKeys, setSelectedKeys] = useControllableState<
|
|
45
|
-
value:
|
|
46
|
-
defaultValue:
|
|
47
|
-
onChange:
|
|
46
|
+
const [selectedKeys, setSelectedKeys] = useControllableState<string[]>({
|
|
47
|
+
value: mode !== "none" ? selectedRowIdsProp : undefined,
|
|
48
|
+
defaultValue: defaultSelectedRowIds ?? [],
|
|
49
|
+
onChange: onSelectedRowIdsChange,
|
|
48
50
|
});
|
|
49
51
|
|
|
50
52
|
const selectedKeysSet = useMemo(() => new Set(selectedKeys), [selectedKeys]);
|
|
@@ -54,52 +56,67 @@ function useTableSelection<T>({
|
|
|
54
56
|
[selectedKeysSet],
|
|
55
57
|
);
|
|
56
58
|
|
|
57
|
-
|
|
59
|
+
return useMemo(() => {
|
|
60
|
+
const baseSelection = { selectedKeys, isRowSelected };
|
|
58
61
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
62
|
+
if (mode === "none") {
|
|
63
|
+
return {
|
|
64
|
+
selection: {
|
|
65
|
+
mode,
|
|
66
|
+
...baseSelection,
|
|
67
|
+
selectedKeys: [],
|
|
68
|
+
},
|
|
69
|
+
selectionTrigger,
|
|
70
|
+
renderSelection: false,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (mode === "single") {
|
|
75
|
+
return {
|
|
76
|
+
selection: {
|
|
77
|
+
mode,
|
|
78
|
+
...baseSelection,
|
|
79
|
+
...getSingleSelectProps({
|
|
80
|
+
selectedKeysSet,
|
|
81
|
+
setSelectedKeys,
|
|
82
|
+
name: radioGroupName,
|
|
83
|
+
enableRowSelection,
|
|
84
|
+
}),
|
|
85
|
+
},
|
|
86
|
+
selectionTrigger,
|
|
87
|
+
renderSelection: visibleRowIds.length !== 0,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
70
90
|
|
|
71
|
-
if (selectionMode === "single") {
|
|
72
91
|
return {
|
|
73
92
|
selection: {
|
|
74
|
-
|
|
93
|
+
mode,
|
|
75
94
|
...baseSelection,
|
|
76
|
-
...
|
|
95
|
+
...getMultipleSelectProps({
|
|
77
96
|
selectedKeysSet,
|
|
97
|
+
selectedKeys,
|
|
78
98
|
setSelectedKeys,
|
|
79
|
-
name: radioGroupName,
|
|
80
99
|
enableRowSelection,
|
|
100
|
+
tableItems,
|
|
101
|
+
isLoading,
|
|
81
102
|
}),
|
|
82
103
|
},
|
|
83
104
|
selectionTrigger,
|
|
84
105
|
renderSelection: visibleRowIds.length !== 0,
|
|
85
106
|
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
...baseSelection,
|
|
92
|
-
...getMultipleSelectProps({
|
|
93
|
-
selectedKeysSet,
|
|
94
|
-
selectedKeys,
|
|
95
|
-
setSelectedKeys,
|
|
96
|
-
enableRowSelection,
|
|
97
|
-
tableItems,
|
|
98
|
-
}),
|
|
99
|
-
},
|
|
107
|
+
}, [
|
|
108
|
+
mode,
|
|
109
|
+
selectedKeys,
|
|
110
|
+
selectedKeysSet,
|
|
111
|
+
isRowSelected,
|
|
100
112
|
selectionTrigger,
|
|
101
|
-
|
|
102
|
-
|
|
113
|
+
visibleRowIds,
|
|
114
|
+
setSelectedKeys,
|
|
115
|
+
radioGroupName,
|
|
116
|
+
enableRowSelection,
|
|
117
|
+
tableItems,
|
|
118
|
+
isLoading,
|
|
119
|
+
]);
|
|
103
120
|
}
|
|
104
121
|
|
|
105
122
|
/**
|
|
@@ -107,7 +124,7 @@ function useTableSelection<T>({
|
|
|
107
124
|
*/
|
|
108
125
|
const noSelectionState: UseTableSelectionReturn = {
|
|
109
126
|
selection: {
|
|
110
|
-
|
|
127
|
+
mode: "none",
|
|
111
128
|
selectedKeys: [],
|
|
112
129
|
isRowSelected: () => false,
|
|
113
130
|
},
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { useCallback } from "react";
|
|
2
1
|
import { consoleWarning } from "../../../utils/helpers/consoleWarning";
|
|
3
|
-
import { useControllableState } from "../../../utils/hooks";
|
|
4
|
-
import type { SortChangeDetail, SortEntry } from "../root/
|
|
2
|
+
import { useControllableState, useEventCallback } from "../../../utils/hooks";
|
|
3
|
+
import type { SortChangeDetail, SortEntry } from "../root/DataGridTable.types";
|
|
5
4
|
|
|
6
5
|
type TableSortOptions = {
|
|
7
6
|
/**
|
|
@@ -9,22 +8,31 @@ type TableSortOptions = {
|
|
|
9
8
|
* Columns not present in the array are unsorted.
|
|
10
9
|
* Supports multi-column sorting when multiple entries are provided.
|
|
11
10
|
*
|
|
12
|
-
* When provided, the component is controlled
|
|
13
|
-
* For uncontrolled usage, use `
|
|
11
|
+
* When provided, the component is controlled - you must also handle `onSortOrderChange`.
|
|
12
|
+
* For uncontrolled usage, use `defaultSortOrder` instead.
|
|
14
13
|
*/
|
|
15
|
-
|
|
14
|
+
sortOrder?: SortEntry[];
|
|
16
15
|
/**
|
|
17
16
|
* Initial sort state for uncontrolled usage.
|
|
18
|
-
* Use `
|
|
17
|
+
* Use `sortOrder` + `onSortOrderChange` for controlled usage.
|
|
19
18
|
* @default []
|
|
20
19
|
*/
|
|
21
|
-
|
|
20
|
+
defaultSortOrder?: SortEntry[];
|
|
22
21
|
/**
|
|
23
22
|
* Called when the user clicks a sortable column header.
|
|
24
23
|
* - `sort` — the full updated sort array after cycling: unsorted → asc → desc → unsorted.
|
|
25
24
|
* - `detail` — the specific column that changed, including its new direction (`"none"` means removed).
|
|
26
25
|
*/
|
|
27
|
-
|
|
26
|
+
onSortOrderChange?: (
|
|
27
|
+
sortOrder: SortEntry[],
|
|
28
|
+
detail: SortChangeDetail,
|
|
29
|
+
) => void;
|
|
30
|
+
/**
|
|
31
|
+
* When true, allows multiple columns to be sorted by holding Shift while clicking headers.
|
|
32
|
+
*
|
|
33
|
+
* @default true
|
|
34
|
+
*/
|
|
35
|
+
allowMultiSort?: boolean;
|
|
28
36
|
};
|
|
29
37
|
|
|
30
38
|
type UseTableSortResults = {
|
|
@@ -42,31 +50,35 @@ type UseTableSortResults = {
|
|
|
42
50
|
};
|
|
43
51
|
|
|
44
52
|
function useTableSort(options?: TableSortOptions): UseTableSortResults {
|
|
45
|
-
const {
|
|
53
|
+
const {
|
|
54
|
+
defaultSortOrder,
|
|
55
|
+
onSortOrderChange,
|
|
56
|
+
sortOrder,
|
|
57
|
+
allowMultiSort = true,
|
|
58
|
+
} = options || {};
|
|
46
59
|
|
|
47
60
|
const [sort, setSort] = useControllableState({
|
|
48
|
-
value:
|
|
49
|
-
defaultValue:
|
|
61
|
+
value: sortOrder,
|
|
62
|
+
defaultValue: defaultSortOrder || [],
|
|
50
63
|
});
|
|
51
64
|
|
|
52
|
-
const handleSortClick =
|
|
65
|
+
const handleSortClick = useEventCallback(
|
|
53
66
|
(id: string, event: React.MouseEvent<HTMLElement, MouseEvent>) => {
|
|
54
67
|
if (id === undefined) {
|
|
55
68
|
consoleWarning(
|
|
56
|
-
"
|
|
69
|
+
"DataGrid.Table: Column id is undefined for sort event on target",
|
|
57
70
|
event.target,
|
|
58
71
|
"Make sure your column definitions include an 'id' property.",
|
|
59
72
|
);
|
|
60
73
|
return;
|
|
61
74
|
}
|
|
62
75
|
|
|
63
|
-
const cumulative = event.shiftKey;
|
|
76
|
+
const cumulative = allowMultiSort && event.shiftKey;
|
|
64
77
|
const base = cumulative ? sort : sort.filter((s) => s.columnId === id);
|
|
65
78
|
const { next, detail } = nextSortEntries(base, id);
|
|
66
79
|
setSort(next);
|
|
67
|
-
|
|
80
|
+
onSortOrderChange?.(next, detail);
|
|
68
81
|
},
|
|
69
|
-
[onSortChange, setSort, sort],
|
|
70
82
|
);
|
|
71
83
|
|
|
72
84
|
return {
|
package/src/data/table/index.tsx
CHANGED
|
@@ -1,23 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
/* export {
|
|
3
|
-
default as DataTable,
|
|
4
|
-
DataTableCaption,
|
|
5
|
-
DataTableThead,
|
|
6
|
-
DataTableTbody,
|
|
7
|
-
DataTableTr,
|
|
8
|
-
DataTableTh,
|
|
9
|
-
DataTableTd,
|
|
10
|
-
DataTableTfoot,
|
|
11
|
-
} from "./root/DataTableRoot.legacy";
|
|
12
|
-
export type {
|
|
13
|
-
DataTableProps,
|
|
14
|
-
DataTableCaptionProps,
|
|
15
|
-
DataTableTheadProps,
|
|
16
|
-
DataTableTbodyProps,
|
|
17
|
-
DataTableTrProps,
|
|
18
|
-
DataTableThProps,
|
|
19
|
-
DataTableTdProps,
|
|
20
|
-
DataTableTfootProps,
|
|
21
|
-
} from "./root/DataTableRoot.legacy"; */
|
|
22
2
|
|
|
23
|
-
export {
|
|
3
|
+
export {
|
|
4
|
+
DataGridTable,
|
|
5
|
+
type DataGridTableProps,
|
|
6
|
+
} from "./root/DataGridTableRoot";
|
|
@@ -1,47 +1,38 @@
|
|
|
1
1
|
import type { DataTableColumnHeaderProps } from "../column-header/DataTableColumnHeader";
|
|
2
2
|
|
|
3
|
-
type SortDirection = "asc" | "desc" | "none";
|
|
4
|
-
|
|
5
3
|
/**
|
|
6
4
|
* TODO:
|
|
7
5
|
* - Consider "accessorKey" or similar to allow simple column definitions without a cell function.
|
|
8
|
-
* - Add "align" property for better control over text alignment in cells.
|
|
9
6
|
*/
|
|
10
7
|
type ColumnDefinition<T> = {
|
|
11
8
|
id: string;
|
|
12
9
|
/**
|
|
13
|
-
*
|
|
10
|
+
* Uses `<th>` instead of `<td>` for the cell if true.
|
|
14
11
|
*
|
|
15
|
-
*
|
|
12
|
+
* Should be used on the column that acts as row header.
|
|
13
|
+
* There should be exactly one column with this set to true.
|
|
16
14
|
*/
|
|
17
|
-
|
|
15
|
+
isRowHeader?: boolean; // TODO: Better documentation, consider warning if not one column has this set to true.
|
|
18
16
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* TODO: Better documentation, consider warning if not one column has this set to true.
|
|
17
|
+
* Name of the column.
|
|
18
|
+
* Used in the header cell unless `headerCell` is provided.
|
|
19
|
+
* Also used in the settings dialog.
|
|
23
20
|
*/
|
|
24
|
-
|
|
21
|
+
header: string;
|
|
25
22
|
/**
|
|
26
|
-
*
|
|
27
|
-
* TODO: Pri zero rename to headerCell
|
|
23
|
+
* Overrides header cell content. Should not differ too much from `header`.
|
|
28
24
|
*/
|
|
29
|
-
|
|
25
|
+
headerCell?: React.ReactNode;
|
|
30
26
|
/**
|
|
31
|
-
* Renders table
|
|
27
|
+
* Renders table body cell content.
|
|
32
28
|
*/
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Label of header. Renders if header is not provided.
|
|
36
|
-
* TODO: Pri zero consider renaming to header
|
|
37
|
-
*/
|
|
38
|
-
label: string;
|
|
29
|
+
bodyCell: (item: T) => React.ReactNode; // TODO: Consider including truncateContent (maybe all options) so that consumer can adjust how content is rendered based on this (e.g. toggle flex-wrap)
|
|
39
30
|
/**
|
|
40
31
|
* Makes the column sortable. Renders the header as a sort button.
|
|
41
|
-
* Use `
|
|
32
|
+
* Use `sorting` prop on `DataGrid.Table` to configure sorting behavior and state management.
|
|
42
33
|
*/
|
|
43
|
-
|
|
44
|
-
} & Pick<DataTableColumnHeaderProps, "width">;
|
|
34
|
+
isSortable?: boolean;
|
|
35
|
+
} & Pick<DataTableColumnHeaderProps, "width" | "align">;
|
|
45
36
|
|
|
46
37
|
type ColumnDefinitions<T> = ColumnDefinition<T>[];
|
|
47
38
|
|
|
@@ -64,9 +55,7 @@ type SortChangeDetail = {
|
|
|
64
55
|
direction: "asc" | "desc" | "none";
|
|
65
56
|
};
|
|
66
57
|
|
|
67
|
-
type DataTableLoadingConfig =
|
|
68
|
-
isLoading?: boolean;
|
|
69
|
-
} & (
|
|
58
|
+
type DataTableLoadingConfig =
|
|
70
59
|
| {
|
|
71
60
|
variant: "content";
|
|
72
61
|
content: React.ReactNode;
|
|
@@ -79,8 +68,7 @@ type DataTableLoadingConfig = {
|
|
|
79
68
|
| {
|
|
80
69
|
variant: "overlay";
|
|
81
70
|
label?: string;
|
|
82
|
-
}
|
|
83
|
-
);
|
|
71
|
+
};
|
|
84
72
|
|
|
85
73
|
type TableRowEntryId = string;
|
|
86
74
|
|
|
@@ -88,7 +76,6 @@ export type {
|
|
|
88
76
|
ColumnDefinition,
|
|
89
77
|
ColumnDefinitions,
|
|
90
78
|
DataTableLoadingConfig,
|
|
91
|
-
SortDirection,
|
|
92
79
|
SortEntry,
|
|
93
80
|
SortChangeDetail,
|
|
94
81
|
TableRowEntryId,
|