@equinor/apollo-components 3.1.2 → 3.1.3-beta.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/dist/index.js +37 -13
- package/dist/index.mjs +35 -11
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -662,7 +662,7 @@ function TableHeader({ table, sticky }) {
|
|
|
662
662
|
|
|
663
663
|
// src/DataTable/DataTable.tsx
|
|
664
664
|
var import_react_table3 = require("@tanstack/react-table");
|
|
665
|
-
var
|
|
665
|
+
var import_react7 = require("react");
|
|
666
666
|
var import_styled_components16 = __toESM(require("styled-components"));
|
|
667
667
|
|
|
668
668
|
// src/DataTable/components/BasicTable.tsx
|
|
@@ -704,11 +704,19 @@ var TableBody = (0, import_styled_components12.default)(import_eds_core_react12.
|
|
|
704
704
|
var import_eds_core_react13 = require("@equinor/eds-core-react");
|
|
705
705
|
var import_styled_components13 = __toESM(require("styled-components"));
|
|
706
706
|
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
707
|
-
function TableRow({
|
|
707
|
+
function TableRow({
|
|
708
|
+
row,
|
|
709
|
+
rowConfig,
|
|
710
|
+
cellConfig,
|
|
711
|
+
measureElement,
|
|
712
|
+
index
|
|
713
|
+
}) {
|
|
708
714
|
var _a;
|
|
709
715
|
const rowWrapper = rowConfig == null ? void 0 : rowConfig.rowWrapper;
|
|
710
716
|
const tableRowContent = /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(StyledTableRow, {
|
|
711
717
|
active: row.getIsSelected(),
|
|
718
|
+
"data-index": index,
|
|
719
|
+
ref: measureElement,
|
|
712
720
|
style: {
|
|
713
721
|
cursor: (rowConfig == null ? void 0 : rowConfig.onClick) ? "pointer" : "initial",
|
|
714
722
|
backgroundColor: (_a = rowConfig == null ? void 0 : rowConfig.getRowBackground) == null ? void 0 : _a.call(rowConfig, row)
|
|
@@ -945,6 +953,7 @@ function VirtualTable({
|
|
|
945
953
|
count: rows.length,
|
|
946
954
|
estimateSize: () => 48,
|
|
947
955
|
getScrollElement: () => containerRef.current,
|
|
956
|
+
measureElement: (element) => element == null ? void 0 : element.getBoundingClientRect().height,
|
|
948
957
|
overscan: 5
|
|
949
958
|
});
|
|
950
959
|
const virtualRows = rowVirtualizer.getVirtualItems();
|
|
@@ -970,7 +979,9 @@ function VirtualTable({
|
|
|
970
979
|
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(TableRow, {
|
|
971
980
|
row,
|
|
972
981
|
rowConfig,
|
|
973
|
-
cellConfig
|
|
982
|
+
cellConfig,
|
|
983
|
+
index: virtualRow.index,
|
|
984
|
+
measureElement: rowVirtualizer.measureElement
|
|
974
985
|
}, row.id);
|
|
975
986
|
}) : /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(PlaceholderRow, {
|
|
976
987
|
isLoading: props.isLoading
|
|
@@ -1013,6 +1024,13 @@ function useFetchMoreOnBottomReached(tableContainerRef, infiniteScrollConfig) {
|
|
|
1013
1024
|
return onTableContainerScroll;
|
|
1014
1025
|
}
|
|
1015
1026
|
|
|
1027
|
+
// src/DataTable/hooks/useForceRerender.ts
|
|
1028
|
+
var import_react6 = require("react");
|
|
1029
|
+
function useForceRerender() {
|
|
1030
|
+
const [, setTick] = (0, import_react6.useState)(0);
|
|
1031
|
+
return (0, import_react6.useCallback)(() => setTick((tick) => tick + 1), []);
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1016
1034
|
// src/DataTable/DataTable.tsx
|
|
1017
1035
|
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
1018
1036
|
var DataTableWrapper = import_styled_components16.default.div`
|
|
@@ -1020,14 +1038,14 @@ var DataTableWrapper = import_styled_components16.default.div`
|
|
|
1020
1038
|
|
|
1021
1039
|
.--table-container {
|
|
1022
1040
|
height: ${(props) => props.height ?? "100%"};
|
|
1023
|
-
width:
|
|
1041
|
+
width: '100%';
|
|
1024
1042
|
overflow: auto;
|
|
1025
1043
|
|
|
1026
1044
|
table {
|
|
1027
1045
|
width: 100%;
|
|
1028
1046
|
|
|
1029
1047
|
// The following attribute is important for fixed column width
|
|
1030
|
-
// CHANGE
|
|
1048
|
+
// CHANGE THIS WITH CAUTION
|
|
1031
1049
|
table-layout: ${(props) => props.tableLayout ?? "auto"};
|
|
1032
1050
|
}
|
|
1033
1051
|
}
|
|
@@ -1035,12 +1053,12 @@ var DataTableWrapper = import_styled_components16.default.div`
|
|
|
1035
1053
|
function DataTable(props) {
|
|
1036
1054
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
1037
1055
|
const { columns, data, bannerConfig, cellConfig, sorting } = props;
|
|
1038
|
-
const [internalColumnVisibility, setInternalColumnVisibility] = (0,
|
|
1056
|
+
const [internalColumnVisibility, setInternalColumnVisibility] = (0, import_react7.useState)({});
|
|
1039
1057
|
const [columnVisibility, setColumnVisibility] = [
|
|
1040
1058
|
((_a = props.columnVisibility) == null ? void 0 : _a.state) ?? internalColumnVisibility,
|
|
1041
1059
|
((_b = props.columnVisibility) == null ? void 0 : _b.onChange) ?? setInternalColumnVisibility
|
|
1042
1060
|
];
|
|
1043
|
-
const [internalGlobalFilterState, setInternalGlobalFilterState] = (0,
|
|
1061
|
+
const [internalGlobalFilterState, setInternalGlobalFilterState] = (0, import_react7.useState)("");
|
|
1044
1062
|
const [globalFilterState, setGlobalFilterState] = [
|
|
1045
1063
|
((_c = props.globalFilter) == null ? void 0 : _c.state) ?? internalGlobalFilterState,
|
|
1046
1064
|
((_d = props.globalFilter) == null ? void 0 : _d.onChange) ?? setInternalGlobalFilterState
|
|
@@ -1049,17 +1067,17 @@ function DataTable(props) {
|
|
|
1049
1067
|
function enableGlobalFilter(value) {
|
|
1050
1068
|
return enableOrUndefined(shouldEnableGlobalFilter, value);
|
|
1051
1069
|
}
|
|
1052
|
-
const [internalSortingState, setInternalSortingState] = (0,
|
|
1070
|
+
const [internalSortingState, setInternalSortingState] = (0, import_react7.useState)([]);
|
|
1053
1071
|
const [sortingState, setSortingState] = [
|
|
1054
1072
|
((_f = props.sorting) == null ? void 0 : _f.state) ?? internalSortingState,
|
|
1055
1073
|
((_g = props.sorting) == null ? void 0 : _g.onChange) ?? setInternalSortingState
|
|
1056
1074
|
];
|
|
1057
|
-
const [internalRowSelectionState, setInternalRowSelectionState] = (0,
|
|
1075
|
+
const [internalRowSelectionState, setInternalRowSelectionState] = (0, import_react7.useState)({});
|
|
1058
1076
|
const [rowSelectionState, setRowSelectionState] = [
|
|
1059
1077
|
((_h = props.rowSelection) == null ? void 0 : _h.state) ?? internalRowSelectionState,
|
|
1060
1078
|
((_i = props.rowSelection) == null ? void 0 : _i.onChange) ?? setInternalRowSelectionState
|
|
1061
1079
|
];
|
|
1062
|
-
const [internalExpandedState, setInternalExpandedState] = (0,
|
|
1080
|
+
const [internalExpandedState, setInternalExpandedState] = (0, import_react7.useState)({});
|
|
1063
1081
|
const [expandedState, setExpandedState] = [
|
|
1064
1082
|
((_j = props.expansion) == null ? void 0 : _j.state) ?? internalExpandedState,
|
|
1065
1083
|
((_k = props.expansion) == null ? void 0 : _k.onChange) ?? setInternalExpandedState
|
|
@@ -1102,18 +1120,23 @@ function DataTable(props) {
|
|
|
1102
1120
|
getSubRows: props == null ? void 0 : props.getSubRows,
|
|
1103
1121
|
getRowId: props == null ? void 0 : props.getRowId
|
|
1104
1122
|
});
|
|
1105
|
-
(0,
|
|
1123
|
+
(0, import_react7.useEffect)(() => {
|
|
1106
1124
|
var _a2;
|
|
1107
1125
|
if ((_a2 = props.expansion) == null ? void 0 : _a2.expandAllByDefault) {
|
|
1108
1126
|
table.toggleAllRowsExpanded();
|
|
1109
1127
|
}
|
|
1110
1128
|
}, [table, (_p = props.expansion) == null ? void 0 : _p.expandAllByDefault]);
|
|
1111
1129
|
const { isLoading, rowConfig } = props;
|
|
1112
|
-
const tableContainerRef = (0,
|
|
1130
|
+
const tableContainerRef = (0, import_react7.useRef)(null);
|
|
1113
1131
|
const onTableContainerScroll = useFetchMoreOnBottomReached(
|
|
1114
1132
|
tableContainerRef,
|
|
1115
1133
|
props.infiniteScroll
|
|
1116
1134
|
);
|
|
1135
|
+
const forceRerender = useForceRerender();
|
|
1136
|
+
(0, import_react7.useEffect)(() => {
|
|
1137
|
+
if (Boolean(tableContainerRef.current))
|
|
1138
|
+
forceRerender();
|
|
1139
|
+
}, [tableContainerRef.current === null]);
|
|
1117
1140
|
return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(DataTableWrapper, {
|
|
1118
1141
|
height: props == null ? void 0 : props.height,
|
|
1119
1142
|
width: props == null ? void 0 : props.width,
|
|
@@ -1127,7 +1150,8 @@ function DataTable(props) {
|
|
|
1127
1150
|
}),
|
|
1128
1151
|
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", {
|
|
1129
1152
|
...props.tableContainerProps,
|
|
1130
|
-
className: "--table-container " + ((_q = props.tableContainerProps) == null ? void 0 : _q.className),
|
|
1153
|
+
className: "--table-container " + (((_q = props.tableContainerProps) == null ? void 0 : _q.className) ?? ""),
|
|
1154
|
+
style: { contain: "strict" },
|
|
1131
1155
|
onScroll: ((_r = props.tableContainerProps) == null ? void 0 : _r.onScroll) ?? onTableContainerScroll,
|
|
1132
1156
|
ref: (node) => {
|
|
1133
1157
|
var _a2;
|
package/dist/index.mjs
CHANGED
|
@@ -619,7 +619,7 @@ import {
|
|
|
619
619
|
getSortedRowModel,
|
|
620
620
|
useReactTable
|
|
621
621
|
} from "@tanstack/react-table";
|
|
622
|
-
import { useEffect as useEffect3, useRef as useRef3, useState as
|
|
622
|
+
import { useEffect as useEffect3, useRef as useRef3, useState as useState6 } from "react";
|
|
623
623
|
import styled16 from "styled-components";
|
|
624
624
|
|
|
625
625
|
// src/DataTable/components/BasicTable.tsx
|
|
@@ -661,11 +661,19 @@ var TableBody = styled12(Table6.Body)`
|
|
|
661
661
|
import { Table as Table7 } from "@equinor/eds-core-react";
|
|
662
662
|
import styled13 from "styled-components";
|
|
663
663
|
import { jsx as jsx13 } from "react/jsx-runtime";
|
|
664
|
-
function TableRow({
|
|
664
|
+
function TableRow({
|
|
665
|
+
row,
|
|
666
|
+
rowConfig,
|
|
667
|
+
cellConfig,
|
|
668
|
+
measureElement,
|
|
669
|
+
index
|
|
670
|
+
}) {
|
|
665
671
|
var _a;
|
|
666
672
|
const rowWrapper = rowConfig == null ? void 0 : rowConfig.rowWrapper;
|
|
667
673
|
const tableRowContent = /* @__PURE__ */ jsx13(StyledTableRow, {
|
|
668
674
|
active: row.getIsSelected(),
|
|
675
|
+
"data-index": index,
|
|
676
|
+
ref: measureElement,
|
|
669
677
|
style: {
|
|
670
678
|
cursor: (rowConfig == null ? void 0 : rowConfig.onClick) ? "pointer" : "initial",
|
|
671
679
|
backgroundColor: (_a = rowConfig == null ? void 0 : rowConfig.getRowBackground) == null ? void 0 : _a.call(rowConfig, row)
|
|
@@ -902,6 +910,7 @@ function VirtualTable({
|
|
|
902
910
|
count: rows.length,
|
|
903
911
|
estimateSize: () => 48,
|
|
904
912
|
getScrollElement: () => containerRef.current,
|
|
913
|
+
measureElement: (element) => element == null ? void 0 : element.getBoundingClientRect().height,
|
|
905
914
|
overscan: 5
|
|
906
915
|
});
|
|
907
916
|
const virtualRows = rowVirtualizer.getVirtualItems();
|
|
@@ -927,7 +936,9 @@ function VirtualTable({
|
|
|
927
936
|
return /* @__PURE__ */ jsx18(TableRow, {
|
|
928
937
|
row,
|
|
929
938
|
rowConfig,
|
|
930
|
-
cellConfig
|
|
939
|
+
cellConfig,
|
|
940
|
+
index: virtualRow.index,
|
|
941
|
+
measureElement: rowVirtualizer.measureElement
|
|
931
942
|
}, row.id);
|
|
932
943
|
}) : /* @__PURE__ */ jsx18(PlaceholderRow, {
|
|
933
944
|
isLoading: props.isLoading
|
|
@@ -970,6 +981,13 @@ function useFetchMoreOnBottomReached(tableContainerRef, infiniteScrollConfig) {
|
|
|
970
981
|
return onTableContainerScroll;
|
|
971
982
|
}
|
|
972
983
|
|
|
984
|
+
// src/DataTable/hooks/useForceRerender.ts
|
|
985
|
+
import { useCallback as useCallback2, useState as useState5 } from "react";
|
|
986
|
+
function useForceRerender() {
|
|
987
|
+
const [, setTick] = useState5(0);
|
|
988
|
+
return useCallback2(() => setTick((tick) => tick + 1), []);
|
|
989
|
+
}
|
|
990
|
+
|
|
973
991
|
// src/DataTable/DataTable.tsx
|
|
974
992
|
import { jsx as jsx19, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
975
993
|
var DataTableWrapper = styled16.div`
|
|
@@ -977,14 +995,14 @@ var DataTableWrapper = styled16.div`
|
|
|
977
995
|
|
|
978
996
|
.--table-container {
|
|
979
997
|
height: ${(props) => props.height ?? "100%"};
|
|
980
|
-
width:
|
|
998
|
+
width: '100%';
|
|
981
999
|
overflow: auto;
|
|
982
1000
|
|
|
983
1001
|
table {
|
|
984
1002
|
width: 100%;
|
|
985
1003
|
|
|
986
1004
|
// The following attribute is important for fixed column width
|
|
987
|
-
// CHANGE
|
|
1005
|
+
// CHANGE THIS WITH CAUTION
|
|
988
1006
|
table-layout: ${(props) => props.tableLayout ?? "auto"};
|
|
989
1007
|
}
|
|
990
1008
|
}
|
|
@@ -992,12 +1010,12 @@ var DataTableWrapper = styled16.div`
|
|
|
992
1010
|
function DataTable(props) {
|
|
993
1011
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
994
1012
|
const { columns, data, bannerConfig, cellConfig, sorting } = props;
|
|
995
|
-
const [internalColumnVisibility, setInternalColumnVisibility] =
|
|
1013
|
+
const [internalColumnVisibility, setInternalColumnVisibility] = useState6({});
|
|
996
1014
|
const [columnVisibility, setColumnVisibility] = [
|
|
997
1015
|
((_a = props.columnVisibility) == null ? void 0 : _a.state) ?? internalColumnVisibility,
|
|
998
1016
|
((_b = props.columnVisibility) == null ? void 0 : _b.onChange) ?? setInternalColumnVisibility
|
|
999
1017
|
];
|
|
1000
|
-
const [internalGlobalFilterState, setInternalGlobalFilterState] =
|
|
1018
|
+
const [internalGlobalFilterState, setInternalGlobalFilterState] = useState6("");
|
|
1001
1019
|
const [globalFilterState, setGlobalFilterState] = [
|
|
1002
1020
|
((_c = props.globalFilter) == null ? void 0 : _c.state) ?? internalGlobalFilterState,
|
|
1003
1021
|
((_d = props.globalFilter) == null ? void 0 : _d.onChange) ?? setInternalGlobalFilterState
|
|
@@ -1006,17 +1024,17 @@ function DataTable(props) {
|
|
|
1006
1024
|
function enableGlobalFilter(value) {
|
|
1007
1025
|
return enableOrUndefined(shouldEnableGlobalFilter, value);
|
|
1008
1026
|
}
|
|
1009
|
-
const [internalSortingState, setInternalSortingState] =
|
|
1027
|
+
const [internalSortingState, setInternalSortingState] = useState6([]);
|
|
1010
1028
|
const [sortingState, setSortingState] = [
|
|
1011
1029
|
((_f = props.sorting) == null ? void 0 : _f.state) ?? internalSortingState,
|
|
1012
1030
|
((_g = props.sorting) == null ? void 0 : _g.onChange) ?? setInternalSortingState
|
|
1013
1031
|
];
|
|
1014
|
-
const [internalRowSelectionState, setInternalRowSelectionState] =
|
|
1032
|
+
const [internalRowSelectionState, setInternalRowSelectionState] = useState6({});
|
|
1015
1033
|
const [rowSelectionState, setRowSelectionState] = [
|
|
1016
1034
|
((_h = props.rowSelection) == null ? void 0 : _h.state) ?? internalRowSelectionState,
|
|
1017
1035
|
((_i = props.rowSelection) == null ? void 0 : _i.onChange) ?? setInternalRowSelectionState
|
|
1018
1036
|
];
|
|
1019
|
-
const [internalExpandedState, setInternalExpandedState] =
|
|
1037
|
+
const [internalExpandedState, setInternalExpandedState] = useState6({});
|
|
1020
1038
|
const [expandedState, setExpandedState] = [
|
|
1021
1039
|
((_j = props.expansion) == null ? void 0 : _j.state) ?? internalExpandedState,
|
|
1022
1040
|
((_k = props.expansion) == null ? void 0 : _k.onChange) ?? setInternalExpandedState
|
|
@@ -1071,6 +1089,11 @@ function DataTable(props) {
|
|
|
1071
1089
|
tableContainerRef,
|
|
1072
1090
|
props.infiniteScroll
|
|
1073
1091
|
);
|
|
1092
|
+
const forceRerender = useForceRerender();
|
|
1093
|
+
useEffect3(() => {
|
|
1094
|
+
if (Boolean(tableContainerRef.current))
|
|
1095
|
+
forceRerender();
|
|
1096
|
+
}, [tableContainerRef.current === null]);
|
|
1074
1097
|
return /* @__PURE__ */ jsxs11(DataTableWrapper, {
|
|
1075
1098
|
height: props == null ? void 0 : props.height,
|
|
1076
1099
|
width: props == null ? void 0 : props.width,
|
|
@@ -1084,7 +1107,8 @@ function DataTable(props) {
|
|
|
1084
1107
|
}),
|
|
1085
1108
|
/* @__PURE__ */ jsx19("div", {
|
|
1086
1109
|
...props.tableContainerProps,
|
|
1087
|
-
className: "--table-container " + ((_q = props.tableContainerProps) == null ? void 0 : _q.className),
|
|
1110
|
+
className: "--table-container " + (((_q = props.tableContainerProps) == null ? void 0 : _q.className) ?? ""),
|
|
1111
|
+
style: { contain: "strict" },
|
|
1088
1112
|
onScroll: ((_r = props.tableContainerProps) == null ? void 0 : _r.onScroll) ?? onTableContainerScroll,
|
|
1089
1113
|
ref: (node) => {
|
|
1090
1114
|
var _a2;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equinor/apollo-components",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.3-beta.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -21,15 +21,15 @@
|
|
|
21
21
|
"@equinor/eds-tokens": "^0.9.0",
|
|
22
22
|
"@tanstack/match-sorter-utils": "^8.7.6",
|
|
23
23
|
"@tanstack/react-table": "^8.7.6",
|
|
24
|
-
"@tanstack/react-virtual": "^3.0.0-beta.
|
|
24
|
+
"@tanstack/react-virtual": "^3.0.0-beta.54",
|
|
25
25
|
"tsup": "^6.3.0",
|
|
26
26
|
"type-fest": "^3.6.1"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"@equinor/eds-core-react": "^0.27.0",
|
|
30
|
-
"styled-components": "^5.3.7",
|
|
31
30
|
"react": "^18.2.0",
|
|
32
|
-
"react-dom": "^18.2.0"
|
|
31
|
+
"react-dom": "^18.2.0",
|
|
32
|
+
"styled-components": "^5.3.7"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@storybook/addon-essentials": "^7.0.0-alpha.38",
|