@symply.io/basic-components 1.6.11-alpha.5 → 1.7.0-alpha.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/DataTable/{TableCore/TableBody.d.ts → TableBody.d.ts} +1 -1
- package/DataTable/TableBody.js +32 -0
- package/DataTable/{TableCore/TableBodyRow.d.ts → TableBodyRow.d.ts} +1 -1
- package/DataTable/TableBodyRow.js +123 -0
- package/DataTable/TableFooter.d.ts +3 -0
- package/DataTable/{TableCore/TableFooter.js → TableFooter.js} +5 -7
- package/DataTable/TableHeader.d.ts +3 -0
- package/DataTable/{TableCore/TableHeader.js → TableHeader.js} +5 -7
- package/DataTable/index.js +42 -16
- package/DataTable/types.d.ts +10 -23
- package/DataTable/useTable.d.ts +2 -2
- package/DataTable/useTable.js +3 -3
- package/README.md +71 -0
- package/VirtualGrid/GridCore/TableBody.d.ts +3 -0
- package/{DataTable/TableCore → VirtualGrid/GridCore}/TableBody.js +12 -7
- package/VirtualGrid/GridCore/TableBodyRow.d.ts +3 -0
- package/{DataTable/TableCore → VirtualGrid/GridCore}/TableBodyRow.js +12 -6
- package/VirtualGrid/GridCore/TableFooter.d.ts +5 -0
- package/VirtualGrid/GridCore/TableFooter.js +114 -0
- package/VirtualGrid/GridCore/TableHeader.d.ts +5 -0
- package/VirtualGrid/GridCore/TableHeader.js +118 -0
- package/VirtualGrid/GridCore/index.d.ts +3 -0
- package/{DataTable/TableCore → VirtualGrid/GridCore}/index.js +4 -4
- package/VirtualGrid/GridVirtualizerContext.d.ts +3 -0
- package/{DataTable/VirtualizerContext.js → VirtualGrid/GridVirtualizerContext.js} +40 -8
- package/VirtualGrid/index.d.ts +6 -0
- package/VirtualGrid/index.js +36 -0
- package/VirtualGrid/types.d.ts +104 -0
- package/VirtualGrid/types.js +1 -0
- package/VirtualGrid/useVirtualGrid.d.ts +3 -0
- package/VirtualGrid/useVirtualGrid.js +103 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +1 -1
- package/DataTable/TableCore/TableFooter.d.ts +0 -5
- package/DataTable/TableCore/TableHeader.d.ts +0 -5
- package/DataTable/TableCore/index.d.ts +0 -3
- package/DataTable/VirtualizerContext.d.ts +0 -3
@@ -0,0 +1,114 @@
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
2
|
+
__assign = Object.assign || function(t) {
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
+
s = arguments[i];
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
+
t[p] = s[p];
|
7
|
+
}
|
8
|
+
return t;
|
9
|
+
};
|
10
|
+
return __assign.apply(this, arguments);
|
11
|
+
};
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
13
|
+
import { memo, cloneElement, useMemo } from "react";
|
14
|
+
import TableRow from "@mui/material/TableRow";
|
15
|
+
import Footer from "@mui/material/TableFooter";
|
16
|
+
import TableCell from "@mui/material/TableCell";
|
17
|
+
import useMediaQuery from "@mui/material/useMediaQuery";
|
18
|
+
import useTheme from "@mui/material/styles/useTheme";
|
19
|
+
import { useGridVirtualizer } from "../GridVirtualizerContext";
|
20
|
+
function TableFooter(props) {
|
21
|
+
var _a = props.footers, footers = _a === void 0 ? [] : _a, footerBgColor = props.footerBgColor, footerTextColor = props.footerTextColor, noData = props.noData;
|
22
|
+
var theme = useTheme();
|
23
|
+
var isUpMd = useMediaQuery(theme.breakpoints.up("md"));
|
24
|
+
var _b = useGridVirtualizer(), leftShadowVisible = _b.leftShadowVisible, rightShadowVisible = _b.rightShadowVisible;
|
25
|
+
var _c = useMemo(function () {
|
26
|
+
if (isUpMd && !noData) {
|
27
|
+
var left = footers.filter(function (f) { return f.fixable === "left"; });
|
28
|
+
var right = footers.filter(function (f) { return f.fixable === "right"; });
|
29
|
+
var dynamic = footers.filter(function (f) { return !f.fixable; });
|
30
|
+
return [left, dynamic, right];
|
31
|
+
}
|
32
|
+
else {
|
33
|
+
return [[], footers, []];
|
34
|
+
}
|
35
|
+
}, [isUpMd, noData, footers]), fixedLeftFooters = _c[0], dynamicFooters = _c[1], fixedRightFooters = _c[2];
|
36
|
+
return (_jsx(Footer, __assign({ sx: {
|
37
|
+
position: "sticky",
|
38
|
+
bottom: "-1px",
|
39
|
+
zIndex: 20,
|
40
|
+
display: "grid",
|
41
|
+
} }, { children: _jsxs(TableRow, __assign({ sx: {
|
42
|
+
backgroundColor: "".concat(footerBgColor || "#eaf0f6", " !important"),
|
43
|
+
color: "".concat(footerTextColor || "inherit", " !important"),
|
44
|
+
display: "flex",
|
45
|
+
width: "100%",
|
46
|
+
} }, { children: [fixedLeftFooters.map(function (footer, index) {
|
47
|
+
var accessor = footer.accessor, Cell = footer.Cell, _a = footer.align, align = _a === void 0 ? "center" : _a, width = footer.width;
|
48
|
+
var left = fixedLeftFooters
|
49
|
+
.slice(0, index)
|
50
|
+
.reduce(function (w, t) { return w + (t.width || 0); }, 0);
|
51
|
+
return (_jsx(TableCell, __assign({ align: align, sx: {
|
52
|
+
position: "sticky",
|
53
|
+
backgroundColor: "".concat(footerBgColor || "#eaf0f6", " !important"),
|
54
|
+
color: "".concat(footerTextColor || "inherit", " !important"),
|
55
|
+
zIndex: 10,
|
56
|
+
left: left,
|
57
|
+
minWidth: width,
|
58
|
+
display: "flex",
|
59
|
+
userSelect: "none",
|
60
|
+
"&::after": index === fixedLeftFooters.length - 1 && leftShadowVisible
|
61
|
+
? {
|
62
|
+
position: "absolute",
|
63
|
+
top: 0,
|
64
|
+
right: 0,
|
65
|
+
bottom: "-1px",
|
66
|
+
width: "20px",
|
67
|
+
transform: "translateX(100%)",
|
68
|
+
transition: "box-shadow .3s",
|
69
|
+
content: "''",
|
70
|
+
boxShadow: "inset 10px 0 10px -8px rgba(0, 0, 0, 0.1)",
|
71
|
+
}
|
72
|
+
: undefined,
|
73
|
+
} }, { children: cloneElement(Cell) }), accessor));
|
74
|
+
}), dynamicFooters.map(function (footer) {
|
75
|
+
var accessor = footer.accessor, Cell = footer.Cell, _a = footer.align, align = _a === void 0 ? "center" : _a, width = footer.width;
|
76
|
+
return (_jsx(TableCell, __assign({ align: align, sx: {
|
77
|
+
zIndex: 9,
|
78
|
+
minWidth: width,
|
79
|
+
display: "flex",
|
80
|
+
userSelect: "none",
|
81
|
+
backgroundColor: "".concat(footerBgColor || "#eaf0f6", " !important"),
|
82
|
+
color: "".concat(footerTextColor || "inherit", " !important"),
|
83
|
+
} }, { children: cloneElement(Cell) }), accessor));
|
84
|
+
}), fixedRightFooters.map(function (footer, index) {
|
85
|
+
var accessor = footer.accessor, Cell = footer.Cell, _a = footer.align, align = _a === void 0 ? "center" : _a, width = footer.width;
|
86
|
+
var right = fixedRightFooters
|
87
|
+
.slice(0, fixedRightFooters.length - 1 - index)
|
88
|
+
.reduce(function (w, t) { return w + (t.width || 0); }, 0);
|
89
|
+
return (_jsx(TableCell, __assign({ align: align, sx: {
|
90
|
+
position: "sticky",
|
91
|
+
zIndex: 10,
|
92
|
+
minWidth: width,
|
93
|
+
right: right,
|
94
|
+
display: "flex",
|
95
|
+
backgroundColor: "".concat(footerBgColor || "#eaf0f6", " !important"),
|
96
|
+
color: "".concat(footerTextColor || "inherit", " !important"),
|
97
|
+
userSelect: "none",
|
98
|
+
"&::after": index === 0 && rightShadowVisible
|
99
|
+
? {
|
100
|
+
position: "absolute",
|
101
|
+
top: 0,
|
102
|
+
left: 0,
|
103
|
+
bottom: "-1px",
|
104
|
+
width: "20px",
|
105
|
+
transform: "translateX(-100%)",
|
106
|
+
transition: "box-shadow .3s",
|
107
|
+
content: "''",
|
108
|
+
boxShadow: "inset -10px 0 10px -8px rgba(0, 0, 0, 0.1)",
|
109
|
+
}
|
110
|
+
: undefined,
|
111
|
+
} }, { children: cloneElement(Cell) }), accessor));
|
112
|
+
})] })) })));
|
113
|
+
}
|
114
|
+
export default memo(TableFooter);
|
@@ -0,0 +1,5 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
import type { VirtualGridHeaderProps } from "../types";
|
3
|
+
declare function TableHeader<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>>(props: VirtualGridHeaderProps<RowProps, ExtendedProps>): import("react/jsx-runtime").JSX.Element;
|
4
|
+
declare const _default: import("react").MemoExoticComponent<typeof TableHeader>;
|
5
|
+
export default _default;
|
@@ -0,0 +1,118 @@
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
2
|
+
__assign = Object.assign || function(t) {
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
+
s = arguments[i];
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
+
t[p] = s[p];
|
7
|
+
}
|
8
|
+
return t;
|
9
|
+
};
|
10
|
+
return __assign.apply(this, arguments);
|
11
|
+
};
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
13
|
+
import { memo, cloneElement, useMemo } from "react";
|
14
|
+
import TableRow from "@mui/material/TableRow";
|
15
|
+
import TableHead from "@mui/material/TableHead";
|
16
|
+
import TableCell from "@mui/material/TableCell";
|
17
|
+
import useMediaQuery from "@mui/material/useMediaQuery";
|
18
|
+
import useTheme from "@mui/material/styles/useTheme";
|
19
|
+
import { useGridVirtualizer } from "../GridVirtualizerContext";
|
20
|
+
function TableHeader(props) {
|
21
|
+
var headers = props.headers, headerBgColor = props.headerBgColor, headerTextColor = props.headerTextColor, noData = props.noData;
|
22
|
+
var theme = useTheme();
|
23
|
+
var isUpMd = useMediaQuery(theme.breakpoints.up("md"));
|
24
|
+
var _a = useGridVirtualizer(), leftShadowVisible = _a.leftShadowVisible, rightShadowVisible = _a.rightShadowVisible;
|
25
|
+
var _b = useMemo(function () {
|
26
|
+
if (isUpMd && !noData) {
|
27
|
+
var left = headers.filter(function (h) { return h.fixable === "left"; });
|
28
|
+
var right = headers.filter(function (h) { return h.fixable === "right"; });
|
29
|
+
var dynamic = headers.filter(function (h) { return !h.fixable; });
|
30
|
+
return [left, dynamic, right];
|
31
|
+
}
|
32
|
+
else {
|
33
|
+
return [[], headers, []];
|
34
|
+
}
|
35
|
+
}, [isUpMd, noData, headers]), fixedLeftHeaders = _b[0], dynamicHeaders = _b[1], fixedRightHeaders = _b[2];
|
36
|
+
return (_jsx(TableHead, __assign({ sx: { position: "sticky", top: 0, zIndex: 20, display: "grid" } }, { children: _jsxs(TableRow, __assign({ sx: {
|
37
|
+
backgroundColor: "".concat(headerBgColor || "#eaf0f6", " !important"),
|
38
|
+
color: "".concat(headerTextColor || "inherit", " !important"),
|
39
|
+
display: "flex",
|
40
|
+
width: "100%",
|
41
|
+
} }, { children: [fixedLeftHeaders.map(function (header, index) {
|
42
|
+
var accessor = header.accessor, Cell = header.Cell, _a = header.align, align = _a === void 0 ? "center" : _a, width = header.width, title = header.title, _b = header.sortable, sortable = _b === void 0 ? false : _b, onSort = header.onSort;
|
43
|
+
var left = fixedLeftHeaders
|
44
|
+
.slice(0, index)
|
45
|
+
.reduce(function (w, t) { return w + (t.width || 0); }, 0);
|
46
|
+
return (_jsx(TableCell, __assign({ title: title, align: align, sx: {
|
47
|
+
position: "sticky",
|
48
|
+
backgroundColor: "".concat(headerBgColor || "#eaf0f6", " !important"),
|
49
|
+
color: "".concat(headerTextColor || "inherit", " !important"),
|
50
|
+
zIndex: 10,
|
51
|
+
minWidth: width,
|
52
|
+
left: left,
|
53
|
+
display: "flex",
|
54
|
+
userSelect: "none",
|
55
|
+
cursor: sortable ? "pointer" : "default",
|
56
|
+
"&::after": index === fixedLeftHeaders.length - 1 && leftShadowVisible
|
57
|
+
? {
|
58
|
+
position: "absolute",
|
59
|
+
top: 0,
|
60
|
+
right: 0,
|
61
|
+
bottom: "-1px",
|
62
|
+
width: "20px",
|
63
|
+
transform: "translateX(100%)",
|
64
|
+
transition: "box-shadow .3s",
|
65
|
+
content: "''",
|
66
|
+
boxShadow: "inset 10px 0 10px -8px rgba(0, 0, 0, 0.1)",
|
67
|
+
}
|
68
|
+
: undefined,
|
69
|
+
}, onClick: function () {
|
70
|
+
onSort({ accessor: accessor });
|
71
|
+
} }, { children: cloneElement(Cell) }), accessor));
|
72
|
+
}), dynamicHeaders.map(function (header) {
|
73
|
+
var accessor = header.accessor, Cell = header.Cell, _a = header.align, align = _a === void 0 ? "center" : _a, width = header.width, title = header.title, _b = header.sortable, sortable = _b === void 0 ? false : _b, onSort = header.onSort;
|
74
|
+
return (_jsx(TableCell, __assign({ title: title, align: align, sx: {
|
75
|
+
minWidth: width,
|
76
|
+
zIndex: 9,
|
77
|
+
userSelect: "none",
|
78
|
+
display: "flex",
|
79
|
+
cursor: sortable ? "pointer" : "default",
|
80
|
+
backgroundColor: "".concat(headerBgColor || "#eaf0f6", " !important"),
|
81
|
+
color: "".concat(headerTextColor || "inherit", " !important"),
|
82
|
+
}, onClick: function () {
|
83
|
+
onSort({ accessor: accessor });
|
84
|
+
} }, { children: cloneElement(Cell) }), accessor));
|
85
|
+
}), fixedRightHeaders.map(function (header, index) {
|
86
|
+
var accessor = header.accessor, Cell = header.Cell, _a = header.align, align = _a === void 0 ? "center" : _a, width = header.width, title = header.title, _b = header.sortable, sortable = _b === void 0 ? false : _b, onSort = header.onSort;
|
87
|
+
var right = fixedRightHeaders
|
88
|
+
.slice(0, fixedRightHeaders.length - 1 - index)
|
89
|
+
.reduce(function (w, t) { return w + (t.width || 0); }, 0);
|
90
|
+
return (_jsx(TableCell, __assign({ title: title, align: align, sx: {
|
91
|
+
position: "sticky",
|
92
|
+
backgroundColor: "".concat(headerBgColor || "#eaf0f6", " !important"),
|
93
|
+
color: "".concat(headerTextColor || "inherit", " !important"),
|
94
|
+
zIndex: 10,
|
95
|
+
minWidth: width,
|
96
|
+
right: right,
|
97
|
+
display: "flex",
|
98
|
+
userSelect: "none",
|
99
|
+
cursor: sortable ? "pointer" : "default",
|
100
|
+
"&::after": index === 0 && rightShadowVisible
|
101
|
+
? {
|
102
|
+
position: "absolute",
|
103
|
+
top: 0,
|
104
|
+
left: 0,
|
105
|
+
bottom: "-1px",
|
106
|
+
width: "20px",
|
107
|
+
transform: "translateX(-100%)",
|
108
|
+
transition: "box-shadow .3s",
|
109
|
+
content: "''",
|
110
|
+
boxShadow: "inset -10px 0 10px -8px rgba(0, 0, 0, 0.1)",
|
111
|
+
}
|
112
|
+
: undefined,
|
113
|
+
}, onClick: function () {
|
114
|
+
onSort({ accessor: accessor });
|
115
|
+
} }, { children: cloneElement(Cell) }), accessor));
|
116
|
+
})] })) })));
|
117
|
+
}
|
118
|
+
export default memo(TableHeader);
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import type { VirtualGridCoreProps } from "../types";
|
2
|
+
declare function VirtualGridCore<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>>(props: VirtualGridCoreProps<RowProps, ExtendedProps>): import("react/jsx-runtime").JSX.Element;
|
3
|
+
export default VirtualGridCore;
|
@@ -15,10 +15,10 @@ import TableContainer from "@mui/material/TableContainer";
|
|
15
15
|
import TableBody from "./TableBody";
|
16
16
|
import TableHeader from "./TableHeader";
|
17
17
|
import TableFooter from "./TableFooter";
|
18
|
-
import {
|
19
|
-
function
|
18
|
+
import { useGridVirtualizer } from "../GridVirtualizerContext";
|
19
|
+
function VirtualGridCore(props) {
|
20
20
|
var dense = props.dense, _a = props.rows, rows = _a === void 0 ? [] : _a, _b = props.columns, columns = _b === void 0 ? [] : _b, _c = props.headers, headers = _c === void 0 ? [] : _c, _d = props.footers, footers = _d === void 0 ? [] : _d, _e = props.noDataText, noDataText = _e === void 0 ? "No Data!" : _e, headerBgColor = props.headerBgColor, headerTextColor = props.headerTextColor, footerBgColor = props.footerBgColor, footerTextColor = props.footerTextColor, onRowClick = props.onRowClick, onContextMenu = props.onContextMenu, onCustomizeRowBgColor = props.onCustomizeRowBgColor;
|
21
|
-
var _f =
|
21
|
+
var _f = useGridVirtualizer(), tableRef = _f.tableRef, onProcessShadowVisible = _f.onProcessShadowVisible;
|
22
22
|
return (_jsx(TableContainer, __assign({ ref: tableRef, onScroll: onProcessShadowVisible, sx: {
|
23
23
|
maxHeight: "inherit",
|
24
24
|
borderWidth: "thin",
|
@@ -29,4 +29,4 @@ function TableCore(props) {
|
|
29
29
|
transition: "all 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms",
|
30
30
|
} }, { children: _jsxs(Table, __assign({ sx: { minWidth: 600, tableLayout: "fixed" }, size: dense ? "small" : "medium" }, { children: [_jsx(TableHeader, { headers: headers, headerBgColor: headerBgColor, headerTextColor: headerTextColor, noData: rows.length === 0 }), _jsx(TableBody, { rows: rows, columns: columns, noDataText: noDataText, onRowClick: onRowClick, onContextMenu: onContextMenu, onCustomizeRowBgColor: onCustomizeRowBgColor }), (footers === null || footers === void 0 ? void 0 : footers.length) > 0 ? (_jsx(TableFooter, { footers: footers, footerBgColor: footerBgColor, footerTextColor: footerTextColor, noData: rows.length === 0 })) : (_jsx(_Fragment, {}))] })) })));
|
31
31
|
}
|
32
|
-
export default
|
32
|
+
export default VirtualGridCore;
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import type { IGridVirtualizerContext, GridVirtualizerContextProviderProps } from "./types";
|
2
|
+
export declare function GridVirtualizerContextProvider<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>>(props: GridVirtualizerContextProviderProps<RowProps, ExtendedProps>): import("react/jsx-runtime").JSX.Element;
|
3
|
+
export declare const useGridVirtualizer: () => IGridVirtualizerContext;
|
@@ -11,18 +11,48 @@ var __assign = (this && this.__assign) || function () {
|
|
11
11
|
};
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
13
13
|
import { useRef, useState, useEffect, useContext, useCallback, createContext, } from "react";
|
14
|
-
import { useVirtualizer } from "@tanstack/react-virtual";
|
15
|
-
var
|
14
|
+
import { useVirtualizer, elementScroll } from "@tanstack/react-virtual";
|
15
|
+
var PI = 3.1415965359;
|
16
|
+
function easeInOutQuint(t) {
|
17
|
+
return t < 0.5
|
18
|
+
? 6 * PI * t * t * t * t * t
|
19
|
+
: 1 + 4 * PI * --t * t * t * t * t;
|
20
|
+
}
|
21
|
+
var GridVirtualizerContext = createContext({
|
16
22
|
tableRef: { current: null },
|
17
23
|
virtualRows: [],
|
18
24
|
leftShadowVisible: false,
|
19
25
|
rightShadowVisible: false,
|
26
|
+
getTotalSize: function () { return 0; },
|
20
27
|
onMeasureElement: function () { },
|
21
28
|
onProcessShadowVisible: function () { },
|
22
29
|
});
|
23
|
-
export function
|
30
|
+
export function GridVirtualizerContextProvider(props) {
|
24
31
|
var children = props.children, rows = props.rows, columns = props.columns, dense = props.dense;
|
25
32
|
var tableRef = useRef(null);
|
33
|
+
var scrollingRef = useRef();
|
34
|
+
var scrollToFn = useCallback(function (offset, canSmooth, instance) {
|
35
|
+
var _a;
|
36
|
+
var duration = 2000;
|
37
|
+
var start = ((_a = tableRef.current) === null || _a === void 0 ? void 0 : _a.scrollTop) || 0;
|
38
|
+
var startTime = (scrollingRef.current = Date.now());
|
39
|
+
var run = function () {
|
40
|
+
if (scrollingRef.current !== startTime)
|
41
|
+
return;
|
42
|
+
var now = Date.now();
|
43
|
+
var elapsed = now - startTime;
|
44
|
+
var progress = easeInOutQuint(Math.min(elapsed / duration, 1));
|
45
|
+
var interpolated = start + (offset - start) * progress;
|
46
|
+
if (elapsed < duration) {
|
47
|
+
elementScroll(interpolated, canSmooth, instance);
|
48
|
+
requestAnimationFrame(run);
|
49
|
+
}
|
50
|
+
else {
|
51
|
+
elementScroll(interpolated, canSmooth, instance);
|
52
|
+
}
|
53
|
+
};
|
54
|
+
requestAnimationFrame(run);
|
55
|
+
}, []);
|
26
56
|
var rowVirtualizer = useVirtualizer({
|
27
57
|
count: rows.length,
|
28
58
|
getScrollElement: function () { return tableRef.current; },
|
@@ -31,11 +61,12 @@ export function VirtualizerContextProvider(props) {
|
|
31
61
|
navigator.userAgent.indexOf("Firefox") === -1
|
32
62
|
? function (element) { return element === null || element === void 0 ? void 0 : element.getBoundingClientRect().height; }
|
33
63
|
: undefined,
|
34
|
-
overscan:
|
64
|
+
overscan: Math.round(rows.length / PI),
|
65
|
+
scrollToFn: scrollToFn,
|
35
66
|
});
|
36
67
|
var _a = useState(false), leftShadowVisible = _a[0], setLeftShadowVisible = _a[1];
|
37
68
|
var _b = useState(false), rightShadowVisible = _b[0], setRightShadowVisible = _b[1];
|
38
|
-
var measureElement = rowVirtualizer.measureElement, getVirtualItems = rowVirtualizer.getVirtualItems;
|
69
|
+
var measureElement = rowVirtualizer.measureElement, getVirtualItems = rowVirtualizer.getVirtualItems, getTotalSize = rowVirtualizer.getTotalSize;
|
39
70
|
var virtualRows = getVirtualItems();
|
40
71
|
var onProcessShadowVisible = useCallback(function () {
|
41
72
|
if (tableRef.current) {
|
@@ -59,15 +90,16 @@ export function VirtualizerContextProvider(props) {
|
|
59
90
|
useEffect(function () { return function () {
|
60
91
|
window.removeEventListener("scroll", onProcessShadowVisible);
|
61
92
|
}; }, [onProcessShadowVisible]);
|
62
|
-
return (_jsx(
|
93
|
+
return (_jsx(GridVirtualizerContext.Provider, __assign({ value: {
|
63
94
|
tableRef: tableRef,
|
64
95
|
virtualRows: virtualRows,
|
65
96
|
leftShadowVisible: leftShadowVisible,
|
66
97
|
rightShadowVisible: rightShadowVisible,
|
98
|
+
getTotalSize: getTotalSize,
|
67
99
|
onMeasureElement: measureElement,
|
68
100
|
onProcessShadowVisible: onProcessShadowVisible,
|
69
101
|
} }, { children: children })));
|
70
102
|
}
|
71
|
-
export var
|
72
|
-
return useContext(
|
103
|
+
export var useGridVirtualizer = function () {
|
104
|
+
return useContext(GridVirtualizerContext);
|
73
105
|
};
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import useVirtualGrid from "./useVirtualGrid";
|
2
|
+
import type { VirtualGridProps } from "./types";
|
3
|
+
declare function VirtualGrid<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>>(props: VirtualGridProps<RowProps, ExtendedProps>): import("react/jsx-runtime").JSX.Element;
|
4
|
+
export default VirtualGrid;
|
5
|
+
export * from "./types";
|
6
|
+
export { useVirtualGrid };
|
@@ -0,0 +1,36 @@
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
2
|
+
__assign = Object.assign || function(t) {
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
+
s = arguments[i];
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
+
t[p] = s[p];
|
7
|
+
}
|
8
|
+
return t;
|
9
|
+
};
|
10
|
+
return __assign.apply(this, arguments);
|
11
|
+
};
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
13
|
+
var t = {};
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
15
|
+
t[p] = s[p];
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
19
|
+
t[p[i]] = s[p[i]];
|
20
|
+
}
|
21
|
+
return t;
|
22
|
+
};
|
23
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
24
|
+
import ThemeProvider from "@mui/material/styles/ThemeProvider";
|
25
|
+
import useCustomTheme from "../useCustomTheme";
|
26
|
+
import useVirtualGrid from "./useVirtualGrid";
|
27
|
+
import VirtualGridCore from "./GridCore";
|
28
|
+
import { GridVirtualizerContextProvider } from "./GridVirtualizerContext";
|
29
|
+
function VirtualGrid(props) {
|
30
|
+
var primaryColor = props.primaryColor, secondaryColor = props.secondaryColor, rows = props.rows, columns = props.columns, dense = props.dense, rest = __rest(props, ["primaryColor", "secondaryColor", "rows", "columns", "dense"]);
|
31
|
+
var theme = useCustomTheme({ primaryColor: primaryColor, secondaryColor: secondaryColor });
|
32
|
+
return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsx(GridVirtualizerContextProvider, __assign({ rows: rows, columns: columns, dense: dense }, { children: _jsx(VirtualGridCore, __assign({}, rest, { rows: rows, columns: columns, dense: dense })) })) })));
|
33
|
+
}
|
34
|
+
export default VirtualGrid;
|
35
|
+
export * from "./types";
|
36
|
+
export { useVirtualGrid };
|
@@ -0,0 +1,104 @@
|
|
1
|
+
import type { ReactNode, RefObject, MouseEvent, ReactElement, CSSProperties } from "react";
|
2
|
+
import type { VirtualItem } from "@tanstack/react-virtual";
|
3
|
+
declare type HexColor = `#${string}`;
|
4
|
+
export declare type CustomVirtualGridRowBgColor = {
|
5
|
+
normal?: HexColor;
|
6
|
+
hover?: HexColor;
|
7
|
+
};
|
8
|
+
export declare type VirtualGridOrderType = "ASC" | "DESC" | "NONE";
|
9
|
+
export declare type VirtualGridSortingProps = {
|
10
|
+
accessor: string;
|
11
|
+
order: VirtualGridOrderType;
|
12
|
+
};
|
13
|
+
declare type InitialVirtualGridStateProps = {
|
14
|
+
sortBy?: VirtualGridSortingProps;
|
15
|
+
};
|
16
|
+
export declare type VirtualGridColumnProps = {
|
17
|
+
headerTip?: string;
|
18
|
+
Header: ReactElement;
|
19
|
+
Body: ReactElement;
|
20
|
+
Footer?: ReactElement;
|
21
|
+
align?: "left" | "center" | "right";
|
22
|
+
accessor: string;
|
23
|
+
sortable?: boolean;
|
24
|
+
fixable?: "left" | "right";
|
25
|
+
width: number;
|
26
|
+
};
|
27
|
+
export declare type UseVirtualGridBaseProps<RowProps extends Record<string, any>> = {
|
28
|
+
data: Array<RowProps>;
|
29
|
+
columns: Array<VirtualGridColumnProps>;
|
30
|
+
initialState?: InitialVirtualGridStateProps;
|
31
|
+
disableSortBy?: boolean;
|
32
|
+
onSort?: (props: VirtualGridSortingProps) => unknown;
|
33
|
+
};
|
34
|
+
export declare type UseVirtualGridProps<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>> = UseVirtualGridBaseProps<RowProps> & ExtendedProps;
|
35
|
+
export declare type VirtualGridHeaderCellProps<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>> = Pick<VirtualGridColumnProps, "align" | "accessor" | "fixable" | "width"> & Omit<UseVirtualGridProps<RowProps, ExtendedProps>, keyof UseVirtualGridBaseProps<RowProps>> & {
|
36
|
+
Cell: ReactElement;
|
37
|
+
title: string;
|
38
|
+
onSort: ({ accessor, }: Pick<VirtualGridSortingProps, "accessor">) => unknown;
|
39
|
+
};
|
40
|
+
export declare type VirtualGridBodyCellProps<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>> = Pick<VirtualGridColumnProps, "align" | "accessor" | "fixable" | "width"> & Omit<UseVirtualGridProps<RowProps, ExtendedProps>, keyof UseVirtualGridBaseProps<RowProps>> & {
|
41
|
+
Cell: ReactElement;
|
42
|
+
};
|
43
|
+
export declare type VirtualGridFooterCellProps<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>> = Pick<VirtualGridColumnProps, "align" | "accessor" | "fixable" | "width"> & Omit<UseVirtualGridProps<RowProps, ExtendedProps>, keyof UseVirtualGridBaseProps<RowProps>> & {
|
44
|
+
Cell: ReactElement;
|
45
|
+
};
|
46
|
+
export declare type UseVirtualGridReturns<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>> = {
|
47
|
+
headers: Array<VirtualGridHeaderCellProps<RowProps, ExtendedProps>>;
|
48
|
+
footers: Array<VirtualGridFooterCellProps<RowProps, ExtendedProps>>;
|
49
|
+
columns: Array<VirtualGridBodyCellProps<RowProps, ExtendedProps>>;
|
50
|
+
rows: Array<RowProps>;
|
51
|
+
onResetSorting: () => void;
|
52
|
+
};
|
53
|
+
export declare type VirtualGridHeaderProps<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>> = {
|
54
|
+
headers: Array<VirtualGridHeaderCellProps<RowProps, ExtendedProps>>;
|
55
|
+
headerBgColor?: CSSProperties["color"];
|
56
|
+
headerTextColor?: CSSProperties["color"];
|
57
|
+
noData?: boolean;
|
58
|
+
};
|
59
|
+
export declare type VirtualGridBodyProps<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>> = {
|
60
|
+
columns: Array<VirtualGridBodyCellProps<RowProps, ExtendedProps>>;
|
61
|
+
rows: Array<RowProps>;
|
62
|
+
noDataText?: string;
|
63
|
+
onRowClick?: (row: RowProps) => unknown;
|
64
|
+
onContextMenu?: (event: MouseEvent<HTMLTableRowElement>, row: RowProps) => unknown;
|
65
|
+
onCustomizeRowBgColor?: ({ row, columns, }: {
|
66
|
+
row: RowProps;
|
67
|
+
columns: Array<VirtualGridBodyCellProps<RowProps, ExtendedProps>>;
|
68
|
+
}) => CustomVirtualGridRowBgColor;
|
69
|
+
};
|
70
|
+
export declare type VirtualGridBodyRowProps<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>> = Omit<VirtualGridBodyProps<RowProps, ExtendedProps>, "noDataText"> & {
|
71
|
+
rowIndex: number;
|
72
|
+
virtualRow: VirtualItem;
|
73
|
+
};
|
74
|
+
export declare type VirtualGridFooterProps<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>> = {
|
75
|
+
footers?: Array<VirtualGridFooterCellProps<RowProps, ExtendedProps>>;
|
76
|
+
footerBgColor?: CSSProperties["color"];
|
77
|
+
footerTextColor?: CSSProperties["color"];
|
78
|
+
noData?: boolean;
|
79
|
+
};
|
80
|
+
export declare type VirtualGridCoreProps<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>> = Omit<VirtualGridHeaderProps<RowProps, ExtendedProps>, "noData"> & VirtualGridBodyProps<RowProps, ExtendedProps> & Omit<VirtualGridFooterProps<RowProps, ExtendedProps>, "noData"> & {
|
81
|
+
dense?: boolean;
|
82
|
+
primaryColor?: CSSProperties["color"];
|
83
|
+
secondaryColor?: CSSProperties["color"];
|
84
|
+
};
|
85
|
+
export declare type VirtualGridProps<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>> = VirtualGridCoreProps<RowProps, ExtendedProps> & {
|
86
|
+
primaryColor?: CSSProperties["color"];
|
87
|
+
secondaryColor?: CSSProperties["color"];
|
88
|
+
};
|
89
|
+
export interface GridVirtualizerContextProviderProps<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>> {
|
90
|
+
dense?: boolean;
|
91
|
+
children: ReactNode;
|
92
|
+
rows: Array<RowProps>;
|
93
|
+
columns: Array<VirtualGridBodyCellProps<RowProps, ExtendedProps>>;
|
94
|
+
}
|
95
|
+
export interface IGridVirtualizerContext {
|
96
|
+
tableRef: RefObject<HTMLDivElement>;
|
97
|
+
virtualRows: Array<VirtualItem>;
|
98
|
+
leftShadowVisible: boolean;
|
99
|
+
rightShadowVisible: boolean;
|
100
|
+
getTotalSize: () => number;
|
101
|
+
onMeasureElement: (node: Element | null | undefined) => void;
|
102
|
+
onProcessShadowVisible: () => void;
|
103
|
+
}
|
104
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,103 @@
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
2
|
+
__assign = Object.assign || function(t) {
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
+
s = arguments[i];
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
+
t[p] = s[p];
|
7
|
+
}
|
8
|
+
return t;
|
9
|
+
};
|
10
|
+
return __assign.apply(this, arguments);
|
11
|
+
};
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
13
|
+
var t = {};
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
15
|
+
t[p] = s[p];
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
19
|
+
t[p[i]] = s[p[i]];
|
20
|
+
}
|
21
|
+
return t;
|
22
|
+
};
|
23
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
24
|
+
import { cloneElement, useState, useMemo, useCallback } from "react";
|
25
|
+
function useVirtualGrid(props) {
|
26
|
+
var data = props.data, columns = props.columns, initialState = props.initialState, disableSortBy = props.disableSortBy, onSort = props.onSort, rest = __rest(props, ["data", "columns", "initialState", "disableSortBy", "onSort"]);
|
27
|
+
if (!data) {
|
28
|
+
throw new Error('"data" is required but got null or undefined');
|
29
|
+
}
|
30
|
+
if (!columns) {
|
31
|
+
throw new Error('"columns" is required but got null or undefined');
|
32
|
+
}
|
33
|
+
var initialSortingProps = useMemo(function () {
|
34
|
+
var sortBy = (initialState || {}).sortBy;
|
35
|
+
var _a = sortBy || {}, accessor = _a.accessor, order = _a.order;
|
36
|
+
return {
|
37
|
+
accessor: accessor || "",
|
38
|
+
order: !!accessor ? order || "NONE" : "NONE",
|
39
|
+
};
|
40
|
+
}, [initialState]);
|
41
|
+
var _a = useState(initialSortingProps), sortingProps = _a[0], setSortingProps = _a[1];
|
42
|
+
var handleSort = useCallback(function (_a) {
|
43
|
+
var accessor = _a.accessor;
|
44
|
+
if (!disableSortBy) {
|
45
|
+
var newSortingProps = __assign({}, sortingProps);
|
46
|
+
if (accessor !== sortingProps.accessor ||
|
47
|
+
sortingProps.order === "NONE") {
|
48
|
+
newSortingProps = { accessor: accessor, order: "ASC" };
|
49
|
+
}
|
50
|
+
else if (sortingProps.order === "ASC") {
|
51
|
+
newSortingProps = __assign(__assign({}, sortingProps), { order: "DESC" });
|
52
|
+
}
|
53
|
+
else {
|
54
|
+
newSortingProps = __assign(__assign({}, sortingProps), { order: "NONE" });
|
55
|
+
}
|
56
|
+
if (onSort) {
|
57
|
+
onSort(__assign({}, newSortingProps));
|
58
|
+
}
|
59
|
+
setSortingProps(__assign({}, newSortingProps));
|
60
|
+
}
|
61
|
+
}, [disableSortBy, onSort, sortingProps]);
|
62
|
+
var onResetSorting = useCallback(function () {
|
63
|
+
if (onSort) {
|
64
|
+
onSort(__assign({}, initialSortingProps));
|
65
|
+
}
|
66
|
+
setSortingProps(__assign({}, initialSortingProps));
|
67
|
+
}, [initialSortingProps, onSort]);
|
68
|
+
var renderSortingSymbol = useCallback(function (accessor) {
|
69
|
+
var field = sortingProps.accessor, order = sortingProps.order;
|
70
|
+
if (accessor !== field || order === "NONE") {
|
71
|
+
return "";
|
72
|
+
}
|
73
|
+
if (order === "ASC") {
|
74
|
+
return "↑";
|
75
|
+
}
|
76
|
+
return "↓";
|
77
|
+
}, [sortingProps]);
|
78
|
+
var rows = useMemo(function () { return data.map(function (d) { return d; }); }, [data]);
|
79
|
+
var cols = useMemo(function () {
|
80
|
+
return columns.map(function (col) {
|
81
|
+
var Body = col.Body;
|
82
|
+
return __assign(__assign({ Cell: cloneElement(Body || _jsx(_Fragment, {}), { column: col }) }, col), rest);
|
83
|
+
});
|
84
|
+
}, [columns, rest]);
|
85
|
+
var headers = useMemo(function () {
|
86
|
+
return columns.map(function (col) {
|
87
|
+
var Header = col.Header, accessor = col.accessor, sortable = col.sortable, headerTip = col.headerTip;
|
88
|
+
var canSortBy = sortable && !disableSortBy;
|
89
|
+
return __assign(__assign({ Cell: (_jsxs(_Fragment, { children: [cloneElement(Header || _jsx(_Fragment, {}), { column: col }), canSortBy && renderSortingSymbol(accessor)] })), title: "".concat(headerTip || "").concat(canSortBy ? " (Click to sort)" : ""), sortable: canSortBy, onSort: canSortBy ? handleSort : function () { } }, col), rest);
|
90
|
+
});
|
91
|
+
}, [columns, disableSortBy, handleSort, renderSortingSymbol, rest]);
|
92
|
+
var footers = useMemo(function () {
|
93
|
+
return columns.map(function (col) {
|
94
|
+
var Footer = col.Footer;
|
95
|
+
return __assign(__assign({ Cell: cloneElement(Footer || _jsx(_Fragment, {}), {
|
96
|
+
column: col,
|
97
|
+
rows: rows,
|
98
|
+
}) }, col), rest);
|
99
|
+
});
|
100
|
+
}, [columns, rest, rows]);
|
101
|
+
return { headers: headers, footers: footers, columns: cols, rows: rows, onResetSorting: onResetSorting };
|
102
|
+
}
|
103
|
+
export default useVirtualGrid;
|
package/index.d.ts
CHANGED
@@ -29,6 +29,7 @@ export * from "./TablePagination";
|
|
29
29
|
export * from "./TextInput";
|
30
30
|
export * from "./ToastPrompt";
|
31
31
|
export * from "./VideoPlayerModal";
|
32
|
+
export * from "./VirtualGrid";
|
32
33
|
export { default as AlertDialog } from "./AlertDialog";
|
33
34
|
export { default as Autocomplete } from "./Autocomplete";
|
34
35
|
export { default as AutocompleteWithFilter } from "./AutocompleteWithFilter";
|
@@ -57,3 +58,4 @@ export { default as TabGroup } from "./TabGroup";
|
|
57
58
|
export { default as TablePagination } from "./TablePagination";
|
58
59
|
export { default as TextInput } from "./TextInput";
|
59
60
|
export { default as VideoPlayerModal } from "./VideoPlayerModal";
|
61
|
+
export { default as VirtualGrid } from "./VirtualGrid";
|
package/index.js
CHANGED
@@ -29,6 +29,7 @@ export * from "./TablePagination";
|
|
29
29
|
export * from "./TextInput";
|
30
30
|
export * from "./ToastPrompt";
|
31
31
|
export * from "./VideoPlayerModal";
|
32
|
+
export * from "./VirtualGrid";
|
32
33
|
export { default as AlertDialog } from "./AlertDialog";
|
33
34
|
export { default as Autocomplete } from "./Autocomplete";
|
34
35
|
export { default as AutocompleteWithFilter } from "./AutocompleteWithFilter";
|
@@ -57,3 +58,4 @@ export { default as TabGroup } from "./TabGroup";
|
|
57
58
|
export { default as TablePagination } from "./TablePagination";
|
58
59
|
export { default as TextInput } from "./TextInput";
|
59
60
|
export { default as VideoPlayerModal } from "./VideoPlayerModal";
|
61
|
+
export { default as VirtualGrid } from "./VirtualGrid";
|