@navikt/ds-react 8.10.6 → 8.11.1
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 +5 -1
- package/cjs/data/drag-and-drop/drag-handler/DragAndDropDragHandler.js.map +1 -1
- package/cjs/data/drag-and-drop/root/DragAndDropRoot.d.ts +1 -1
- package/cjs/data/drag-and-drop/root/DragAndDropRoot.js +50 -20
- 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 -4
- package/cjs/data/table/column-header/useTableColumnResize.js +15 -11
- 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/helpers/table-focus.js +1 -1
- package/cjs/data/table/helpers/table-focus.js.map +1 -1
- package/cjs/data/table/hooks/useColumnOptions.d.ts +8 -5
- package/cjs/data/table/hooks/useColumnOptions.js +25 -10
- 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} +59 -38
- 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 +45 -23
- 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 +48 -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 +35 -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/primitives/bleed/Bleed.d.ts +0 -2
- package/cjs/primitives/bleed/Bleed.js.map +1 -1
- package/cjs/table/ColumnHeader.js.map +1 -1
- package/cjs/tabs/Tabs.context.d.ts +1 -1
- package/cjs/tabs/useTabs.d.ts +1 -1
- package/cjs/toggle-group/ToggleGroup.context.d.ts +1 -1
- package/cjs/toggle-group/useToggleGroup.d.ts +1 -1
- package/cjs/utils/components/dismissablelayer/DismissableLayer.js +1 -0
- package/cjs/utils/components/dismissablelayer/DismissableLayer.js.map +1 -1
- package/cjs/utils/components/dismissablelayer/util/useFocusOutside.d.ts +1 -0
- package/cjs/utils/components/dismissablelayer/util/useFocusOutside.js +11 -1
- package/cjs/utils/components/dismissablelayer/util/useFocusOutside.js.map +1 -1
- package/cjs/utils/hooks/useControllableState.d.ts +1 -1
- package/cjs/utils/hooks/useControllableState.js.map +1 -1
- package/esm/data/drag-and-drop/drag-handler/DragAndDropDragHandler.js +5 -1
- package/esm/data/drag-and-drop/drag-handler/DragAndDropDragHandler.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 +51 -21
- 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 -4
- package/esm/data/table/column-header/useTableColumnResize.js +15 -11
- 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/helpers/table-focus.js +1 -1
- package/esm/data/table/helpers/table-focus.js.map +1 -1
- package/esm/data/table/hooks/useColumnOptions.d.ts +8 -5
- package/esm/data/table/hooks/useColumnOptions.js +25 -10
- 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} +61 -39
- 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 +45 -23
- 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 +48 -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 +59 -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/primitives/bleed/Bleed.d.ts +0 -2
- package/esm/primitives/bleed/Bleed.js.map +1 -1
- package/esm/table/ColumnHeader.js.map +1 -1
- package/esm/tabs/Tabs.context.d.ts +1 -1
- package/esm/tabs/useTabs.d.ts +1 -1
- package/esm/toggle-group/ToggleGroup.context.d.ts +1 -1
- package/esm/toggle-group/useToggleGroup.d.ts +1 -1
- package/esm/utils/components/dismissablelayer/DismissableLayer.js +1 -0
- package/esm/utils/components/dismissablelayer/DismissableLayer.js.map +1 -1
- package/esm/utils/components/dismissablelayer/util/useFocusOutside.d.ts +1 -0
- package/esm/utils/components/dismissablelayer/util/useFocusOutside.js +12 -2
- package/esm/utils/components/dismissablelayer/util/useFocusOutside.js.map +1 -1
- package/esm/utils/hooks/useControllableState.d.ts +1 -1
- package/esm/utils/hooks/useControllableState.js.map +1 -1
- package/package.json +25 -5
- package/src/data/drag-and-drop/drag-handler/DragAndDropDragHandler.tsx +5 -1
- package/src/data/drag-and-drop/root/DragAndDropRoot.tsx +55 -25
- 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 +19 -16
- 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 +18 -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/helpers/table-focus.ts +1 -1
- package/src/data/table/hooks/__tests__/useTableItems.test.ts +1 -1
- package/src/data/table/hooks/useColumnOptions.ts +50 -15
- 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} +198 -144
- 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 -20
- 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 +46 -0
- package/src/data-grid/root/DataGridRoot.context.ts +21 -0
- package/src/data-grid/root/DataGridRoot.tsx +154 -0
- package/src/preview.ts +2 -0
- package/src/primitives/bleed/Bleed.tsx +0 -2
- package/src/table/ColumnHeader.tsx +1 -0
- package/src/utils/components/dismissablelayer/DismissableLayer.tsx +1 -0
- package/src/utils/components/dismissablelayer/util/useFocusOutside.ts +14 -2
- package/src/utils/hooks/useControllableState.ts +10 -8
- 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
|
@@ -7,12 +7,12 @@ interface DataTableBaseCellProps extends Omit<
|
|
|
7
7
|
"width"
|
|
8
8
|
> {
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Text alignment inside cell.
|
|
11
11
|
*
|
|
12
12
|
* Quantitative figures like amounts and percentages should be right‑aligned (but not phone numbers, postal codes etc.)
|
|
13
13
|
* @default "left"
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
align?: "left" | "center" | "right";
|
|
16
16
|
/**
|
|
17
17
|
* Internal cell type that controls padding, alignment, row-click prevention, and resize behavior.
|
|
18
18
|
* - `"action"`: Centers content, removes cell padding, prevents row click, and disables column resize.
|
|
@@ -20,7 +20,7 @@ interface DataTableBaseCellProps extends Omit<
|
|
|
20
20
|
*/
|
|
21
21
|
cellType?: "action";
|
|
22
22
|
/**
|
|
23
|
-
* When true, clicking this cell will not trigger `
|
|
23
|
+
* When true, clicking this cell will not trigger `onRowAction` on the row.
|
|
24
24
|
* Useful for cells that contain their own interactive content or actions
|
|
25
25
|
* that should be independent of row-level click handling.
|
|
26
26
|
*/
|
|
@@ -28,7 +28,7 @@ interface DataTableBaseCellProps extends Omit<
|
|
|
28
28
|
/**
|
|
29
29
|
* Sets a max-width on the content wrapper div inside the cell.
|
|
30
30
|
* This is only needed when using `layout="auto"` together with
|
|
31
|
-
* `truncateContent` on `<
|
|
31
|
+
* `truncateContent` on `<DataGrid.Table>` and you want the cell to be truncated.
|
|
32
32
|
*/
|
|
33
33
|
contentMaxWidth?: number | string;
|
|
34
34
|
/**
|
|
@@ -58,7 +58,7 @@ const DataTableBaseCell = forwardRef<
|
|
|
58
58
|
children,
|
|
59
59
|
as: Component,
|
|
60
60
|
beforeContent,
|
|
61
|
-
|
|
61
|
+
align = "left",
|
|
62
62
|
cellType,
|
|
63
63
|
preventRowClick,
|
|
64
64
|
contentMaxWidth,
|
|
@@ -77,7 +77,7 @@ const DataTableBaseCell = forwardRef<
|
|
|
77
77
|
ref={forwardedRef}
|
|
78
78
|
className={cl("aksel-data-table__cell", className)}
|
|
79
79
|
tabIndex={withKeyboardNav ? -1 : undefined}
|
|
80
|
-
data-align={
|
|
80
|
+
data-align={align}
|
|
81
81
|
data-cell-type={cellType || undefined}
|
|
82
82
|
data-prevent-row-click={
|
|
83
83
|
preventRowClick || cellType === "action" || undefined
|
|
@@ -6,21 +6,21 @@ 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 type { SortDirection } from "../root/DataTable.types";
|
|
16
16
|
import { useDataTableContext } from "../root/DataTableRoot.context";
|
|
17
17
|
import { type ResizeProps, useTableColumnResize } from "./useTableColumnResize";
|
|
18
18
|
|
|
19
19
|
interface DataTableColumnHeaderProps extends DataTableBaseCellProps {
|
|
20
20
|
/**
|
|
21
|
-
* Unique identifier for the column.
|
|
21
|
+
* Unique identifier for the column. Used when sorting to identify which column is being sorted.
|
|
22
22
|
*/
|
|
23
|
-
id
|
|
23
|
+
id: string;
|
|
24
24
|
/**
|
|
25
25
|
* Accessible name of the column.
|
|
26
26
|
*/
|
|
@@ -29,18 +29,7 @@ interface DataTableColumnHeaderProps extends DataTableBaseCellProps {
|
|
|
29
29
|
* Makes the column sortable by clicking on the header.
|
|
30
30
|
* The entire header cell content becomes a clickable button when true.
|
|
31
31
|
*/
|
|
32
|
-
sortable?: boolean;
|
|
33
|
-
/**
|
|
34
|
-
* Current sort direction. Only relevant when `sortable` is true.
|
|
35
|
-
* Uses values matching the `aria-sort` attribute directly. // TODO: What does this mean? (Can we just remove it?)
|
|
36
|
-
* @default "none"
|
|
37
|
-
*/
|
|
38
|
-
sortDirection?: SortDirection; // TODO Not in use???
|
|
39
|
-
/**
|
|
40
|
-
* Called when the user clicks the header. Only relevant when `sortable` is true.
|
|
41
|
-
* The consumer is responsible for determining and setting the next sort state. // TODO: We don't use the term "consumer" in JSDoc anywhere else
|
|
42
|
-
*/
|
|
43
|
-
onSortClick?: (event: React.MouseEvent<HTMLElement>) => void; // TODO Not in use???
|
|
32
|
+
sortable?: boolean;
|
|
44
33
|
/**
|
|
45
34
|
* Object with props related to column width and resizing. Summary:
|
|
46
35
|
*
|
|
@@ -49,7 +38,7 @@ interface DataTableColumnHeaderProps extends DataTableBaseCellProps {
|
|
|
49
38
|
* - `resizeMin?: number` - Minimum width of the column when resizing.
|
|
50
39
|
* - `resizeMax?: number` - Maximum width of the column when resizing.
|
|
51
40
|
* - `value?: number | string` - Controlled width of the column.
|
|
52
|
-
* - `
|
|
41
|
+
* - `defaultValue?: number | string` - Initial width of the column.
|
|
53
42
|
* - `onChange?: (width: number) => void` - Called when the column width changes.
|
|
54
43
|
*
|
|
55
44
|
* See individual props for details and defaults.
|
|
@@ -57,7 +46,7 @@ interface DataTableColumnHeaderProps extends DataTableBaseCellProps {
|
|
|
57
46
|
width?: ResizeProps;
|
|
58
47
|
}
|
|
59
48
|
|
|
60
|
-
const SORT_ICON: Record<
|
|
49
|
+
const SORT_ICON: Record<"asc" | "desc" | "none", React.ElementType> = {
|
|
61
50
|
asc: SortUpIcon,
|
|
62
51
|
desc: SortDownIcon,
|
|
63
52
|
none: ArrowsUpDownIcon,
|
|
@@ -86,6 +75,7 @@ const DataTableColumnHeader = forwardRef<
|
|
|
86
75
|
},
|
|
87
76
|
forwardedRef,
|
|
88
77
|
) => {
|
|
78
|
+
const { isLoading } = useDataGridContext();
|
|
89
79
|
const thRef = useRef<HTMLTableCellElement>(null);
|
|
90
80
|
const mergedRef = useMergeRefs(forwardedRef, thRef);
|
|
91
81
|
const { sortingState } = useDataTableContext();
|
|
@@ -106,6 +96,8 @@ const DataTableColumnHeader = forwardRef<
|
|
|
106
96
|
|
|
107
97
|
const SortIcon = canSort ? SORT_ICON[sortDirection] : null;
|
|
108
98
|
|
|
99
|
+
const contentId = `th-content-${id.replace(/\s/g, "-")}`;
|
|
100
|
+
|
|
109
101
|
return (
|
|
110
102
|
<DataTableBaseCell
|
|
111
103
|
as="th"
|
|
@@ -116,14 +108,18 @@ const DataTableColumnHeader = forwardRef<
|
|
|
116
108
|
style={{ ...style, width: resizeResult.width }}
|
|
117
109
|
aria-sort={canSort ? getAriaSort(sortDirection) : undefined}
|
|
118
110
|
cellType={cellType}
|
|
111
|
+
aria-labelledby={contentId} // Avoids VO announcing "Endre bredde" when navigating horizontally in tbody
|
|
119
112
|
>
|
|
120
113
|
{canSort ? (
|
|
121
114
|
<button
|
|
122
115
|
type="button"
|
|
123
116
|
className="aksel-data-table__th-sort-button"
|
|
124
117
|
onClick={(event) => onSortClick(id, event)}
|
|
118
|
+
disabled={isLoading}
|
|
125
119
|
>
|
|
126
|
-
<div className="aksel-data-table__th-content">
|
|
120
|
+
<div id={contentId} className="aksel-data-table__th-content">
|
|
121
|
+
{children}
|
|
122
|
+
</div>
|
|
127
123
|
{SortIcon && (
|
|
128
124
|
<SortIcon
|
|
129
125
|
aria-hidden
|
|
@@ -135,6 +131,7 @@ const DataTableColumnHeader = forwardRef<
|
|
|
135
131
|
</button>
|
|
136
132
|
) : (
|
|
137
133
|
<div
|
|
134
|
+
id={contentId}
|
|
138
135
|
className={cl({
|
|
139
136
|
"aksel-data-table__th-content": cellType !== "action",
|
|
140
137
|
})}
|
|
@@ -164,7 +161,7 @@ const DataTableColumnHeader = forwardRef<
|
|
|
164
161
|
typeof resizeResult.width === "number" &&
|
|
165
162
|
resizeResult.isResizingWithKeyboard
|
|
166
163
|
? resizeResult.width.toString()
|
|
167
|
-
: "" // Needs to be blank when not in keyboard resizing mode to avoid NVDA announcing the value as part of the column heading
|
|
164
|
+
: " " // Needs to be blank when not in keyboard resizing mode to avoid NVDA announcing the value as part of the column heading
|
|
168
165
|
} // Need either this or aria-valuemax to get SR (at least NVDA) to announce the value
|
|
169
166
|
>
|
|
170
167
|
{resizeResult.isResizingWithKeyboard && (
|
|
@@ -185,7 +182,7 @@ const DataTableColumnHeader = forwardRef<
|
|
|
185
182
|
);
|
|
186
183
|
|
|
187
184
|
function getAriaSort(
|
|
188
|
-
sortDirection:
|
|
185
|
+
sortDirection: "asc" | "desc" | "none" | undefined,
|
|
189
186
|
): "ascending" | "descending" | "none" | undefined {
|
|
190
187
|
if (sortDirection === "asc") return "ascending";
|
|
191
188
|
if (sortDirection === "desc") return "descending";
|
|
@@ -26,8 +26,6 @@ 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.
|
|
31
29
|
*/
|
|
32
30
|
autoResizeOnce?: boolean;
|
|
33
31
|
/**
|
|
@@ -55,7 +53,7 @@ type ResizeProps = {
|
|
|
55
53
|
* **NB:** Percentage as initial width does not work well with resizing.
|
|
56
54
|
* @default 140px
|
|
57
55
|
*/
|
|
58
|
-
|
|
56
|
+
defaultValue?: number | string;
|
|
59
57
|
/**
|
|
60
58
|
* Called when the column width changes.
|
|
61
59
|
* @param width New width in pixels.
|
|
@@ -98,7 +96,7 @@ function useTableColumnResize({
|
|
|
98
96
|
resizeMin = 40,
|
|
99
97
|
resizeMax = Infinity,
|
|
100
98
|
value,
|
|
101
|
-
|
|
99
|
+
defaultValue,
|
|
102
100
|
onChange,
|
|
103
101
|
thRef,
|
|
104
102
|
colSpan,
|
|
@@ -110,7 +108,7 @@ function useTableColumnResize({
|
|
|
110
108
|
|
|
111
109
|
const [width, setWidth] = useControllableState({
|
|
112
110
|
value,
|
|
113
|
-
defaultValue:
|
|
111
|
+
defaultValue: defaultValue ?? (colSpan ?? 1) * 140,
|
|
114
112
|
/**
|
|
115
113
|
* TODO:
|
|
116
114
|
* - Potential optimization: Only call when width as "stopped" changing, e.g. on mouse up or after a debounce when resizing with keyboard.
|
|
@@ -292,7 +290,6 @@ function useTableColumnResize({
|
|
|
292
290
|
|
|
293
291
|
/**
|
|
294
292
|
* 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
293
|
*/
|
|
297
294
|
function getAutoColumnWidth(
|
|
298
295
|
thRef: React.RefObject<HTMLTableCellElement | null>,
|
|
@@ -344,18 +341,24 @@ function getAutoColumnWidth(
|
|
|
344
341
|
// Find needed width
|
|
345
342
|
const cellContent = cell.querySelector(
|
|
346
343
|
".aksel-data-table__cell-content",
|
|
347
|
-
) as HTMLElement;
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
const
|
|
344
|
+
) as HTMLElement | null;
|
|
345
|
+
|
|
346
|
+
if (!cellContent) {
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
cellContent.style.width = "fit-content";
|
|
351
|
+
const cellContentWidth = cellContent.scrollWidth;
|
|
352
|
+
cellContent.style.removeProperty("width");
|
|
353
|
+
let marginLeft = 0;
|
|
354
|
+
if (cell.dataset.nested === "true") {
|
|
355
|
+
const contentElStyle = window.getComputedStyle(cellContent);
|
|
356
|
+
marginLeft = parseInt(contentElStyle.marginLeft, 10);
|
|
357
|
+
}
|
|
355
358
|
const widthNeededForThisCell =
|
|
356
|
-
(cellContentWidth +
|
|
359
|
+
(cellContentWidth + marginLeft + 1) / cell.colSpan;
|
|
357
360
|
if (widthNeededForThisCell > newColumnWidth) {
|
|
358
|
-
newColumnWidth = widthNeededForThisCell;
|
|
361
|
+
newColumnWidth = Math.ceil(widthNeededForThisCell);
|
|
359
362
|
}
|
|
360
363
|
}
|
|
361
364
|
|
|
@@ -2,15 +2,16 @@ import type { ChangeEventHandler, SetStateAction } from "react";
|
|
|
2
2
|
import type { CheckboxInputProps } from "../../../../form/checkbox/checkbox-input/CheckboxInput";
|
|
3
3
|
import { consoleWarning } from "../../../../utils/helpers/consoleWarning";
|
|
4
4
|
import type { UseTableItemsReturn } from "../../hooks/useTableItems";
|
|
5
|
-
import type { TableRowEntryId } from "../../root/
|
|
6
|
-
import type {
|
|
5
|
+
import type { TableRowEntryId } from "../../root/DataGridTable.types";
|
|
6
|
+
import type { SelectionProps } from "./selection.types";
|
|
7
7
|
import { canSelectTableRow, mutateRowSelection } from "./selection.utils";
|
|
8
8
|
|
|
9
9
|
type GetMultipleSelectPropsArgs<T> = {
|
|
10
10
|
selectedKeysSet: Set<TableRowEntryId>;
|
|
11
|
-
selectedKeys:
|
|
12
|
-
setSelectedKeys: (next: SetStateAction<
|
|
11
|
+
selectedKeys: string[];
|
|
12
|
+
setSelectedKeys: (next: SetStateAction<string[]>) => void;
|
|
13
13
|
tableItems: UseTableItemsReturn<T>;
|
|
14
|
+
isLoading?: boolean;
|
|
14
15
|
} & Pick<SelectionProps<T>, "enableRowSelection">;
|
|
15
16
|
|
|
16
17
|
function getMultipleSelectProps<T>({
|
|
@@ -19,6 +20,7 @@ function getMultipleSelectProps<T>({
|
|
|
19
20
|
setSelectedKeys,
|
|
20
21
|
enableRowSelection,
|
|
21
22
|
tableItems,
|
|
23
|
+
isLoading,
|
|
22
24
|
}: GetMultipleSelectPropsArgs<T>) {
|
|
23
25
|
const selectableIdsSet: Set<TableRowEntryId> = new Set();
|
|
24
26
|
|
|
@@ -40,7 +42,7 @@ function getMultipleSelectProps<T>({
|
|
|
40
42
|
const handleToggleRow = (key: TableRowEntryId, row: T) => {
|
|
41
43
|
if (!row) {
|
|
42
44
|
consoleWarning(
|
|
43
|
-
`Row data is undefined for key ${key}. This may cause issues with selection if enableRowSelection is used.`,
|
|
45
|
+
`DataGrid.Table: Row data is undefined for key ${key}. This may cause issues with selection if enableRowSelection is used.`,
|
|
44
46
|
);
|
|
45
47
|
}
|
|
46
48
|
|
|
@@ -62,6 +64,9 @@ function getMultipleSelectProps<T>({
|
|
|
62
64
|
const toggleAllRowSelected: ChangeEventHandler<HTMLInputElement> = (
|
|
63
65
|
event,
|
|
64
66
|
) => {
|
|
67
|
+
if (isLoading) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
65
70
|
if (event.target.checked) {
|
|
66
71
|
const preserved = selectedKeys.filter((k) => !selectableIdsSet.has(k));
|
|
67
72
|
setSelectedKeys([...preserved, ...selectableIdsSet]);
|
|
@@ -75,6 +80,7 @@ function getMultipleSelectProps<T>({
|
|
|
75
80
|
checked: isAllSelected,
|
|
76
81
|
indeterminate: !isAllSelected && someSelected,
|
|
77
82
|
onChange: toggleAllRowSelected,
|
|
83
|
+
disabled: selectableIdsSet.size === 0 || isLoading,
|
|
78
84
|
}),
|
|
79
85
|
getRowCheckboxProps: (key: TableRowEntryId, row: T): CheckboxInputProps => {
|
|
80
86
|
return {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { RadioInputProps } from "../../../../form/radio/radio-input/RadioInput";
|
|
2
2
|
import { consoleWarning } from "../../../../utils/helpers/consoleWarning";
|
|
3
|
-
import type { TableRowEntryId } from "../../root/
|
|
4
|
-
import type {
|
|
3
|
+
import type { TableRowEntryId } from "../../root/DataGridTable.types";
|
|
4
|
+
import type { SelectionProps } from "./selection.types";
|
|
5
5
|
import { canSelectTableRow } from "./selection.utils";
|
|
6
6
|
|
|
7
7
|
type GetSingleSelectPropsArgs<T> = {
|
|
8
8
|
selectedKeysSet: Set<TableRowEntryId>;
|
|
9
|
-
setSelectedKeys: (keys:
|
|
9
|
+
setSelectedKeys: (keys: string[]) => void;
|
|
10
10
|
name: string;
|
|
11
11
|
} & Pick<SelectionProps<T>, "enableRowSelection">;
|
|
12
12
|
|
|
@@ -19,7 +19,7 @@ function getSingleSelectProps<T>({
|
|
|
19
19
|
const handleSelectionChange = (key: TableRowEntryId, row: T) => {
|
|
20
20
|
if (!row) {
|
|
21
21
|
consoleWarning(
|
|
22
|
-
`Row data is undefined for key ${key}. This may cause issues with selection if enableRowSelection is used.`,
|
|
22
|
+
`DataGrid.Table: Row data is undefined for key ${key}. This may cause issues with selection if enableRowSelection is used.`,
|
|
23
23
|
);
|
|
24
24
|
}
|
|
25
25
|
if (!canSelectTableRow(enableRowSelection, { row, id: key })) {
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import type { CheckboxInputProps } from "../../../../form/checkbox/checkbox-input/CheckboxInput";
|
|
2
2
|
import type { RadioInputProps } from "../../../../form/radio/radio-input/RadioInput";
|
|
3
|
-
import type { TableRowEntryId } from "../../root/DataTable.types";
|
|
4
3
|
|
|
5
|
-
type
|
|
6
|
-
|
|
7
|
-
// TODO: Remove `any` if possible
|
|
8
|
-
type SelectionProps<T = any> = {
|
|
4
|
+
type SelectionProps<T = unknown> = {
|
|
9
5
|
/**
|
|
10
6
|
* Enables selection of rows.
|
|
11
7
|
*
|
|
@@ -16,57 +12,51 @@ type SelectionProps<T = any> = {
|
|
|
16
12
|
*
|
|
17
13
|
* @default "none"
|
|
18
14
|
*/
|
|
19
|
-
|
|
15
|
+
mode: "none" | "single" | "multiple";
|
|
20
16
|
/**
|
|
21
|
-
* Controlled selected keys. Should be used in conjunction with `
|
|
17
|
+
* Controlled selected keys. Should be used in conjunction with `onSelectedRowIdsChange`.
|
|
22
18
|
*/
|
|
23
|
-
|
|
19
|
+
selectedRowIds?: string[];
|
|
24
20
|
/**
|
|
25
21
|
* Default selected keys when using uncontrolled selection. Should not be used together with `selectedKeys`.
|
|
26
22
|
*/
|
|
27
|
-
|
|
23
|
+
defaultSelectedRowIds?: string[];
|
|
28
24
|
/**
|
|
29
25
|
* Callback with array of selected keys.
|
|
30
26
|
*/
|
|
31
|
-
|
|
27
|
+
onSelectedRowIdsChange?: (ids: string[]) => void;
|
|
32
28
|
/**
|
|
33
29
|
* Callback to determine if a row should be enabled for selection.
|
|
34
30
|
*
|
|
35
|
-
*
|
|
36
31
|
* If set to a boolean, it will enable selection for all rows when true, and disable selection for all rows when false.
|
|
37
32
|
*/
|
|
38
33
|
enableRowSelection?:
|
|
39
|
-
| (({ row, id }: { row: T; id:
|
|
34
|
+
| (({ row, id }: { row: T; id: string }) => boolean)
|
|
40
35
|
| boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Determines if selection is triggered by clicking the row or the selection control (checkbox/radio).
|
|
43
|
-
* @default "row"
|
|
44
|
-
*/
|
|
45
|
-
selectionTrigger?: "row" | "control";
|
|
46
36
|
};
|
|
47
37
|
|
|
48
38
|
type NoneSelection = {
|
|
49
|
-
|
|
50
|
-
selectedKeys:
|
|
39
|
+
mode: "none";
|
|
40
|
+
selectedKeys: string[];
|
|
51
41
|
};
|
|
52
42
|
|
|
53
43
|
type SingleSelection = {
|
|
54
|
-
|
|
55
|
-
selectedKeys:
|
|
56
|
-
getRowRadioProps: (key:
|
|
57
|
-
toggleSelection: (key:
|
|
44
|
+
mode: "single";
|
|
45
|
+
selectedKeys: string[];
|
|
46
|
+
getRowRadioProps: (key: string, row: any) => RadioInputProps;
|
|
47
|
+
toggleSelection: (key: string, row: any) => void;
|
|
58
48
|
};
|
|
59
49
|
|
|
60
50
|
type MultipleSelection = {
|
|
61
|
-
|
|
62
|
-
selectedKeys:
|
|
51
|
+
mode: "multiple";
|
|
52
|
+
selectedKeys: string[];
|
|
63
53
|
getTheadCheckboxProps: () => CheckboxInputProps;
|
|
64
|
-
getRowCheckboxProps: (key:
|
|
65
|
-
toggleSelection: (key:
|
|
54
|
+
getRowCheckboxProps: (key: string, row: any) => CheckboxInputProps;
|
|
55
|
+
toggleSelection: (key: string, row: any) => void;
|
|
66
56
|
};
|
|
67
57
|
|
|
68
58
|
type TableSelectionBase = {
|
|
69
|
-
isRowSelected: (rowId:
|
|
59
|
+
isRowSelected: (rowId: string) => boolean;
|
|
70
60
|
};
|
|
71
61
|
|
|
72
62
|
type TableSelection = TableSelectionBase &
|
|
@@ -75,7 +65,6 @@ type TableSelection = TableSelectionBase &
|
|
|
75
65
|
export type {
|
|
76
66
|
MultipleSelection,
|
|
77
67
|
NoneSelection,
|
|
78
|
-
SelectedKeysT,
|
|
79
68
|
SelectionProps,
|
|
80
69
|
SingleSelection,
|
|
81
70
|
TableSelection,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, test } from "vitest";
|
|
2
|
-
import type { TableRowEntryId } from "../../root/
|
|
2
|
+
import type { TableRowEntryId } from "../../root/DataGridTable.types";
|
|
3
3
|
import type { ItemDetail } from "../collectTableRowEntries";
|
|
4
4
|
import { mutateRowSelection } from "./selection.utils";
|
|
5
5
|
|
|
@@ -137,7 +137,7 @@ function getStickyOffsets(element: HTMLElement): {
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
const stickyHeader = table.querySelector<HTMLElement>(
|
|
140
|
-
`.aksel-data-
|
|
140
|
+
`.aksel-data-table__thead[data-sticky="true"]`,
|
|
141
141
|
);
|
|
142
142
|
|
|
143
143
|
const stickyNodesStart = table.querySelectorAll<HTMLElement>(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { renderHook } from "@testing-library/react";
|
|
2
2
|
import { describe, expect, test } from "vitest";
|
|
3
|
-
import type { TableRowEntryId } from "../../root/
|
|
3
|
+
import type { TableRowEntryId } from "../../root/DataGridTable.types";
|
|
4
4
|
import { useTableItems } from "../useTableItems";
|
|
5
5
|
|
|
6
6
|
type TestRow = {
|
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
|
+
import { consoleWarning } from "../../../utils/helpers/consoleWarning";
|
|
2
3
|
import type {
|
|
3
4
|
ColumnDefinition,
|
|
4
5
|
ColumnDefinitions,
|
|
5
|
-
} from "../root/
|
|
6
|
+
} from "../root/DataGridTable.types";
|
|
6
7
|
import { ACTION_CELL_WIDTH } from "../tr/DataTableTr";
|
|
7
8
|
|
|
8
9
|
type UseColumnOptions = {
|
|
9
10
|
stickyColumns?: {
|
|
10
|
-
start?:
|
|
11
|
-
end?:
|
|
11
|
+
start?: 1;
|
|
12
|
+
end?: 1;
|
|
12
13
|
};
|
|
13
14
|
hasSelection: boolean;
|
|
14
15
|
hasDetailsPanel: boolean;
|
|
15
16
|
layout: "fixed" | "auto";
|
|
17
|
+
columnDisplay?: {
|
|
18
|
+
id: string;
|
|
19
|
+
visible: boolean;
|
|
20
|
+
}[];
|
|
16
21
|
};
|
|
17
22
|
|
|
18
23
|
type StickyStartState = {
|
|
@@ -37,9 +42,15 @@ function useColumnOptions<T>(
|
|
|
37
42
|
columnDefinitions: ColumnDefinitions<T>,
|
|
38
43
|
options: UseColumnOptions,
|
|
39
44
|
): UseColumnOptionsResult<T> {
|
|
40
|
-
const {
|
|
45
|
+
const {
|
|
46
|
+
stickyColumns,
|
|
47
|
+
hasSelection,
|
|
48
|
+
hasDetailsPanel,
|
|
49
|
+
layout,
|
|
50
|
+
columnDisplay,
|
|
51
|
+
} = options;
|
|
41
52
|
|
|
42
|
-
const hasStickyStart = stickyColumns?.start ===
|
|
53
|
+
const hasStickyStart = stickyColumns?.start === 1;
|
|
43
54
|
|
|
44
55
|
const stickyExpansion = hasStickyStart && hasDetailsPanel;
|
|
45
56
|
const stickySelection = hasStickyStart && hasSelection;
|
|
@@ -49,11 +60,15 @@ function useColumnOptions<T>(
|
|
|
49
60
|
(stickyExpansion ? ACTION_CELL_WIDTH : 0) +
|
|
50
61
|
(stickySelection ? ACTION_CELL_WIDTH : 0);
|
|
51
62
|
|
|
63
|
+
const visibleColumns = useMemo(() => {
|
|
64
|
+
return orderColumnsAndFilterByVisibility(columnDefinitions, columnDisplay);
|
|
65
|
+
}, [columnDefinitions, columnDisplay]);
|
|
66
|
+
|
|
52
67
|
const columns = useMemo(() => {
|
|
53
|
-
return
|
|
68
|
+
return visibleColumns.map((colDef, index) => {
|
|
54
69
|
const isFirstSticky = hasStickyStart && index === 0;
|
|
55
70
|
const isLastSticky =
|
|
56
|
-
stickyColumns?.end ===
|
|
71
|
+
stickyColumns?.end === 1 && index === visibleColumns.length - 1;
|
|
57
72
|
|
|
58
73
|
return {
|
|
59
74
|
isSticky: isFirstSticky
|
|
@@ -66,12 +81,7 @@ function useColumnOptions<T>(
|
|
|
66
81
|
colDef,
|
|
67
82
|
};
|
|
68
83
|
});
|
|
69
|
-
}, [
|
|
70
|
-
columnDefinitions,
|
|
71
|
-
hasStickyStart,
|
|
72
|
-
stickyColumns,
|
|
73
|
-
stickyFirstColumnOffset,
|
|
74
|
-
]);
|
|
84
|
+
}, [visibleColumns, hasStickyStart, stickyColumns, stickyFirstColumnOffset]);
|
|
75
85
|
|
|
76
86
|
const totalColSpan =
|
|
77
87
|
columns.length +
|
|
@@ -91,6 +101,31 @@ function useColumnOptions<T>(
|
|
|
91
101
|
};
|
|
92
102
|
}
|
|
93
103
|
|
|
104
|
+
function orderColumnsAndFilterByVisibility<T>(
|
|
105
|
+
columns: ColumnDefinition<T>[],
|
|
106
|
+
columnDisplay?: { id: string; visible: boolean }[],
|
|
107
|
+
): ColumnDefinition<T>[] {
|
|
108
|
+
if (!columnDisplay) {
|
|
109
|
+
return columns;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const columnMap = new Map(columns.map((col) => [col.id, col]));
|
|
113
|
+
|
|
114
|
+
return columnDisplay.reduce<ColumnDefinition<T>[]>((acc, { id, visible }) => {
|
|
115
|
+
const col = columnMap.get(id);
|
|
116
|
+
|
|
117
|
+
if (!col) {
|
|
118
|
+
consoleWarning(
|
|
119
|
+
`DataGrid: Column with id "${id}" not found in column definitions. Please check your columnDisplay configuration.`,
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (col && visible) {
|
|
124
|
+
acc.push(col);
|
|
125
|
+
}
|
|
126
|
+
return acc;
|
|
127
|
+
}, []);
|
|
128
|
+
}
|
|
129
|
+
|
|
94
130
|
export { useColumnOptions };
|
|
95
|
-
export type { StickyStartState };
|
|
96
|
-
export type { UseColumnOptionsResult };
|
|
131
|
+
export type { StickyStartState, UseColumnOptionsResult };
|