@navikt/ds-react 8.10.5 → 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/drag-handler/DragAndDropDragHandler.js +0 -1
- package/cjs/data/drag-and-drop/drag-handler/DragAndDropDragHandler.js.map +1 -1
- package/cjs/data/drag-and-drop/root/DragAndDropRoot.d.ts +6 -6
- package/cjs/data/drag-and-drop/root/DragAndDropRoot.js +6 -29
- package/cjs/data/drag-and-drop/root/DragAndDropRoot.js.map +1 -1
- package/cjs/data/stories/Data.test-data.d.ts +3 -6
- package/cjs/data/stories/Data.test-data.js +46 -59
- package/cjs/data/stories/Data.test-data.js.map +1 -1
- package/cjs/data/table/base-cell/DataTableBaseCell.d.ts +18 -18
- package/cjs/data/table/base-cell/DataTableBaseCell.js +4 -8
- package/cjs/data/table/base-cell/DataTableBaseCell.js.map +1 -1
- package/cjs/data/table/column-header/DataTableColumnHeader.d.ts +19 -13
- package/cjs/data/table/column-header/DataTableColumnHeader.js +26 -28
- package/cjs/data/table/column-header/DataTableColumnHeader.js.map +1 -1
- package/cjs/data/table/column-header/useTableColumnResize.d.ts +19 -29
- package/cjs/data/table/column-header/useTableColumnResize.js +30 -28
- package/cjs/data/table/column-header/useTableColumnResize.js.map +1 -1
- package/cjs/data/table/details-panel-row/DataTableDetailsPanelRow.d.ts +1 -1
- package/cjs/data/table/details-panel-row/DataTableDetailsPanelRow.js +2 -2
- package/cjs/data/table/details-panel-row/DataTableDetailsPanelRow.js.map +1 -1
- package/cjs/data/table/helpers/collectTableRowEntries.d.ts +2 -2
- package/cjs/data/table/helpers/selection/getMultipleSelectProps.d.ts +14 -11
- package/cjs/data/table/helpers/selection/getMultipleSelectProps.js +45 -51
- package/cjs/data/table/helpers/selection/getMultipleSelectProps.js.map +1 -1
- package/cjs/data/table/helpers/selection/getSingleSelectProps.d.ts +9 -8
- package/cjs/data/table/helpers/selection/getSingleSelectProps.js +23 -10
- package/cjs/data/table/helpers/selection/getSingleSelectProps.js.map +1 -1
- package/cjs/data/table/helpers/selection/selection.types.d.ts +24 -32
- package/cjs/data/table/helpers/selection/selection.utils.d.ts +21 -0
- package/cjs/data/table/helpers/selection/selection.utils.js +46 -0
- package/cjs/data/table/helpers/selection/selection.utils.js.map +1 -0
- package/cjs/data/table/hooks/useColumnOptions.d.ts +17 -6
- package/cjs/data/table/hooks/useColumnOptions.js +26 -8
- package/cjs/data/table/hooks/useColumnOptions.js.map +1 -1
- package/cjs/data/table/hooks/useTableDetailsPanel.d.ts +10 -14
- package/cjs/data/table/hooks/useTableDetailsPanel.js +6 -5
- package/cjs/data/table/hooks/useTableDetailsPanel.js.map +1 -1
- package/cjs/data/table/hooks/useTableItems.d.ts +32 -19
- package/cjs/data/table/hooks/useTableItems.js +13 -15
- package/cjs/data/table/hooks/useTableItems.js.map +1 -1
- package/cjs/data/table/hooks/useTableKeyboardNav.d.ts +1 -6
- package/cjs/data/table/hooks/useTableKeyboardNav.js +1 -4
- package/cjs/data/table/hooks/useTableKeyboardNav.js.map +1 -1
- package/cjs/data/table/hooks/useTableSelection.d.ts +7 -6
- package/cjs/data/table/hooks/useTableSelection.js +52 -35
- package/cjs/data/table/hooks/useTableSelection.js.map +1 -1
- package/cjs/data/table/hooks/useTableSort.d.ts +15 -9
- package/cjs/data/table/hooks/useTableSort.js +9 -11
- 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/DataGridTable.types.d.ts +65 -0
- 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/DataGridTableRoot.js +237 -0
- package/cjs/data/table/root/DataGridTableRoot.js.map +1 -0
- package/cjs/data/table/root/DataTableRoot.context.d.ts +17 -7
- package/cjs/data/table/root/DataTableRoot.context.js.map +1 -1
- package/cjs/data/table/sub-row-toggle/DataTableSubRowToggle.js +4 -4
- package/cjs/data/table/sub-row-toggle/DataTableSubRowToggle.js.map +1 -1
- package/cjs/data/table/tbody/DataTableTbody.js +4 -2
- package/cjs/data/table/tbody/DataTableTbody.js.map +1 -1
- package/cjs/data/table/tr/DataTableTr.d.ts +7 -5
- package/cjs/data/table/tr/DataTableTr.js +69 -32
- 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-grid/root/DataGridRoot.context.js +11 -0
- package/cjs/data-grid/root/DataGridRoot.context.js.map +1 -0
- package/cjs/data-grid/root/DataGridRoot.d.ts +89 -0
- package/cjs/data-grid/root/DataGridRoot.js +93 -0
- package/cjs/data-grid/root/DataGridRoot.js.map +1 -0
- package/cjs/preview.d.ts +1 -0
- package/cjs/preview.js +7 -0
- package/cjs/preview.js.map +1 -0
- package/cjs/table/ColumnHeader.js +2 -1
- package/cjs/table/ColumnHeader.js.map +1 -1
- package/esm/data/drag-and-drop/drag-handler/DragAndDropDragHandler.js +0 -1
- package/esm/data/drag-and-drop/drag-handler/DragAndDropDragHandler.js.map +1 -1
- package/esm/data/drag-and-drop/root/DragAndDropRoot.d.ts +6 -6
- package/esm/data/drag-and-drop/root/DragAndDropRoot.js +6 -29
- package/esm/data/drag-and-drop/root/DragAndDropRoot.js.map +1 -1
- package/esm/data/stories/Data.test-data.d.ts +3 -6
- package/esm/data/stories/Data.test-data.js +46 -59
- package/esm/data/stories/Data.test-data.js.map +1 -1
- package/esm/data/table/base-cell/DataTableBaseCell.d.ts +18 -18
- package/esm/data/table/base-cell/DataTableBaseCell.js +4 -8
- package/esm/data/table/base-cell/DataTableBaseCell.js.map +1 -1
- package/esm/data/table/column-header/DataTableColumnHeader.d.ts +19 -13
- package/esm/data/table/column-header/DataTableColumnHeader.js +27 -29
- package/esm/data/table/column-header/DataTableColumnHeader.js.map +1 -1
- package/esm/data/table/column-header/useTableColumnResize.d.ts +19 -29
- package/esm/data/table/column-header/useTableColumnResize.js +30 -28
- package/esm/data/table/column-header/useTableColumnResize.js.map +1 -1
- package/esm/data/table/details-panel-row/DataTableDetailsPanelRow.d.ts +1 -1
- package/esm/data/table/details-panel-row/DataTableDetailsPanelRow.js +2 -2
- package/esm/data/table/details-panel-row/DataTableDetailsPanelRow.js.map +1 -1
- package/esm/data/table/helpers/collectTableRowEntries.d.ts +2 -2
- package/esm/data/table/helpers/selection/getMultipleSelectProps.d.ts +14 -11
- package/esm/data/table/helpers/selection/getMultipleSelectProps.js +45 -51
- package/esm/data/table/helpers/selection/getMultipleSelectProps.js.map +1 -1
- package/esm/data/table/helpers/selection/getSingleSelectProps.d.ts +9 -8
- package/esm/data/table/helpers/selection/getSingleSelectProps.js +23 -10
- package/esm/data/table/helpers/selection/getSingleSelectProps.js.map +1 -1
- package/esm/data/table/helpers/selection/selection.types.d.ts +24 -32
- package/esm/data/table/helpers/selection/selection.utils.d.ts +21 -0
- package/esm/data/table/helpers/selection/selection.utils.js +43 -0
- package/esm/data/table/helpers/selection/selection.utils.js.map +1 -0
- package/esm/data/table/hooks/useColumnOptions.d.ts +17 -6
- package/esm/data/table/hooks/useColumnOptions.js +26 -8
- package/esm/data/table/hooks/useColumnOptions.js.map +1 -1
- package/esm/data/table/hooks/useTableDetailsPanel.d.ts +10 -14
- package/esm/data/table/hooks/useTableDetailsPanel.js +6 -5
- package/esm/data/table/hooks/useTableDetailsPanel.js.map +1 -1
- package/esm/data/table/hooks/useTableItems.d.ts +32 -19
- package/esm/data/table/hooks/useTableItems.js +14 -13
- package/esm/data/table/hooks/useTableItems.js.map +1 -1
- package/esm/data/table/hooks/useTableKeyboardNav.d.ts +1 -6
- package/esm/data/table/hooks/useTableKeyboardNav.js +1 -4
- package/esm/data/table/hooks/useTableKeyboardNav.js.map +1 -1
- package/esm/data/table/hooks/useTableSelection.d.ts +7 -6
- package/esm/data/table/hooks/useTableSelection.js +52 -35
- package/esm/data/table/hooks/useTableSelection.js.map +1 -1
- package/esm/data/table/hooks/useTableSort.d.ts +15 -9
- package/esm/data/table/hooks/useTableSort.js +10 -12
- 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/DataGridTable.types.d.ts +65 -0
- 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/DataGridTableRoot.js +202 -0
- package/esm/data/table/root/DataGridTableRoot.js.map +1 -0
- package/esm/data/table/root/DataTableRoot.context.d.ts +17 -7
- package/esm/data/table/root/DataTableRoot.context.js.map +1 -1
- package/esm/data/table/sub-row-toggle/DataTableSubRowToggle.js +4 -4
- package/esm/data/table/sub-row-toggle/DataTableSubRowToggle.js.map +1 -1
- package/esm/data/table/tbody/DataTableTbody.js +4 -2
- package/esm/data/table/tbody/DataTableTbody.js.map +1 -1
- package/esm/data/table/tr/DataTableTr.d.ts +7 -5
- package/esm/data/table/tr/DataTableTr.js +68 -32
- 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-grid/root/DataGridRoot.context.js +7 -0
- 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 +2 -1
- package/esm/table/ColumnHeader.js.map +1 -1
- package/package.json +23 -3
- package/src/data/drag-and-drop/drag-handler/DragAndDropDragHandler.tsx +0 -1
- package/src/data/drag-and-drop/root/DragAndDropRoot.tsx +18 -52
- package/src/data/stories/Data.test-data.tsx +76 -65
- package/src/data/table/base-cell/DataTableBaseCell.tsx +36 -26
- package/src/data/table/column-header/DataTableColumnHeader.tsx +62 -62
- package/src/data/table/column-header/useTableColumnResize.ts +63 -79
- package/src/data/table/details-panel-row/DataTableDetailsPanelRow.tsx +3 -3
- package/src/data/table/helpers/collectTableRowEntries.ts +1 -2
- package/src/data/table/helpers/selection/getMultipleSelectProps.ts +69 -83
- package/src/data/table/helpers/selection/getSingleSelectProps.ts +35 -17
- package/src/data/table/helpers/selection/selection.types.ts +23 -33
- package/src/data/table/helpers/selection/selection.utils.test.ts +161 -0
- package/src/data/table/helpers/selection/selection.utils.ts +73 -0
- package/src/data/table/hooks/__tests__/useTableItems.test.ts +2 -1
- package/src/data/table/hooks/useColumnOptions.ts +49 -15
- package/src/data/table/hooks/useTableDetailsPanel.tsx +21 -28
- package/src/data/table/hooks/useTableItems.ts +60 -38
- package/src/data/table/hooks/useTableKeyboardNav.ts +1 -13
- package/src/data/table/hooks/useTableSelection.ts +80 -68
- package/src/data/table/hooks/useTableSort.ts +36 -23
- package/src/data/table/index.tsx +4 -21
- package/src/data/table/root/DataGridTable.types.ts +82 -0
- package/src/data/table/root/DataGridTableRoot.tsx +566 -0
- package/src/data/table/root/DataTableRoot.context.ts +24 -10
- package/src/data/table/sub-row-toggle/DataTableSubRowToggle.tsx +6 -5
- package/src/data/table/tbody/DataTableTbody.tsx +6 -2
- package/src/data/table/tr/DataTableTr.tsx +145 -47
- 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 +3 -1
- package/cjs/data/drag-and-drop-legacy/drag-handler/DragAndDropDragHandlerLegacy.d.ts +0 -22
- package/cjs/data/drag-and-drop-legacy/drag-handler/DragAndDropDragHandlerLegacy.js +0 -35
- package/cjs/data/drag-and-drop-legacy/drag-handler/DragAndDropDragHandlerLegacy.js.map +0 -1
- package/cjs/data/drag-and-drop-legacy/item/DragAndDropItemLegacy.d.ts +0 -27
- package/cjs/data/drag-and-drop-legacy/item/DragAndDropItemLegacy.js +0 -86
- package/cjs/data/drag-and-drop-legacy/item/DragAndDropItemLegacy.js.map +0 -1
- package/cjs/data/drag-and-drop-legacy/root/DragAndDropLegacy.context.d.ts +0 -5
- package/cjs/data/drag-and-drop-legacy/root/DragAndDropLegacy.context.js +0 -6
- package/cjs/data/drag-and-drop-legacy/root/DragAndDropLegacy.context.js.map +0 -1
- package/cjs/data/drag-and-drop-legacy/root/DragAndDropLegacyRoot.d.ts +0 -24
- package/cjs/data/drag-and-drop-legacy/root/DragAndDropLegacyRoot.js +0 -108
- package/cjs/data/drag-and-drop-legacy/root/DragAndDropLegacyRoot.js.map +0 -1
- package/cjs/data/table/helpers/selection/SelectionSubtreeHelper.d.ts +0 -46
- package/cjs/data/table/helpers/selection/SelectionSubtreeHelper.js +0 -112
- package/cjs/data/table/helpers/selection/SelectionSubtreeHelper.js.map +0 -1
- package/cjs/data/table/root/DataTable.types.d.ts +0 -63
- package/cjs/data/table/root/DataTable.types.js.map +0 -1
- package/cjs/data/table/root/DataTableRoot.d.ts +0 -141
- package/cjs/data/table/root/DataTableRoot.js +0 -229
- package/cjs/data/table/root/DataTableRoot.js.map +0 -1
- package/cjs/data/table/root/DataTableRoot.legacy.d.ts +0 -177
- package/cjs/data/table/root/DataTableRoot.legacy.js +0 -104
- package/cjs/data/table/root/DataTableRoot.legacy.js.map +0 -1
- package/esm/data/drag-and-drop-legacy/drag-handler/DragAndDropDragHandlerLegacy.d.ts +0 -22
- package/esm/data/drag-and-drop-legacy/drag-handler/DragAndDropDragHandlerLegacy.js +0 -29
- package/esm/data/drag-and-drop-legacy/drag-handler/DragAndDropDragHandlerLegacy.js.map +0 -1
- package/esm/data/drag-and-drop-legacy/item/DragAndDropItemLegacy.d.ts +0 -27
- package/esm/data/drag-and-drop-legacy/item/DragAndDropItemLegacy.js +0 -50
- package/esm/data/drag-and-drop-legacy/item/DragAndDropItemLegacy.js.map +0 -1
- package/esm/data/drag-and-drop-legacy/root/DragAndDropLegacy.context.d.ts +0 -5
- package/esm/data/drag-and-drop-legacy/root/DragAndDropLegacy.context.js +0 -3
- package/esm/data/drag-and-drop-legacy/root/DragAndDropLegacy.context.js.map +0 -1
- package/esm/data/drag-and-drop-legacy/root/DragAndDropLegacyRoot.d.ts +0 -24
- package/esm/data/drag-and-drop-legacy/root/DragAndDropLegacyRoot.js +0 -68
- package/esm/data/drag-and-drop-legacy/root/DragAndDropLegacyRoot.js.map +0 -1
- package/esm/data/table/helpers/selection/SelectionSubtreeHelper.d.ts +0 -46
- package/esm/data/table/helpers/selection/SelectionSubtreeHelper.js +0 -109
- package/esm/data/table/helpers/selection/SelectionSubtreeHelper.js.map +0 -1
- package/esm/data/table/root/DataTable.types.d.ts +0 -63
- 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 -141
- package/esm/data/table/root/DataTableRoot.js +0 -193
- package/esm/data/table/root/DataTableRoot.js.map +0 -1
- package/esm/data/table/root/DataTableRoot.legacy.d.ts +0 -177
- package/esm/data/table/root/DataTableRoot.legacy.js +0 -59
- package/esm/data/table/root/DataTableRoot.legacy.js.map +0 -1
- package/src/data/drag-and-drop-legacy/drag-handler/DragAndDropDragHandlerLegacy.tsx +0 -104
- package/src/data/drag-and-drop-legacy/item/DragAndDropItemLegacy.tsx +0 -74
- package/src/data/drag-and-drop-legacy/root/DragAndDropLegacy.context.tsx +0 -11
- package/src/data/drag-and-drop-legacy/root/DragAndDropLegacyRoot.tsx +0 -94
- package/src/data/table/Readme.md +0 -11
- package/src/data/table/helpers/selection/SelectionSubtreeHelper.test.ts +0 -66
- package/src/data/table/helpers/selection/SelectionSubtreeHelper.ts +0 -162
- package/src/data/table/hooks/__tests__/useTableSelection.test.ts +0 -488
- package/src/data/table/root/DataTable.types.ts +0 -87
- package/src/data/table/root/DataTableRoot.legacy.tsx +0 -297
- package/src/data/table/root/DataTableRoot.tsx +0 -562
- package/src/data/table/root/agent-feature-gap.md +0 -96
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { forwardRef, useRef } from "react";
|
|
1
|
+
import React, { forwardRef, useMemo, useRef } from "react";
|
|
2
2
|
import {
|
|
3
3
|
ArrowsUpDownIcon,
|
|
4
4
|
CaretLeftCircleFillIcon,
|
|
@@ -6,40 +6,47 @@ import {
|
|
|
6
6
|
SortDownIcon,
|
|
7
7
|
SortUpIcon,
|
|
8
8
|
} from "@navikt/aksel-icons";
|
|
9
|
+
import { useDataGridContext } from "../../../data-grid/root/DataGridRoot.context";
|
|
9
10
|
import { cl } from "../../../utils/helpers";
|
|
10
11
|
import { useMergeRefs } from "../../../utils/hooks";
|
|
11
12
|
import {
|
|
12
13
|
DataTableBaseCell,
|
|
13
14
|
type DataTableBaseCellProps,
|
|
14
15
|
} from "../base-cell/DataTableBaseCell";
|
|
15
|
-
import
|
|
16
|
+
import { useDataTableContext } from "../root/DataTableRoot.context";
|
|
16
17
|
import { type ResizeProps, useTableColumnResize } from "./useTableColumnResize";
|
|
17
18
|
|
|
18
|
-
interface DataTableColumnHeaderProps
|
|
19
|
-
|
|
19
|
+
interface DataTableColumnHeaderProps extends DataTableBaseCellProps {
|
|
20
|
+
/**
|
|
21
|
+
* Unique identifier for the column. Used when sorting to identify which column is being sorted.
|
|
22
|
+
*/
|
|
23
|
+
id: string;
|
|
20
24
|
/**
|
|
21
25
|
* Accessible name of the column.
|
|
22
26
|
*/
|
|
23
27
|
label: string;
|
|
24
28
|
/**
|
|
25
|
-
* Makes the column
|
|
26
|
-
* a clickable button when true.
|
|
29
|
+
* Makes the column sortable by clicking on the header.
|
|
30
|
+
* The entire header cell content becomes a clickable button when true.
|
|
27
31
|
*/
|
|
28
32
|
sortable?: boolean;
|
|
29
33
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
*
|
|
37
|
-
*
|
|
34
|
+
* Object with props related to column width and resizing. Summary:
|
|
35
|
+
*
|
|
36
|
+
* - `resizable?: boolean` - Whether the column should be resizable by the user.
|
|
37
|
+
* - `autoResizeOnce?: boolean` - Whether the column should automatically resize to fit its content.
|
|
38
|
+
* - `resizeMin?: number` - Minimum width of the column when resizing.
|
|
39
|
+
* - `resizeMax?: number` - Maximum width of the column when resizing.
|
|
40
|
+
* - `value?: number | string` - Controlled width of the column.
|
|
41
|
+
* - `defaultValue?: number | string` - Initial width of the column.
|
|
42
|
+
* - `onChange?: (width: number) => void` - Called when the column width changes.
|
|
43
|
+
*
|
|
44
|
+
* See individual props for details and defaults.
|
|
38
45
|
*/
|
|
39
|
-
|
|
46
|
+
width?: ResizeProps;
|
|
40
47
|
}
|
|
41
48
|
|
|
42
|
-
const SORT_ICON: Record<
|
|
49
|
+
const SORT_ICON: Record<"asc" | "desc" | "none", React.ElementType> = {
|
|
43
50
|
asc: SortUpIcon,
|
|
44
51
|
desc: SortDownIcon,
|
|
45
52
|
none: ArrowsUpDownIcon,
|
|
@@ -56,45 +63,40 @@ const DataTableColumnHeader = forwardRef<
|
|
|
56
63
|
>(
|
|
57
64
|
(
|
|
58
65
|
{
|
|
59
|
-
|
|
60
|
-
children,
|
|
66
|
+
id,
|
|
61
67
|
label,
|
|
62
68
|
sortable = false,
|
|
63
|
-
sortDirection = "none",
|
|
64
|
-
onSortClick,
|
|
65
|
-
resizable = true,
|
|
66
|
-
style,
|
|
67
69
|
width,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
onWidthChange,
|
|
73
|
-
colSpan,
|
|
74
|
-
rowSpan,
|
|
75
|
-
UNSAFE_isSelection,
|
|
70
|
+
cellType,
|
|
71
|
+
className,
|
|
72
|
+
children,
|
|
73
|
+
style,
|
|
76
74
|
...rest
|
|
77
75
|
},
|
|
78
76
|
forwardedRef,
|
|
79
77
|
) => {
|
|
80
|
-
const
|
|
78
|
+
const { isLoading } = useDataGridContext();
|
|
81
79
|
const thRef = useRef<HTMLTableCellElement>(null);
|
|
82
80
|
const mergedRef = useMergeRefs(forwardedRef, thRef);
|
|
81
|
+
const { sortingState } = useDataTableContext();
|
|
82
|
+
const { onSortClick, sortState } = sortingState;
|
|
83
83
|
|
|
84
84
|
const resizeResult = useTableColumnResize({
|
|
85
|
-
|
|
85
|
+
...width,
|
|
86
86
|
thRef,
|
|
87
|
-
|
|
88
|
-
defaultWidth,
|
|
89
|
-
autoWidth,
|
|
90
|
-
minWidth,
|
|
91
|
-
maxWidth,
|
|
92
|
-
onWidthChange,
|
|
93
|
-
style,
|
|
94
|
-
colSpan,
|
|
87
|
+
colSpan: rest.colSpan,
|
|
95
88
|
});
|
|
96
89
|
|
|
97
|
-
const
|
|
90
|
+
const sortDirection = useMemo(() => {
|
|
91
|
+
const sortEntry = sortState.find((s) => s.columnId === id);
|
|
92
|
+
return sortEntry?.direction ?? "none";
|
|
93
|
+
}, [id, sortState]);
|
|
94
|
+
|
|
95
|
+
const canSort = sortable && id !== undefined;
|
|
96
|
+
|
|
97
|
+
const SortIcon = canSort ? SORT_ICON[sortDirection] : null;
|
|
98
|
+
|
|
99
|
+
const contentId = `th-content-${id.replace(/\s/g, "-")}`;
|
|
98
100
|
|
|
99
101
|
return (
|
|
100
102
|
<DataTableBaseCell
|
|
@@ -102,20 +104,20 @@ const DataTableColumnHeader = forwardRef<
|
|
|
102
104
|
{...rest}
|
|
103
105
|
ref={mergedRef}
|
|
104
106
|
className={cl("aksel-data-table__column-header", className)}
|
|
105
|
-
data-sortable={
|
|
106
|
-
style={resizeResult.
|
|
107
|
-
aria-sort={
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
rowSpan={rowSpan}
|
|
107
|
+
data-sortable={canSort}
|
|
108
|
+
style={{ ...style, width: resizeResult.width }}
|
|
109
|
+
aria-sort={canSort ? getAriaSort(sortDirection) : undefined}
|
|
110
|
+
cellType={cellType}
|
|
111
|
+
aria-labelledby={contentId} // Avoids VO announcing "Endre bredde" when navigating horizontally in tbody
|
|
111
112
|
>
|
|
112
|
-
{
|
|
113
|
+
{canSort ? (
|
|
113
114
|
<button
|
|
114
115
|
type="button"
|
|
115
116
|
className="aksel-data-table__th-sort-button"
|
|
116
|
-
onClick={onSortClick}
|
|
117
|
+
onClick={(event) => onSortClick(id, event)}
|
|
118
|
+
disabled={isLoading}
|
|
117
119
|
>
|
|
118
|
-
<div
|
|
120
|
+
<div id={contentId} className="aksel-data-table__th-content">
|
|
119
121
|
{children}
|
|
120
122
|
</div>
|
|
121
123
|
{SortIcon && (
|
|
@@ -129,16 +131,16 @@ const DataTableColumnHeader = forwardRef<
|
|
|
129
131
|
</button>
|
|
130
132
|
) : (
|
|
131
133
|
<div
|
|
132
|
-
|
|
134
|
+
id={contentId}
|
|
133
135
|
className={cl({
|
|
134
|
-
"aksel-data-table__th-content":
|
|
136
|
+
"aksel-data-table__th-content": cellType !== "action",
|
|
135
137
|
})}
|
|
136
138
|
>
|
|
137
139
|
{children}
|
|
138
140
|
</div>
|
|
139
141
|
)}
|
|
140
142
|
|
|
141
|
-
{resizeResult.enabled &&
|
|
143
|
+
{resizeResult.enabled && cellType !== "action" && (
|
|
142
144
|
<button
|
|
143
145
|
{...resizeResult.resizeHandlerProps}
|
|
144
146
|
type="button"
|
|
@@ -153,23 +155,21 @@ const DataTableColumnHeader = forwardRef<
|
|
|
153
155
|
data-block-keyboard-nav
|
|
154
156
|
role="slider"
|
|
155
157
|
aria-valuenow={
|
|
156
|
-
typeof resizeResult.
|
|
157
|
-
? resizeResult.style.width
|
|
158
|
-
: 0
|
|
158
|
+
typeof resizeResult.width === "number" ? resizeResult.width : 0
|
|
159
159
|
}
|
|
160
160
|
aria-valuetext={
|
|
161
|
-
typeof resizeResult.
|
|
161
|
+
typeof resizeResult.width === "number" &&
|
|
162
162
|
resizeResult.isResizingWithKeyboard
|
|
163
|
-
? resizeResult.
|
|
164
|
-
: "" // Needs to be blank when not in keyboard resizing mode to avoid NVDA announcing the value as part of the column heading
|
|
163
|
+
? resizeResult.width.toString()
|
|
164
|
+
: " " // Needs to be blank when not in keyboard resizing mode to avoid NVDA announcing the value as part of the column heading
|
|
165
165
|
} // Need either this or aria-valuemax to get SR (at least NVDA) to announce the value
|
|
166
166
|
>
|
|
167
167
|
{resizeResult.isResizingWithKeyboard && (
|
|
168
168
|
<>
|
|
169
|
-
<span className="aksel-data-table__th-resize-handle-indicator
|
|
169
|
+
<span className="aksel-data-table__th-resize-handle-indicator">
|
|
170
170
|
<CaretLeftCircleFillIcon aria-hidden fontSize="1.5rem" />
|
|
171
171
|
</span>
|
|
172
|
-
<span className="aksel-data-table__th-resize-handle-indicator
|
|
172
|
+
<span className="aksel-data-table__th-resize-handle-indicator">
|
|
173
173
|
<CaretRightCircleFillIcon aria-hidden fontSize="1.5rem" />
|
|
174
174
|
</span>
|
|
175
175
|
</>
|
|
@@ -182,7 +182,7 @@ const DataTableColumnHeader = forwardRef<
|
|
|
182
182
|
);
|
|
183
183
|
|
|
184
184
|
function getAriaSort(
|
|
185
|
-
sortDirection:
|
|
185
|
+
sortDirection: "asc" | "desc" | "none" | undefined,
|
|
186
186
|
): "ascending" | "descending" | "none" | undefined {
|
|
187
187
|
if (sortDirection === "asc") return "ascending";
|
|
188
188
|
if (sortDirection === "desc") return "descending";
|
|
@@ -26,61 +26,51 @@ type ResizeProps = {
|
|
|
26
26
|
* consider using `layout="auto"` on the root instead for better performance.
|
|
27
27
|
*
|
|
28
28
|
* **NB:** This can cause a layout shift. Set a good initial width with `width` or `defaultWidth` to mitigate this.
|
|
29
|
+
*
|
|
30
|
+
* **NB:** Does not work with block content.
|
|
29
31
|
*/
|
|
30
|
-
|
|
32
|
+
autoResizeOnce?: boolean;
|
|
31
33
|
/**
|
|
32
|
-
* Minimum width of the column when resizing. Only used when `resizable` or `
|
|
34
|
+
* Minimum width of the column when resizing. Only used when `resizable` or `autoResizeOnce` is enabled.
|
|
33
35
|
* @default 40
|
|
34
36
|
*/
|
|
35
|
-
|
|
37
|
+
resizeMin?: number;
|
|
36
38
|
/**
|
|
37
|
-
* Maximum width of the column when resizing. Only used when `resizable` or `
|
|
39
|
+
* Maximum width of the column when resizing. Only used when `resizable` or `autoResizeOnce` is enabled.
|
|
38
40
|
*/
|
|
39
|
-
|
|
41
|
+
resizeMax?: number;
|
|
40
42
|
// TODO: Consider "allowing" %-width on last column, if we find a solution to the overflow issue (width becomes 0px).
|
|
41
43
|
/**
|
|
42
|
-
* Controlled width of the column. Does not respect `
|
|
44
|
+
* Controlled width of the column. (Does not respect `resizeMin` and `resizeMax`.)
|
|
43
45
|
*
|
|
44
|
-
* Should only be used to fully control column width state. Otherwise, use `
|
|
46
|
+
* Should only be used to fully control column width state. Otherwise, use `default` and let the component handle resizing.
|
|
45
47
|
*
|
|
46
48
|
* **NB:** Percentage as initial width does not work well with resizing.
|
|
47
49
|
*/
|
|
48
|
-
|
|
50
|
+
value?: number | string;
|
|
49
51
|
/**
|
|
50
|
-
* Initial width of the column. Only used when `
|
|
51
|
-
* Does not respect `
|
|
52
|
+
* Initial width of the column. Only used when `value` is not set.
|
|
53
|
+
* (Does not respect `resizeMin` and `resizeMax`.)
|
|
52
54
|
*
|
|
53
55
|
* **NB:** Percentage as initial width does not work well with resizing.
|
|
54
56
|
* @default 140px
|
|
55
57
|
*/
|
|
56
|
-
|
|
58
|
+
defaultValue?: number | string;
|
|
57
59
|
/**
|
|
58
60
|
* Called when the column width changes.
|
|
59
61
|
* @param width New width in pixels.
|
|
60
62
|
*/
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Forwarded styles
|
|
64
|
-
*/
|
|
65
|
-
style?: React.CSSProperties;
|
|
66
|
-
/**
|
|
67
|
-
* Forwarded colSpan
|
|
68
|
-
*/
|
|
69
|
-
colSpan?: number;
|
|
63
|
+
onChange?: (width: number) => void;
|
|
70
64
|
};
|
|
71
65
|
|
|
72
|
-
type
|
|
73
|
-
[K in keyof T]: T[K] | undefined;
|
|
74
|
-
};
|
|
75
|
-
type Unomittable<T> = WithUndefined<Required<T>>;
|
|
76
|
-
|
|
77
|
-
type TableColumnResizeArgs = Unomittable<ResizeProps> & {
|
|
66
|
+
type TableColumnResizeArgs = ResizeProps & {
|
|
78
67
|
thRef: React.RefObject<HTMLTableCellElement | null>;
|
|
68
|
+
colSpan: number | undefined;
|
|
79
69
|
};
|
|
80
70
|
|
|
81
71
|
type TableColumnResizeResult =
|
|
82
72
|
| {
|
|
83
|
-
|
|
73
|
+
width: number | string;
|
|
84
74
|
resizeHandlerProps: {
|
|
85
75
|
onMouseDown: DOMAttributes<HTMLButtonElement>["onMouseDown"];
|
|
86
76
|
onTouchStart: DOMAttributes<HTMLButtonElement>["onTouchStart"];
|
|
@@ -93,59 +83,53 @@ type TableColumnResizeResult =
|
|
|
93
83
|
enabled: true;
|
|
94
84
|
}
|
|
95
85
|
| {
|
|
96
|
-
|
|
86
|
+
width?: number | string;
|
|
97
87
|
enabled: false;
|
|
98
88
|
};
|
|
99
89
|
|
|
100
90
|
/**
|
|
101
91
|
* TODO:
|
|
102
|
-
* - Do we allow % widths?
|
|
103
92
|
* - Auto-width mode is hard now since that might cause layout-shifts on mount. But would be preferable to
|
|
104
93
|
* be able to set "1fr" or similar and have it fill remaining space.
|
|
105
94
|
*/
|
|
106
|
-
function useTableColumnResize(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
minWidth = 40,
|
|
118
|
-
style,
|
|
119
|
-
colSpan,
|
|
120
|
-
} = args;
|
|
121
|
-
|
|
95
|
+
function useTableColumnResize({
|
|
96
|
+
resizable = true,
|
|
97
|
+
autoResizeOnce,
|
|
98
|
+
resizeMin = 40,
|
|
99
|
+
resizeMax = Infinity,
|
|
100
|
+
value,
|
|
101
|
+
defaultValue,
|
|
102
|
+
onChange,
|
|
103
|
+
thRef,
|
|
104
|
+
colSpan,
|
|
105
|
+
}: TableColumnResizeArgs): TableColumnResizeResult {
|
|
122
106
|
const tableContext = useDataTableContext();
|
|
123
107
|
|
|
124
108
|
const [isResizingWithKeyboard, setIsResizingWithKeyboard] = useState(false);
|
|
125
109
|
const ignoreNextOnClick = useRef(false);
|
|
126
110
|
|
|
127
111
|
const [width, setWidth] = useControllableState({
|
|
128
|
-
value
|
|
129
|
-
defaultValue:
|
|
112
|
+
value,
|
|
113
|
+
defaultValue: defaultValue ?? (colSpan ?? 1) * 140,
|
|
130
114
|
/**
|
|
131
115
|
* TODO:
|
|
132
116
|
* - Potential optimization: Only call when width as "stopped" changing, e.g. on mouse up or after a debounce when resizing with keyboard.
|
|
133
117
|
* Otherwise, this could cause excessive calls when resizing quickly.
|
|
134
118
|
*/
|
|
135
|
-
onChange
|
|
119
|
+
onChange,
|
|
136
120
|
});
|
|
137
121
|
|
|
138
122
|
const setClampedWidth = useCallback(
|
|
139
123
|
(newWidth: number) => {
|
|
140
|
-
setWidth(Math.min(Math.max(newWidth,
|
|
124
|
+
setWidth(Math.min(Math.max(newWidth, resizeMin), resizeMax));
|
|
141
125
|
},
|
|
142
|
-
[
|
|
126
|
+
[resizeMin, resizeMax, setWidth],
|
|
143
127
|
);
|
|
144
128
|
|
|
145
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: We only want to run this on mount and when
|
|
129
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: We only want to run this on mount and when autoResizeOnce changes
|
|
146
130
|
useEffect(
|
|
147
131
|
function autoResizeColumn() {
|
|
148
|
-
if (!
|
|
132
|
+
if (!autoResizeOnce) {
|
|
149
133
|
return;
|
|
150
134
|
}
|
|
151
135
|
|
|
@@ -154,20 +138,19 @@ function useTableColumnResize(
|
|
|
154
138
|
setClampedWidth(newColumnWidth);
|
|
155
139
|
}
|
|
156
140
|
},
|
|
157
|
-
[
|
|
141
|
+
[autoResizeOnce], // eslint-disable-line react-hooks/exhaustive-deps
|
|
158
142
|
);
|
|
159
143
|
|
|
160
144
|
const handleOnClick: DOMAttributes<HTMLButtonElement>["onClick"] =
|
|
161
145
|
useCallback(() => {
|
|
162
146
|
// We need to use the onClick event in order to support screen readers properly,
|
|
163
|
-
// since some of them only send a mouse click when pressing enter/space.
|
|
147
|
+
// since some of them only send a mouse click (no kbd events) when pressing enter/space.
|
|
164
148
|
// We detect a "screen reader click" by checking if we had a mouseUp event right before.
|
|
165
149
|
|
|
166
150
|
if (ignoreNextOnClick.current) {
|
|
167
151
|
ignoreNextOnClick.current = false;
|
|
168
152
|
return;
|
|
169
153
|
}
|
|
170
|
-
|
|
171
154
|
setIsResizingWithKeyboard((prev) => !prev);
|
|
172
155
|
}, []);
|
|
173
156
|
|
|
@@ -213,11 +196,11 @@ function useTableColumnResize(
|
|
|
213
196
|
const currentWidth = thRef.current?.offsetWidth ?? 0;
|
|
214
197
|
const newWidth = startWidth + (clientX - startX);
|
|
215
198
|
|
|
216
|
-
if (newWidth >
|
|
199
|
+
if (newWidth > resizeMax) {
|
|
217
200
|
setWidth(newWidth < currentWidth ? newWidth : currentWidth);
|
|
218
201
|
return;
|
|
219
202
|
}
|
|
220
|
-
if (newWidth <
|
|
203
|
+
if (newWidth < resizeMin) {
|
|
221
204
|
setWidth(newWidth > currentWidth ? newWidth : currentWidth);
|
|
222
205
|
return;
|
|
223
206
|
}
|
|
@@ -250,7 +233,7 @@ function useTableColumnResize(
|
|
|
250
233
|
document.addEventListener("touchend", cleanup, { once: true });
|
|
251
234
|
document.addEventListener("touchcancel", cleanup, { once: true });
|
|
252
235
|
},
|
|
253
|
-
[
|
|
236
|
+
[resizeMax, resizeMin, setWidth, setClampedWidth, thRef],
|
|
254
237
|
);
|
|
255
238
|
|
|
256
239
|
const handleMouseDown: DOMAttributes<HTMLButtonElement>["onMouseDown"] =
|
|
@@ -269,7 +252,7 @@ function useTableColumnResize(
|
|
|
269
252
|
[startResize],
|
|
270
253
|
);
|
|
271
254
|
|
|
272
|
-
// Auto-size column to fit content on double click
|
|
255
|
+
// Auto-size column to fit content on double click
|
|
273
256
|
const handleDoubleClick: DOMAttributes<HTMLButtonElement>["onDoubleClick"] =
|
|
274
257
|
useCallback(() => {
|
|
275
258
|
const newColumnWidth = getAutoColumnWidth(thRef);
|
|
@@ -280,26 +263,20 @@ function useTableColumnResize(
|
|
|
280
263
|
|
|
281
264
|
if (tableContext.layout !== "fixed") {
|
|
282
265
|
return {
|
|
283
|
-
style,
|
|
284
266
|
enabled: false,
|
|
285
267
|
};
|
|
286
268
|
}
|
|
287
269
|
|
|
288
270
|
if (!resizable) {
|
|
289
271
|
return {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
width,
|
|
293
|
-
},
|
|
272
|
+
width,
|
|
273
|
+
|
|
294
274
|
enabled: false,
|
|
295
275
|
};
|
|
296
276
|
}
|
|
297
277
|
|
|
298
278
|
return {
|
|
299
|
-
|
|
300
|
-
...style,
|
|
301
|
-
width,
|
|
302
|
-
},
|
|
279
|
+
width,
|
|
303
280
|
resizeHandlerProps: {
|
|
304
281
|
onMouseDown: handleMouseDown,
|
|
305
282
|
onTouchStart: handleTouchStart,
|
|
@@ -313,12 +290,16 @@ function useTableColumnResize(
|
|
|
313
290
|
};
|
|
314
291
|
}
|
|
315
292
|
|
|
293
|
+
/**
|
|
294
|
+
* Figures out how wide the column needs to be to fit all the content without truncation.
|
|
295
|
+
* NB: Does not work with block content!
|
|
296
|
+
*/
|
|
316
297
|
function getAutoColumnWidth(
|
|
317
298
|
thRef: React.RefObject<HTMLTableCellElement | null>,
|
|
318
299
|
) {
|
|
319
300
|
const th = thRef.current!;
|
|
320
301
|
const thContent = th.querySelector(".aksel-data-table__th-content");
|
|
321
|
-
const thPaddingEl = th.querySelector("
|
|
302
|
+
const thPaddingEl = th.querySelector(".aksel-data-table__cell-content");
|
|
322
303
|
const rows = th.closest("table")?.querySelectorAll("tbody tr, tfoot tr");
|
|
323
304
|
if (!thContent || !thPaddingEl || !rows) {
|
|
324
305
|
return;
|
|
@@ -361,17 +342,20 @@ function getAutoColumnWidth(
|
|
|
361
342
|
skipRows = cell.rowSpan - 1;
|
|
362
343
|
|
|
363
344
|
// Find needed width
|
|
364
|
-
const cellContent = cell.
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
345
|
+
const cellContent = cell.querySelector(
|
|
346
|
+
".aksel-data-table__cell-content",
|
|
347
|
+
) as HTMLElement | null;
|
|
348
|
+
|
|
349
|
+
if (!cellContent) {
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
cellContent.style.width = "fit-content";
|
|
354
|
+
const cellContentWidth = cellContent.scrollWidth;
|
|
355
|
+
cellContent.style.removeProperty("width");
|
|
356
|
+
const widthNeededForThisCell = (cellContentWidth + 1) / cell.colSpan;
|
|
373
357
|
if (widthNeededForThisCell > newColumnWidth) {
|
|
374
|
-
newColumnWidth = widthNeededForThisCell;
|
|
358
|
+
newColumnWidth = Math.ceil(widthNeededForThisCell);
|
|
375
359
|
}
|
|
376
360
|
}
|
|
377
361
|
|
|
@@ -9,10 +9,10 @@ function DataTableDetailsPanelRow<T>({
|
|
|
9
9
|
rowId,
|
|
10
10
|
rowData,
|
|
11
11
|
}: {
|
|
12
|
-
rowId: string
|
|
12
|
+
rowId: string;
|
|
13
13
|
rowData: T;
|
|
14
14
|
}) {
|
|
15
|
-
const { tableId,
|
|
15
|
+
const { tableId, totalColSpan } = useDataTableContext();
|
|
16
16
|
const {
|
|
17
17
|
enableDetailsPanel,
|
|
18
18
|
isExpanded,
|
|
@@ -45,7 +45,7 @@ function DataTableDetailsPanelRow<T>({
|
|
|
45
45
|
<tr className="aksel-data-table__details-panel-row">
|
|
46
46
|
<td
|
|
47
47
|
id={expansionId}
|
|
48
|
-
colSpan={
|
|
48
|
+
colSpan={totalColSpan}
|
|
49
49
|
className="aksel-data-table__details-panel-row-cell"
|
|
50
50
|
>
|
|
51
51
|
<div style={style}>{content}</div>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type TableRowEntryId
|
|
1
|
+
import type { TableRowEntryId } from "../root/DataGridTable.types";
|
|
2
2
|
|
|
3
3
|
type CollectTableRowEntriesArgs<T> = {
|
|
4
4
|
items: T[];
|
|
@@ -91,6 +91,5 @@ export { collectTableRowEntries };
|
|
|
91
91
|
export type {
|
|
92
92
|
CollectTableRowEntriesArgs,
|
|
93
93
|
CollectTableRowEntriesReturn,
|
|
94
|
-
TableRowEntryId,
|
|
95
94
|
ItemDetail,
|
|
96
95
|
};
|