@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
|
@@ -6,32 +6,37 @@ import {
|
|
|
6
6
|
PlusIcon,
|
|
7
7
|
} from "@navikt/aksel-icons";
|
|
8
8
|
import { Button } from "../../../button";
|
|
9
|
+
import { useDataGridContext } from "../../../data-grid/root/DataGridRoot.context";
|
|
9
10
|
import { CheckboxInput } from "../../../form/checkbox/checkbox-input/CheckboxInput";
|
|
10
11
|
import { RadioInput } from "../../../form/radio/radio-input/RadioInput";
|
|
11
12
|
import { Skeleton } from "../../../skeleton";
|
|
12
13
|
import { Label } from "../../../typography";
|
|
13
14
|
import { useId } from "../../../utils-external";
|
|
14
15
|
import { cl, composeEventHandlers } from "../../../utils/helpers";
|
|
16
|
+
import { consoleWarning } from "../../../utils/helpers/consoleWarning";
|
|
15
17
|
import { DataTableBaseCell } from "../base-cell/DataTableBaseCell";
|
|
16
18
|
import { DataTableColumnHeader } from "../column-header/DataTableColumnHeader";
|
|
17
19
|
import {
|
|
18
20
|
getDataTableDetailsPanelId,
|
|
19
21
|
useDataTableDetailsPanel,
|
|
20
22
|
} from "../hooks/useTableDetailsPanel";
|
|
23
|
+
import type { TableRowEntryId } from "../root/DataGridTable.types";
|
|
21
24
|
import {
|
|
22
25
|
useDataTableContext,
|
|
23
26
|
useDataTableLocation,
|
|
24
27
|
} from "../root/DataTableRoot.context";
|
|
25
28
|
import { DataTableTd } from "../td/DataTableTd";
|
|
26
29
|
|
|
27
|
-
const
|
|
30
|
+
const ACTION_CELL_WIDTH = 50;
|
|
31
|
+
|
|
32
|
+
const ACTION_CELL_CSS_WIDTH = `${ACTION_CELL_WIDTH}px`;
|
|
28
33
|
|
|
29
34
|
type DataTableTrProps = React.HTMLAttributes<HTMLTableRowElement> & {
|
|
30
35
|
selected?: boolean;
|
|
31
36
|
/**
|
|
32
|
-
* Unique identifier for the row, used for selection
|
|
37
|
+
* Unique identifier for the row, used for selection.
|
|
33
38
|
*/
|
|
34
|
-
rowId?:
|
|
39
|
+
rowId?: TableRowEntryId;
|
|
35
40
|
};
|
|
36
41
|
|
|
37
42
|
const DataTableTr = forwardRef<HTMLTableRowElement, DataTableTrProps>(
|
|
@@ -46,9 +51,10 @@ const DataTableTr = forwardRef<HTMLTableRowElement, DataTableTrProps>(
|
|
|
46
51
|
},
|
|
47
52
|
forwardedRef,
|
|
48
53
|
) => {
|
|
49
|
-
const { layout, stickyHeader, selectionState,
|
|
54
|
+
const { layout, stickyHeader, selectionState, onRowAction } =
|
|
50
55
|
useDataTableContext();
|
|
51
56
|
const { location } = useDataTableLocation();
|
|
57
|
+
const { tableItems } = useDataTableContext();
|
|
52
58
|
|
|
53
59
|
const renderFillerCell = layout === "fixed" && children;
|
|
54
60
|
|
|
@@ -58,7 +64,11 @@ const DataTableTr = forwardRef<HTMLTableRowElement, DataTableTrProps>(
|
|
|
58
64
|
const isSticky = location === "thead" && stickyHeader;
|
|
59
65
|
|
|
60
66
|
const handleClick =
|
|
61
|
-
location === "tbody" &&
|
|
67
|
+
location === "tbody" &&
|
|
68
|
+
rowId !== undefined &&
|
|
69
|
+
((selectionState.selectionTrigger === "row" &&
|
|
70
|
+
selectionState.selection.mode !== "none") ||
|
|
71
|
+
onRowAction)
|
|
62
72
|
? (event: React.MouseEvent<HTMLTableRowElement>) => {
|
|
63
73
|
if (
|
|
64
74
|
rowId === undefined ||
|
|
@@ -70,18 +80,44 @@ const DataTableTr = forwardRef<HTMLTableRowElement, DataTableTrProps>(
|
|
|
70
80
|
return;
|
|
71
81
|
}
|
|
72
82
|
|
|
83
|
+
if (onRowAction) {
|
|
84
|
+
const rowData = tableItems.itemDetails.get(rowId)?.rowData;
|
|
85
|
+
|
|
86
|
+
if (rowData) {
|
|
87
|
+
onRowAction({
|
|
88
|
+
row: rowData,
|
|
89
|
+
id: rowId,
|
|
90
|
+
event,
|
|
91
|
+
});
|
|
92
|
+
} else {
|
|
93
|
+
consoleWarning(
|
|
94
|
+
`DataGrid.Table: Unable to find row data for rowId ${rowId} when calling onRowAction.`,
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (event.defaultPrevented) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
73
103
|
const selection = window.getSelection();
|
|
74
104
|
if (selection && selection.toString().length > 0) {
|
|
75
105
|
return;
|
|
76
106
|
}
|
|
77
107
|
|
|
78
108
|
if (
|
|
79
|
-
|
|
80
|
-
selectionState.selection.
|
|
109
|
+
selectionState.selectionTrigger === "row" &&
|
|
110
|
+
selectionState.selection.mode !== "none"
|
|
81
111
|
) {
|
|
82
|
-
|
|
112
|
+
const rowData = tableItems.itemDetails.get(rowId)?.rowData;
|
|
113
|
+
|
|
114
|
+
if (!rowData) {
|
|
115
|
+
consoleWarning(
|
|
116
|
+
`DataGrid.Table: No row data found for rowId ${rowId}. This may cause issues with selection if enableRowSelection is used.`,
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
selectionState.selection.toggleSelection(rowId, rowData);
|
|
83
120
|
}
|
|
84
|
-
onRowClick?.(rowId, event);
|
|
85
121
|
}
|
|
86
122
|
: undefined;
|
|
87
123
|
|
|
@@ -113,8 +149,13 @@ const DataTableTr = forwardRef<HTMLTableRowElement, DataTableTrProps>(
|
|
|
113
149
|
},
|
|
114
150
|
);
|
|
115
151
|
|
|
116
|
-
function RowExpansionCell({ rowId }: { rowId?:
|
|
117
|
-
const {
|
|
152
|
+
function RowExpansionCell({ rowId }: { rowId?: TableRowEntryId }) {
|
|
153
|
+
const { isLoading } = useDataGridContext();
|
|
154
|
+
const { tableId, loading, stickyStart } = useDataTableContext();
|
|
155
|
+
const stickyExpansion = stickyStart.expansion;
|
|
156
|
+
|
|
157
|
+
const expansionHeaderId = useId();
|
|
158
|
+
|
|
118
159
|
const { location } = useDataTableLocation();
|
|
119
160
|
|
|
120
161
|
const {
|
|
@@ -131,20 +172,26 @@ function RowExpansionCell({ rowId }: { rowId?: string | number }) {
|
|
|
131
172
|
return null;
|
|
132
173
|
}
|
|
133
174
|
|
|
134
|
-
if (
|
|
175
|
+
if (isLoading && loading?.variant === "skeleton") {
|
|
135
176
|
if (location === "thead") {
|
|
136
177
|
return (
|
|
137
178
|
<DataTableColumnHeader
|
|
138
|
-
|
|
139
|
-
|
|
179
|
+
id={expansionHeaderId}
|
|
180
|
+
width={{ value: ACTION_CELL_CSS_WIDTH }}
|
|
181
|
+
cellType="action"
|
|
140
182
|
data-block-keyboard-nav
|
|
141
183
|
label=""
|
|
142
|
-
|
|
184
|
+
isSticky={stickyExpansion && "start"}
|
|
185
|
+
style={stickyExpansion ? { left: 0 } : undefined}
|
|
143
186
|
/>
|
|
144
187
|
);
|
|
145
188
|
}
|
|
146
189
|
return (
|
|
147
|
-
<DataTableBaseCell
|
|
190
|
+
<DataTableBaseCell
|
|
191
|
+
as="td"
|
|
192
|
+
isSticky={stickyExpansion && "start"}
|
|
193
|
+
style={stickyExpansion ? { left: 0 } : undefined}
|
|
194
|
+
>
|
|
148
195
|
<Skeleton variant="text" />
|
|
149
196
|
</DataTableBaseCell>
|
|
150
197
|
);
|
|
@@ -153,11 +200,13 @@ function RowExpansionCell({ rowId }: { rowId?: string | number }) {
|
|
|
153
200
|
if (location === "thead" && !showExpandAll) {
|
|
154
201
|
return (
|
|
155
202
|
<DataTableColumnHeader
|
|
156
|
-
|
|
157
|
-
|
|
203
|
+
id={expansionHeaderId}
|
|
204
|
+
width={{ value: ACTION_CELL_CSS_WIDTH }}
|
|
205
|
+
cellType="action"
|
|
158
206
|
data-block-keyboard-nav
|
|
159
207
|
label=""
|
|
160
|
-
|
|
208
|
+
isSticky={stickyExpansion && "start"}
|
|
209
|
+
style={stickyExpansion ? { left: 0 } : undefined}
|
|
161
210
|
/>
|
|
162
211
|
);
|
|
163
212
|
}
|
|
@@ -165,11 +214,13 @@ function RowExpansionCell({ rowId }: { rowId?: string | number }) {
|
|
|
165
214
|
if (location === "thead") {
|
|
166
215
|
return (
|
|
167
216
|
<DataTableColumnHeader
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
217
|
+
id={expansionHeaderId}
|
|
218
|
+
align="center"
|
|
219
|
+
width={{ value: ACTION_CELL_CSS_WIDTH }}
|
|
220
|
+
cellType="action"
|
|
171
221
|
label=""
|
|
172
|
-
|
|
222
|
+
isSticky={stickyExpansion && "start"}
|
|
223
|
+
style={stickyExpansion ? { left: 0 } : undefined}
|
|
173
224
|
>
|
|
174
225
|
<Button
|
|
175
226
|
variant="tertiary"
|
|
@@ -199,11 +250,23 @@ function RowExpansionCell({ rowId }: { rowId?: string | number }) {
|
|
|
199
250
|
const expansionId = getDataTableDetailsPanelId(tableId, rowId);
|
|
200
251
|
|
|
201
252
|
if (!canExpandRow) {
|
|
202
|
-
return
|
|
253
|
+
return (
|
|
254
|
+
<DataTableTd
|
|
255
|
+
cellType="action"
|
|
256
|
+
preventRowClick
|
|
257
|
+
isSticky={stickyExpansion && "start"}
|
|
258
|
+
style={stickyExpansion ? { left: 0 } : undefined}
|
|
259
|
+
/>
|
|
260
|
+
);
|
|
203
261
|
}
|
|
204
262
|
|
|
205
263
|
return (
|
|
206
|
-
<DataTableTd
|
|
264
|
+
<DataTableTd
|
|
265
|
+
cellType="action"
|
|
266
|
+
preventRowClick
|
|
267
|
+
isSticky={stickyExpansion && "start"}
|
|
268
|
+
style={stickyExpansion ? { left: 0 } : undefined}
|
|
269
|
+
>
|
|
207
270
|
<Button
|
|
208
271
|
variant="tertiary"
|
|
209
272
|
data-color="neutral"
|
|
@@ -227,40 +290,52 @@ function RowExpansionCell({ rowId }: { rowId?: string | number }) {
|
|
|
227
290
|
* TODO: How do these cells handle multiple thead rows, or col/row-spans?
|
|
228
291
|
* TODO: a11y for labels
|
|
229
292
|
*/
|
|
230
|
-
function RowSelectionCell({ rowId }: { rowId?:
|
|
231
|
-
const {
|
|
232
|
-
|
|
293
|
+
function RowSelectionCell({ rowId }: { rowId?: TableRowEntryId }) {
|
|
294
|
+
const { isLoading } = useDataGridContext();
|
|
295
|
+
const { selectionState, stickyStart, loading } = useDataTableContext();
|
|
296
|
+
const stickySelection = stickyStart.selection;
|
|
297
|
+
const stickySelectionOffset = stickyStart.selectionOffset;
|
|
233
298
|
const { location } = useDataTableLocation();
|
|
299
|
+
|
|
300
|
+
const { tableItems } = useDataTableContext();
|
|
301
|
+
|
|
234
302
|
const inputId = useId();
|
|
303
|
+
const selectionHeaderId = useId();
|
|
235
304
|
|
|
236
305
|
const { selection, renderSelection } = selectionState;
|
|
237
306
|
|
|
238
|
-
if (selection.
|
|
307
|
+
if (selection.mode === "none" || !renderSelection) {
|
|
239
308
|
return null;
|
|
240
309
|
}
|
|
241
310
|
|
|
242
|
-
if (
|
|
311
|
+
if (isLoading && loading?.variant === "skeleton") {
|
|
243
312
|
if (location === "thead") {
|
|
244
313
|
return (
|
|
245
314
|
<DataTableColumnHeader
|
|
246
|
-
|
|
247
|
-
|
|
315
|
+
id={selectionHeaderId}
|
|
316
|
+
width={{ value: ACTION_CELL_CSS_WIDTH }}
|
|
317
|
+
cellType="action"
|
|
248
318
|
label=""
|
|
249
319
|
data-block-keyboard-nav
|
|
250
320
|
isSticky={stickySelection && "start"}
|
|
321
|
+
style={stickySelection ? { left: stickySelectionOffset } : undefined}
|
|
251
322
|
/>
|
|
252
323
|
);
|
|
253
324
|
}
|
|
254
325
|
|
|
255
326
|
return (
|
|
256
|
-
<DataTableBaseCell
|
|
327
|
+
<DataTableBaseCell
|
|
328
|
+
as="td"
|
|
329
|
+
isSticky={stickySelection && "start"}
|
|
330
|
+
style={stickySelection ? { left: stickySelectionOffset } : undefined}
|
|
331
|
+
>
|
|
257
332
|
<Skeleton variant="text" />
|
|
258
333
|
</DataTableBaseCell>
|
|
259
334
|
);
|
|
260
335
|
}
|
|
261
336
|
|
|
262
337
|
/* TODO: A11y support */
|
|
263
|
-
if (selection.
|
|
338
|
+
if (selection.mode === "multiple" && location === "thead") {
|
|
264
339
|
const theadCheckboxProps = selection.getTheadCheckboxProps();
|
|
265
340
|
|
|
266
341
|
let labelText = "Velg alle synlige rader";
|
|
@@ -270,11 +345,13 @@ function RowSelectionCell({ rowId }: { rowId?: string | number }) {
|
|
|
270
345
|
|
|
271
346
|
return (
|
|
272
347
|
<DataTableColumnHeader
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
348
|
+
id={selectionHeaderId}
|
|
349
|
+
align="center"
|
|
350
|
+
width={{ value: ACTION_CELL_CSS_WIDTH }}
|
|
351
|
+
cellType="action"
|
|
276
352
|
label=""
|
|
277
353
|
isSticky={stickySelection && "start"}
|
|
354
|
+
style={stickySelection ? { left: stickySelectionOffset } : undefined}
|
|
278
355
|
>
|
|
279
356
|
<Label htmlFor={inputId} visuallyHidden>
|
|
280
357
|
{labelText}
|
|
@@ -284,14 +361,16 @@ function RowSelectionCell({ rowId }: { rowId?: string | number }) {
|
|
|
284
361
|
);
|
|
285
362
|
}
|
|
286
363
|
|
|
287
|
-
if (selection.
|
|
364
|
+
if (selection.mode === "single" && location === "thead") {
|
|
288
365
|
return (
|
|
289
366
|
<DataTableColumnHeader
|
|
290
|
-
|
|
291
|
-
|
|
367
|
+
id={selectionHeaderId}
|
|
368
|
+
width={{ value: ACTION_CELL_CSS_WIDTH }}
|
|
369
|
+
cellType="action"
|
|
292
370
|
label=""
|
|
293
371
|
data-block-keyboard-nav
|
|
294
372
|
isSticky={stickySelection && "start"}
|
|
373
|
+
style={stickySelection ? { left: stickySelectionOffset } : undefined}
|
|
295
374
|
/>
|
|
296
375
|
);
|
|
297
376
|
}
|
|
@@ -300,18 +379,37 @@ function RowSelectionCell({ rowId }: { rowId?: string | number }) {
|
|
|
300
379
|
return null;
|
|
301
380
|
}
|
|
302
381
|
|
|
303
|
-
if (selection.
|
|
382
|
+
if (selection.mode === "multiple" && location === "tbody") {
|
|
304
383
|
return (
|
|
305
|
-
<DataTableTd
|
|
306
|
-
|
|
384
|
+
<DataTableTd
|
|
385
|
+
cellType="action"
|
|
386
|
+
isSticky={stickySelection && "start"}
|
|
387
|
+
style={stickySelection ? { left: stickySelectionOffset } : undefined}
|
|
388
|
+
>
|
|
389
|
+
<CheckboxInput
|
|
390
|
+
{...selection.getRowCheckboxProps(
|
|
391
|
+
rowId,
|
|
392
|
+
tableItems.itemDetails.get(rowId)?.rowData,
|
|
393
|
+
)}
|
|
394
|
+
compact
|
|
395
|
+
/>
|
|
307
396
|
</DataTableTd>
|
|
308
397
|
);
|
|
309
398
|
}
|
|
310
399
|
|
|
311
|
-
if (selection.
|
|
400
|
+
if (selection.mode === "single" && location === "tbody") {
|
|
312
401
|
return (
|
|
313
|
-
<DataTableTd
|
|
314
|
-
|
|
402
|
+
<DataTableTd
|
|
403
|
+
cellType="action"
|
|
404
|
+
isSticky={stickySelection && "start"}
|
|
405
|
+
style={stickySelection ? { left: stickySelectionOffset } : undefined}
|
|
406
|
+
>
|
|
407
|
+
<RadioInput
|
|
408
|
+
{...selection.getRowRadioProps(
|
|
409
|
+
rowId,
|
|
410
|
+
tableItems.itemDetails.get(rowId)?.rowData,
|
|
411
|
+
)}
|
|
412
|
+
/>
|
|
315
413
|
</DataTableTd>
|
|
316
414
|
);
|
|
317
415
|
}
|
|
@@ -326,5 +424,5 @@ function isInteractiveTarget(target: EventTarget | null): boolean {
|
|
|
326
424
|
);
|
|
327
425
|
}
|
|
328
426
|
|
|
329
|
-
export { DataTableTr };
|
|
427
|
+
export { DataTableTr, ACTION_CELL_WIDTH };
|
|
330
428
|
export type { DataTableTrProps };
|
|
@@ -23,7 +23,7 @@ type TokenFilterProps = {
|
|
|
23
23
|
options: ExternalOptions;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
/*
|
|
27
27
|
* TODO:
|
|
28
28
|
* - Implement onChange handler to update query state when user selects an autocomplete option.
|
|
29
29
|
* - Handle token rendering and editing (e.g., show tokens for matched properties/operators/values, allow deleting tokens).
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
type DataGridSettings = {
|
|
2
|
+
/**
|
|
3
|
+
* Controls vertical cell padding.
|
|
4
|
+
* @default "standard"
|
|
5
|
+
*/
|
|
6
|
+
rowDensity?: "tight" | "standard" | "loose";
|
|
7
|
+
/**
|
|
8
|
+
* Zebra striped table
|
|
9
|
+
* @default false
|
|
10
|
+
*/
|
|
11
|
+
zebraStripes?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Truncate content in cells and show ellipsis for overflowed text.
|
|
14
|
+
*
|
|
15
|
+
* **NB:** When using this together with `layout="auto"`,
|
|
16
|
+
* you have to manually set a `maxWidth` on columns that should be truncated.
|
|
17
|
+
* @default false if layout="auto", else true
|
|
18
|
+
*/
|
|
19
|
+
truncateContent?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Sticky columns that remain visible when horizontally scrolling the table.
|
|
22
|
+
*
|
|
23
|
+
* You can specify 1 sticky column on the left and 1 on the right.
|
|
24
|
+
*/
|
|
25
|
+
stickyColumns?: {
|
|
26
|
+
start?: 1;
|
|
27
|
+
end?: 1;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Adjusts font-size
|
|
31
|
+
* @default "medium"
|
|
32
|
+
*/
|
|
33
|
+
textSize?: "small" | "medium";
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type { DataGridSettings };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { SelectionProps } from "../../data/table/hooks/useTableSelection";
|
|
2
|
+
import type { ColumnDefinitions } from "../../data/table/root/DataGridTable.types";
|
|
3
|
+
import { createStrictContext } from "../../utils/helpers";
|
|
4
|
+
import type { DataGridSettings } from "./DataGrid.types";
|
|
5
|
+
|
|
6
|
+
type DataGridContextValue<RowT = unknown> = {
|
|
7
|
+
data: RowT[];
|
|
8
|
+
columnDefinitions: ColumnDefinitions<RowT>;
|
|
9
|
+
getRowId?: (rowData: RowT) => string;
|
|
10
|
+
selection?: SelectionProps<RowT>;
|
|
11
|
+
isLoading?: boolean;
|
|
12
|
+
tableSettings?: DataGridSettings;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const { Provider: DataGridContextProvider, useContext: useDataGridContext } =
|
|
16
|
+
createStrictContext<DataGridContextValue>({
|
|
17
|
+
name: "DataGridContext",
|
|
18
|
+
errorMessage: "DataGrid hooks must be used within a <DataGrid />",
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export { DataGridContextProvider, useDataGridContext };
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import React, { forwardRef, useMemo } from "react";
|
|
2
|
+
import type { SelectionProps } from "../../data/table/hooks/useTableSelection";
|
|
3
|
+
import type { ColumnDefinitions } from "../../data/table/root/DataGridTable.types";
|
|
4
|
+
import { DataGridTable } from "../../data/table/root/DataGridTableRoot";
|
|
5
|
+
import { cl } from "../../utils/helpers";
|
|
6
|
+
import type { DataGridSettings } from "./DataGrid.types";
|
|
7
|
+
import { DataGridContextProvider } from "./DataGridRoot.context";
|
|
8
|
+
|
|
9
|
+
interface DataGridProps<RowT> {
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
className?: string;
|
|
12
|
+
style?: React.CSSProperties;
|
|
13
|
+
/**
|
|
14
|
+
* Definitions of the columns to display.
|
|
15
|
+
*/
|
|
16
|
+
columns: ColumnDefinitions<RowT>;
|
|
17
|
+
/**
|
|
18
|
+
* The data to display.
|
|
19
|
+
*
|
|
20
|
+
* Each object in the array represents a row, and the properties of the
|
|
21
|
+
* object are used to render the cells based on `columnDefinitions`.
|
|
22
|
+
*/
|
|
23
|
+
data: RowT[];
|
|
24
|
+
/**
|
|
25
|
+
* Function to get unique row ID from row data.
|
|
26
|
+
*
|
|
27
|
+
* If not provided, the row index will be used as ID.
|
|
28
|
+
* This can cause issues if your data changes dynamically,
|
|
29
|
+
* so it's recommended to provide a stable ID if possible.
|
|
30
|
+
*/
|
|
31
|
+
getRowId?: (rowData: RowT) => string;
|
|
32
|
+
/**
|
|
33
|
+
* Object with props related to row selection.
|
|
34
|
+
*/
|
|
35
|
+
selection?: SelectionProps<RowT>;
|
|
36
|
+
/**
|
|
37
|
+
* Determines if the data grid is in a loading state.
|
|
38
|
+
* See `loadingContent` prop on the `DataGrid.Table` component for display settings.
|
|
39
|
+
* @default false
|
|
40
|
+
*/
|
|
41
|
+
isLoading?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Settings for the data grid.
|
|
44
|
+
*/
|
|
45
|
+
settings?: DataGridSettings;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface DataGridComponent {
|
|
49
|
+
<RowT>(
|
|
50
|
+
props: DataGridProps<RowT> & React.RefAttributes<HTMLDivElement>,
|
|
51
|
+
): React.ReactElement | null;
|
|
52
|
+
/**
|
|
53
|
+
* @see 🏷️ {@link DataGridTableProps}
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* <DataGrid columnDefinitions={columnDefs} data={rowData} getRowId={(row) => row.id}>
|
|
57
|
+
* <DataGrid.Table />
|
|
58
|
+
* </DataGrid>
|
|
59
|
+
*/
|
|
60
|
+
Table: typeof DataGridTable;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Component for displaying tabular data.
|
|
65
|
+
*
|
|
66
|
+
* **WARNING: This component is in active development and may receive breaking changes outside major releases!**
|
|
67
|
+
*
|
|
68
|
+
* @see [📝 Documentation](https://aksel.nav.no/komponenter/core/datagrid)
|
|
69
|
+
* @see 🏷️ {@link DataGridProps}
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```jsx
|
|
73
|
+
* <DataGrid columnDefinitions={columnDefs} data={rowData} getRowId={(row) => row.id}>
|
|
74
|
+
* <DataGrid.Table />
|
|
75
|
+
* </DataGrid>
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
const DataGridInternal = forwardRef<HTMLDivElement, DataGridProps<any>>(
|
|
79
|
+
(
|
|
80
|
+
{
|
|
81
|
+
children,
|
|
82
|
+
className,
|
|
83
|
+
columns,
|
|
84
|
+
data,
|
|
85
|
+
getRowId,
|
|
86
|
+
selection,
|
|
87
|
+
isLoading = false,
|
|
88
|
+
settings,
|
|
89
|
+
...rest
|
|
90
|
+
}: DataGridProps<unknown>,
|
|
91
|
+
ref,
|
|
92
|
+
) => {
|
|
93
|
+
const resolvedSettings = useMemo(
|
|
94
|
+
() => ({
|
|
95
|
+
rowDensity: settings?.rowDensity ?? "standard",
|
|
96
|
+
zebraStripes: settings?.zebraStripes ?? false,
|
|
97
|
+
truncateContent: settings?.truncateContent,
|
|
98
|
+
stickyColumns: settings?.stickyColumns ?? {},
|
|
99
|
+
textSize: settings?.textSize ?? "medium",
|
|
100
|
+
}),
|
|
101
|
+
[
|
|
102
|
+
settings?.rowDensity,
|
|
103
|
+
settings?.zebraStripes,
|
|
104
|
+
settings?.truncateContent,
|
|
105
|
+
settings?.stickyColumns,
|
|
106
|
+
settings?.textSize,
|
|
107
|
+
],
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<div {...rest} ref={ref} className={cl("aksel-data-grid", className)}>
|
|
112
|
+
<DataGridContextProvider
|
|
113
|
+
columnDefinitions={columns}
|
|
114
|
+
data={data}
|
|
115
|
+
getRowId={getRowId}
|
|
116
|
+
selection={selection}
|
|
117
|
+
isLoading={isLoading}
|
|
118
|
+
tableSettings={resolvedSettings}
|
|
119
|
+
>
|
|
120
|
+
{children}
|
|
121
|
+
</DataGridContextProvider>
|
|
122
|
+
</div>
|
|
123
|
+
);
|
|
124
|
+
},
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const DataGrid = DataGridInternal as unknown as DataGridComponent;
|
|
128
|
+
DataGrid.Table = DataGridTable;
|
|
129
|
+
|
|
130
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace, import/export
|
|
131
|
+
export namespace DataGrid {
|
|
132
|
+
export type Props<T = unknown> = DataGridProps<T>;
|
|
133
|
+
export type Columns<T = unknown> = ColumnDefinitions<T>;
|
|
134
|
+
export type Selection<T = unknown> = SelectionProps<T>;
|
|
135
|
+
export type Settings = DataGridSettings;
|
|
136
|
+
|
|
137
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
138
|
+
export namespace Table {
|
|
139
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
140
|
+
export type Props<T = unknown> = DataGridTable.Props<T>;
|
|
141
|
+
export type Sorting = DataGridTable.Sorting;
|
|
142
|
+
export type SortEntry = DataGridTable.SortEntry;
|
|
143
|
+
export type SortChangeDetail = DataGridTable.SortChangeDetail;
|
|
144
|
+
export type LoadingContent = DataGridTable.LoadingContent;
|
|
145
|
+
export type SubRows<T = unknown> = DataGridTable.SubRows<T>;
|
|
146
|
+
export type DetailsPanel<T = unknown> = DataGridTable.DetailsPanel<T>;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// eslint-disable-next-line import/export
|
|
151
|
+
export { DataGrid, DataGridInternal }; // DataGridRoot needs to be exported b.c. of docgen
|
|
152
|
+
export default DataGrid;
|
package/src/preview.ts
ADDED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
SortDownIcon,
|
|
5
5
|
SortUpIcon,
|
|
6
6
|
} from "@navikt/aksel-icons";
|
|
7
|
+
import { consoleWarning } from "../utils/helpers/consoleWarning";
|
|
7
8
|
import HeaderCell, { HeaderCellProps } from "./HeaderCell";
|
|
8
9
|
import { TableContext } from "./context";
|
|
9
10
|
|
|
@@ -28,7 +29,7 @@ export const ColumnHeader: ColumnHeaderType = forwardRef(
|
|
|
28
29
|
const context = useContext(TableContext);
|
|
29
30
|
|
|
30
31
|
if (sortable && !sortKey) {
|
|
31
|
-
|
|
32
|
+
consoleWarning("ColumnHeader with `sortable=true` must have a sortKey.");
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
return (
|
|
@@ -44,6 +45,7 @@ export const ColumnHeader: ColumnHeaderType = forwardRef(
|
|
|
44
45
|
}
|
|
45
46
|
{...rest}
|
|
46
47
|
>
|
|
48
|
+
{/* TODO: Padding on cell makes clickable area smaller than cell with button. Make cell clickable, have pointer etc */}
|
|
47
49
|
{sortable ? (
|
|
48
50
|
<button
|
|
49
51
|
type="button"
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
export interface DragAndDropDragHandlerLegacyProps {
|
|
3
|
-
/**
|
|
4
|
-
* Whether the drag handler is disabled
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Wether dragging is done by keyboard. Used to conditionally render drag indicators.
|
|
8
|
-
*/
|
|
9
|
-
keyboardDragging?: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Handle ref is forwarded to the button element serving as drag handle.
|
|
12
|
-
*/
|
|
13
|
-
handleRef: React.Ref<HTMLDivElement>;
|
|
14
|
-
alt?: boolean;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* DragAndDropDragHandlerLegacy
|
|
18
|
-
*
|
|
19
|
-
* A button component that serves as a drag handle for drag and drop operations.
|
|
20
|
-
* Can be used to initiate dragging of elements in a data table or list.
|
|
21
|
-
*/
|
|
22
|
-
export declare const DragAndDropDragHandlerLegacy: React.ForwardRefExoticComponent<DragAndDropDragHandlerLegacyProps & React.RefAttributes<HTMLButtonElement>>;
|