@equinor/apollo-components 1.12.2 → 1.12.3
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.d.ts +13 -2
- package/dist/index.js +51 -8
- package/dist/index.mjs +49 -6
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IconData } from '@equinor/eds-icons';
|
|
2
2
|
import * as react from 'react';
|
|
3
|
-
import { ReactNode, ReactElement, ComponentProps } from 'react';
|
|
3
|
+
import { ReactNode, ReactElement, HTMLProps, MutableRefObject, ComponentProps } from 'react';
|
|
4
4
|
import { Cell, CellContext, Table, Row, SortingState, OnChangeFn, ColumnDef, VisibilityState, RowSelectionState, HeaderContext } from '@tanstack/react-table';
|
|
5
5
|
import { ColumnDef as ColumnDef$1 } from '@tanstack/table-core';
|
|
6
6
|
import * as styled_components from 'styled-components';
|
|
@@ -108,6 +108,15 @@ interface ExpansionConfig {
|
|
|
108
108
|
expandAllByDefault?: boolean;
|
|
109
109
|
hideExpandControls?: boolean;
|
|
110
110
|
}
|
|
111
|
+
interface HTMLPropsRef<T extends HTMLElement> extends HTMLProps<T> {
|
|
112
|
+
ref?: MutableRefObject<T | null> | null;
|
|
113
|
+
}
|
|
114
|
+
interface InfiniteScrollConfig {
|
|
115
|
+
/** Called on scroll below offset. */
|
|
116
|
+
onBottomScroll: () => void;
|
|
117
|
+
/** Pixels above bottom. Defines when the onBottomScroll should be called. Defaults to `300`. */
|
|
118
|
+
offset?: number;
|
|
119
|
+
}
|
|
111
120
|
interface DataTableCommonProps<T> {
|
|
112
121
|
isLoading?: boolean;
|
|
113
122
|
className?: string;
|
|
@@ -117,6 +126,8 @@ interface DataTableCommonProps<T> {
|
|
|
117
126
|
sortConfig?: SortConfig;
|
|
118
127
|
filters?: FilterConfig;
|
|
119
128
|
header?: HeaderConfig;
|
|
129
|
+
tableContainerProps?: HTMLPropsRef<HTMLDivElement>;
|
|
130
|
+
infiniteScroll?: InfiniteScrollConfig;
|
|
120
131
|
}
|
|
121
132
|
interface DataTableProps<T> extends DataTableCommonProps<T> {
|
|
122
133
|
data: T[];
|
|
@@ -180,4 +191,4 @@ declare type TypographyProps = {
|
|
|
180
191
|
} & TypographyProps$1;
|
|
181
192
|
declare const TypographyCustom: (props: TypographyProps) => JSX.Element;
|
|
182
193
|
|
|
183
|
-
export { AppShell, AppSidebar, CellConfig, ChipsCell, ColumnSelect, DataTable, DataTableCommonProps, DataTableConfig, DataTableProps, DataTableRawProps, DynamicCell, FilterConfig, HeaderConfig, HierarchyCell, RowConfig, RowSelectionMode, SelectColumnDef, SortConfig, StickyCell, TableHeader, TableLayout, TableRowWrapper, TableRowWrapperProps, TruncateMode, TypographyCustom, capitalizeHeader, columnVisibilityAtom, globalFilterAtom, prependSelectColumn, rowSelectionAtom, tableSortingAtom };
|
|
194
|
+
export { AppShell, AppSidebar, CellConfig, ChipsCell, ColumnSelect, DataTable, DataTableCommonProps, DataTableConfig, DataTableProps, DataTableRawProps, DynamicCell, FilterConfig, HTMLPropsRef, HeaderConfig, HierarchyCell, InfiniteScrollConfig, RowConfig, RowSelectionMode, SelectColumnDef, SortConfig, StickyCell, TableHeader, TableLayout, TableRowWrapper, TableRowWrapperProps, TruncateMode, TypographyCustom, capitalizeHeader, columnVisibilityAtom, globalFilterAtom, prependSelectColumn, rowSelectionAtom, tableSortingAtom };
|
package/dist/index.js
CHANGED
|
@@ -405,7 +405,7 @@ function SelectColumnDef(props = {}) {
|
|
|
405
405
|
}
|
|
406
406
|
|
|
407
407
|
// src/DataTable/DataTableRaw.tsx
|
|
408
|
-
var
|
|
408
|
+
var import_react5 = require("react");
|
|
409
409
|
var import_styled_components16 = __toESM(require("styled-components"));
|
|
410
410
|
|
|
411
411
|
// src/DataTable/components/BasicTable.tsx
|
|
@@ -918,6 +918,35 @@ function VirtualTable({
|
|
|
918
918
|
});
|
|
919
919
|
}
|
|
920
920
|
|
|
921
|
+
// src/DataTable/hooks/useFetchMoreOnBottomReached.tsx
|
|
922
|
+
var import_react4 = require("react");
|
|
923
|
+
function useFetchMoreOnBottomReached(tableContainerRef, infiniteScrollConfig) {
|
|
924
|
+
const fetchMoreOnBottomReached = (0, import_react4.useCallback)(
|
|
925
|
+
(tableContainer) => {
|
|
926
|
+
if (!infiniteScrollConfig)
|
|
927
|
+
return;
|
|
928
|
+
if (!tableContainer)
|
|
929
|
+
return;
|
|
930
|
+
const { onBottomScroll, offset = 300 } = infiniteScrollConfig;
|
|
931
|
+
const { scrollHeight, scrollTop, clientHeight } = tableContainer;
|
|
932
|
+
if (scrollHeight - scrollTop - clientHeight < offset) {
|
|
933
|
+
onBottomScroll();
|
|
934
|
+
}
|
|
935
|
+
},
|
|
936
|
+
[infiniteScrollConfig]
|
|
937
|
+
);
|
|
938
|
+
const onTableContainerScroll = (0, import_react4.useCallback)(
|
|
939
|
+
(event) => fetchMoreOnBottomReached(event.target),
|
|
940
|
+
[fetchMoreOnBottomReached]
|
|
941
|
+
);
|
|
942
|
+
(0, import_react4.useEffect)(() => {
|
|
943
|
+
if (!infiniteScrollConfig)
|
|
944
|
+
return;
|
|
945
|
+
fetchMoreOnBottomReached(tableContainerRef.current);
|
|
946
|
+
}, [fetchMoreOnBottomReached]);
|
|
947
|
+
return onTableContainerScroll;
|
|
948
|
+
}
|
|
949
|
+
|
|
921
950
|
// src/DataTable/DataTableRaw.tsx
|
|
922
951
|
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
923
952
|
var DataTableWrapper = import_styled_components16.default.div`
|
|
@@ -931,16 +960,20 @@ var DataTableWrapper = import_styled_components16.default.div`
|
|
|
931
960
|
table {
|
|
932
961
|
width: 100%;
|
|
933
962
|
|
|
934
|
-
// The following
|
|
963
|
+
// The following attribute is important for fixed column width
|
|
935
964
|
// CHANGE THES WITH CAUTION
|
|
936
|
-
overflow: auto;
|
|
937
965
|
table-layout: ${(props) => props.tableLayout ?? "auto"};
|
|
938
966
|
}
|
|
939
967
|
}
|
|
940
968
|
`;
|
|
941
969
|
function DataTableRaw(props) {
|
|
970
|
+
var _a, _b;
|
|
942
971
|
const { isLoading, header, filters, config, rowConfig, cellConfig, table } = props;
|
|
943
|
-
const tableContainerRef = (0,
|
|
972
|
+
const tableContainerRef = (0, import_react5.useRef)(null);
|
|
973
|
+
const onTableContainerScroll = useFetchMoreOnBottomReached(
|
|
974
|
+
tableContainerRef,
|
|
975
|
+
props.infiniteScroll
|
|
976
|
+
);
|
|
944
977
|
return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(DataTableWrapper, {
|
|
945
978
|
captionPadding: header == null ? void 0 : header.captionPadding,
|
|
946
979
|
height: config == null ? void 0 : config.height,
|
|
@@ -954,8 +987,18 @@ function DataTableRaw(props) {
|
|
|
954
987
|
config: filters
|
|
955
988
|
}),
|
|
956
989
|
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", {
|
|
957
|
-
|
|
958
|
-
className: "--table-container",
|
|
990
|
+
...props.tableContainerProps,
|
|
991
|
+
className: "--table-container " + ((_a = props.tableContainerProps) == null ? void 0 : _a.className),
|
|
992
|
+
onScroll: ((_b = props.tableContainerProps) == null ? void 0 : _b.onScroll) ?? onTableContainerScroll,
|
|
993
|
+
ref: (node) => {
|
|
994
|
+
var _a2;
|
|
995
|
+
if (node) {
|
|
996
|
+
tableContainerRef.current = node;
|
|
997
|
+
if ((_a2 = props.tableContainerProps) == null ? void 0 : _a2.ref) {
|
|
998
|
+
props.tableContainerProps.ref.current = node;
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
},
|
|
959
1002
|
children: (config == null ? void 0 : config.virtual) ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(VirtualTable, {
|
|
960
1003
|
containerRef: tableContainerRef,
|
|
961
1004
|
table,
|
|
@@ -978,7 +1021,7 @@ function DataTableRaw(props) {
|
|
|
978
1021
|
// src/DataTable/useDataTable.tsx
|
|
979
1022
|
var import_react_table3 = require("@tanstack/react-table");
|
|
980
1023
|
var import_jotai3 = require("jotai");
|
|
981
|
-
var
|
|
1024
|
+
var import_react6 = require("react");
|
|
982
1025
|
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
983
1026
|
function useDataTable(props) {
|
|
984
1027
|
const { columns, data, filters, config, cellConfig, sortConfig } = props;
|
|
@@ -1028,7 +1071,7 @@ function useDataTable(props) {
|
|
|
1028
1071
|
getSubRows: config == null ? void 0 : config.getSubRows,
|
|
1029
1072
|
getRowId: config == null ? void 0 : config.getRowId
|
|
1030
1073
|
});
|
|
1031
|
-
(0,
|
|
1074
|
+
(0, import_react6.useEffect)(() => {
|
|
1032
1075
|
if (config && config.expandAllByDefault) {
|
|
1033
1076
|
table.toggleAllRowsExpanded();
|
|
1034
1077
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -872,6 +872,35 @@ function VirtualTable({
|
|
|
872
872
|
});
|
|
873
873
|
}
|
|
874
874
|
|
|
875
|
+
// src/DataTable/hooks/useFetchMoreOnBottomReached.tsx
|
|
876
|
+
import { useCallback, useEffect as useEffect2 } from "react";
|
|
877
|
+
function useFetchMoreOnBottomReached(tableContainerRef, infiniteScrollConfig) {
|
|
878
|
+
const fetchMoreOnBottomReached = useCallback(
|
|
879
|
+
(tableContainer) => {
|
|
880
|
+
if (!infiniteScrollConfig)
|
|
881
|
+
return;
|
|
882
|
+
if (!tableContainer)
|
|
883
|
+
return;
|
|
884
|
+
const { onBottomScroll, offset = 300 } = infiniteScrollConfig;
|
|
885
|
+
const { scrollHeight, scrollTop, clientHeight } = tableContainer;
|
|
886
|
+
if (scrollHeight - scrollTop - clientHeight < offset) {
|
|
887
|
+
onBottomScroll();
|
|
888
|
+
}
|
|
889
|
+
},
|
|
890
|
+
[infiniteScrollConfig]
|
|
891
|
+
);
|
|
892
|
+
const onTableContainerScroll = useCallback(
|
|
893
|
+
(event) => fetchMoreOnBottomReached(event.target),
|
|
894
|
+
[fetchMoreOnBottomReached]
|
|
895
|
+
);
|
|
896
|
+
useEffect2(() => {
|
|
897
|
+
if (!infiniteScrollConfig)
|
|
898
|
+
return;
|
|
899
|
+
fetchMoreOnBottomReached(tableContainerRef.current);
|
|
900
|
+
}, [fetchMoreOnBottomReached]);
|
|
901
|
+
return onTableContainerScroll;
|
|
902
|
+
}
|
|
903
|
+
|
|
875
904
|
// src/DataTable/DataTableRaw.tsx
|
|
876
905
|
import { jsx as jsx18, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
877
906
|
var DataTableWrapper = styled16.div`
|
|
@@ -885,16 +914,20 @@ var DataTableWrapper = styled16.div`
|
|
|
885
914
|
table {
|
|
886
915
|
width: 100%;
|
|
887
916
|
|
|
888
|
-
// The following
|
|
917
|
+
// The following attribute is important for fixed column width
|
|
889
918
|
// CHANGE THES WITH CAUTION
|
|
890
|
-
overflow: auto;
|
|
891
919
|
table-layout: ${(props) => props.tableLayout ?? "auto"};
|
|
892
920
|
}
|
|
893
921
|
}
|
|
894
922
|
`;
|
|
895
923
|
function DataTableRaw(props) {
|
|
924
|
+
var _a, _b;
|
|
896
925
|
const { isLoading, header, filters, config, rowConfig, cellConfig, table } = props;
|
|
897
926
|
const tableContainerRef = useRef2(null);
|
|
927
|
+
const onTableContainerScroll = useFetchMoreOnBottomReached(
|
|
928
|
+
tableContainerRef,
|
|
929
|
+
props.infiniteScroll
|
|
930
|
+
);
|
|
898
931
|
return /* @__PURE__ */ jsxs10(DataTableWrapper, {
|
|
899
932
|
captionPadding: header == null ? void 0 : header.captionPadding,
|
|
900
933
|
height: config == null ? void 0 : config.height,
|
|
@@ -908,8 +941,18 @@ function DataTableRaw(props) {
|
|
|
908
941
|
config: filters
|
|
909
942
|
}),
|
|
910
943
|
/* @__PURE__ */ jsx18("div", {
|
|
911
|
-
|
|
912
|
-
className: "--table-container",
|
|
944
|
+
...props.tableContainerProps,
|
|
945
|
+
className: "--table-container " + ((_a = props.tableContainerProps) == null ? void 0 : _a.className),
|
|
946
|
+
onScroll: ((_b = props.tableContainerProps) == null ? void 0 : _b.onScroll) ?? onTableContainerScroll,
|
|
947
|
+
ref: (node) => {
|
|
948
|
+
var _a2;
|
|
949
|
+
if (node) {
|
|
950
|
+
tableContainerRef.current = node;
|
|
951
|
+
if ((_a2 = props.tableContainerProps) == null ? void 0 : _a2.ref) {
|
|
952
|
+
props.tableContainerProps.ref.current = node;
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
},
|
|
913
956
|
children: (config == null ? void 0 : config.virtual) ? /* @__PURE__ */ jsx18(VirtualTable, {
|
|
914
957
|
containerRef: tableContainerRef,
|
|
915
958
|
table,
|
|
@@ -938,7 +981,7 @@ import {
|
|
|
938
981
|
useReactTable
|
|
939
982
|
} from "@tanstack/react-table";
|
|
940
983
|
import { useAtom as useAtom2 } from "jotai";
|
|
941
|
-
import { useEffect as
|
|
984
|
+
import { useEffect as useEffect3 } from "react";
|
|
942
985
|
import { jsx as jsx19 } from "react/jsx-runtime";
|
|
943
986
|
function useDataTable(props) {
|
|
944
987
|
const { columns, data, filters, config, cellConfig, sortConfig } = props;
|
|
@@ -988,7 +1031,7 @@ function useDataTable(props) {
|
|
|
988
1031
|
getSubRows: config == null ? void 0 : config.getSubRows,
|
|
989
1032
|
getRowId: config == null ? void 0 : config.getRowId
|
|
990
1033
|
});
|
|
991
|
-
|
|
1034
|
+
useEffect3(() => {
|
|
992
1035
|
if (config && config.expandAllByDefault) {
|
|
993
1036
|
table.toggleAllRowsExpanded();
|
|
994
1037
|
}
|