@symply.io/basic-components 1.7.0-alpha.5 → 1.7.0-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/README.md +21 -38
- package/VirtualDataTable/index.js +16 -11
- package/index.d.ts +0 -2
- package/index.js +0 -2
- package/package.json +1 -2
- package/VirtualGrid/GridCore/GridBody.d.ts +0 -4
- package/VirtualGrid/GridCore/GridBody.js +0 -37
- package/VirtualGrid/GridCore/GridBodyRow.d.ts +0 -4
- package/VirtualGrid/GridCore/GridBodyRow.js +0 -144
- package/VirtualGrid/GridCore/GridFooter.d.ts +0 -4
- package/VirtualGrid/GridCore/GridFooter.js +0 -109
- package/VirtualGrid/GridCore/GridHeader.d.ts +0 -4
- package/VirtualGrid/GridCore/GridHeader.js +0 -114
- package/VirtualGrid/GridCore/index.d.ts +0 -4
- package/VirtualGrid/GridCore/index.js +0 -34
- package/VirtualGrid/GridVirtualizerContext.d.ts +0 -3
- package/VirtualGrid/GridVirtualizerContext.js +0 -108
- package/VirtualGrid/index.d.ts +0 -6
- package/VirtualGrid/index.js +0 -36
- package/VirtualGrid/types.d.ts +0 -104
- package/VirtualGrid/types.js +0 -1
- package/VirtualGrid/useVirtualGrid.d.ts +0 -3
- package/VirtualGrid/useVirtualGrid.js +0 -103
package/README.md
CHANGED
@@ -968,16 +968,16 @@ import VideoPlayerModal from '@symply.io/basic-components/VideoPlayerModal';
|
|
968
968
|
|
969
969
|
|
970
970
|
|
971
|
-
<h3>
|
971
|
+
<h3>VirtualDataTable</h3>
|
972
972
|
|
973
|
-
Reusable data
|
973
|
+
Reusable data table component with virtualizer
|
974
974
|
|
975
975
|
<h5>Import</h5>
|
976
976
|
|
977
977
|
```tsx
|
978
|
-
import {
|
978
|
+
import { VirtualDataTablev } from '@symply.io/basic-components';
|
979
979
|
// or
|
980
|
-
import
|
980
|
+
import VirtualDataTable, { useVirtualGird } from '@symply.io/basic-components/VirtualDataTable';
|
981
981
|
```
|
982
982
|
|
983
983
|
<h5>Column Props</h5>
|
@@ -1001,43 +1001,26 @@ import VirtualGird, { useVirtualGird } from '@symply.io/basic-components/Virtual
|
|
1001
1001
|
| accessor | string | | true | The key of the column. |
|
1002
1002
|
| order | "ASC" \| "DESC" \| "NONE" | | true | The sorting order. |
|
1003
1003
|
|
1004
|
-
<h5>Hook Props</h5>
|
1005
|
-
|
1006
|
-
| Name | Type | Default | Required | Description |
|
1007
|
-
| ------------- | -------------------------- | ------- | -------- | ------------------------------------------------------------ |
|
1008
|
-
| columns | Array | | true | table columns |
|
1009
|
-
| data | Array<{ [name]: unknown }> | | true | table data/rows |
|
1010
|
-
| disableSortBy | bool | | false | If true, the whole table can't be sortable. |
|
1011
|
-
| initialState | { sortBy?: SortingProps} | | false | Set the initial states |
|
1012
|
-
| onSort | func | | false | The function for sorting rows.<br />**Signature:**<br/>`function(props: SortingProps) => unknown` |
|
1013
|
-
|
1014
|
-
<h5>Hook Returns</h5>
|
1015
|
-
|
1016
|
-
| Name | Type | Description |
|
1017
|
-
| -------------- | ----- | ------------------------------------------------------------ |
|
1018
|
-
| columns | Array | The cells for the body. |
|
1019
|
-
| footers | Array | The cells for the footer. |
|
1020
|
-
| headers | Array | The cells for the header. |
|
1021
|
-
| rows | Array | The rows for the table. |
|
1022
|
-
| onResetSorting | func | An one-key function for resetting sorting to the initial state. |
|
1023
1004
|
|
1024
1005
|
<h5>Component Props</h5>
|
1025
1006
|
|
1026
|
-
| Name | Type
|
1027
|
-
| --------------------- |
|
1028
|
-
| columns | Array
|
1029
|
-
| dense | bool
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
| noDataText | string
|
1037
|
-
| onContextMenu | func
|
1038
|
-
| onCustomizeRowBgColor | func
|
1039
|
-
| onRowClick | func
|
1040
|
-
|
|
1007
|
+
| Name | Type | Default | Required | Description |
|
1008
|
+
| --------------------- | -------------------------- | ---------- | -------- | ------------------------------------------------------------ |
|
1009
|
+
| columns | Array | [] | true | Table columns |
|
1010
|
+
| dense | bool | | false | If `true` the table size/density would be tight. |
|
1011
|
+
| footerBgColor | CSSProperties["color"] | | false | Customized footer background color. |
|
1012
|
+
| footerTextColor | CSSProperties["color"] | | false | Customized footer text color. |
|
1013
|
+
| | | | | |
|
1014
|
+
| headerBgColor | CSSProperties["color"] | | false | Customized header background color. |
|
1015
|
+
| headerTextColor | CSSProperties["color"] | | false | Customized header text color. |
|
1016
|
+
| initialState | { sortBy?: SortingProps} | | false | Set the initial states |
|
1017
|
+
| noDataText | string | 'No Data!' | false | The text when no data rendered. |
|
1018
|
+
| onContextMenu | func | | false | The function for row right-clicking.<br />**Signature:**<br/>`function(event: MouseEvent, row: RowProps) => unknown` |
|
1019
|
+
| onCustomizeRowBgColor | func | | false | The function for customizing the row background color.<br />**Signature:**<br/>`function(props: {row: RowProps, columns: Array\<ColumnProps\>}) => {normal?: HexColor;<br/> hover?: HexColor;<br/>}` |
|
1020
|
+
| onRowClick | func | | false | The function for row clicking.<br />**Signature:**<br/>`function(row: RowProps) => unknown` |
|
1021
|
+
| onSort | func | | false | The function for sorting rows.<br />**Signature:**<br/>`function(props: SortingProps) => unknown` |
|
1022
|
+
| rows | Array<{ [name]: unknown }> | | true | table data/rows |
|
1023
|
+
| sortingDisabled | bool | | false | If true, the whole table can't be sortable. |
|
1041
1024
|
|
1042
1025
|
|
1043
1026
|
|
@@ -23,7 +23,7 @@ import Typography from "@mui/material/Typography";
|
|
23
23
|
import useInteractions from "./useInteractions";
|
24
24
|
var VirtualDataTable = function (props, ref) {
|
25
25
|
var rows = props.rows, columns = props.columns, dense = props.dense, height = props.height, _a = props.noDataText, noDataText = _a === void 0 ? "No Data" : _a, headerBgColor = props.headerBgColor, headerTextColor = props.headerTextColor, footerBgColor = props.footerBgColor, footerTextColor = props.footerTextColor, sortingDisabled = props.sortingDisabled, options = props.options, initialState = props.initialState, onSort = props.onSort, onRowClick = props.onRowClick, onContextMenu = props.onContextMenu, onCustomizeRowBgColor = props.onCustomizeRowBgColor;
|
26
|
-
var _b = useState(),
|
26
|
+
var _b = useState(null), rowDataIndex = _b[0], setRowDataIndex = _b[1];
|
27
27
|
var _c = useInteractions({ rows: rows, columns: columns, initialState: initialState, sortingDisabled: sortingDisabled, onSort: onSort }), normalCols = _c.normalCols, pinnedLeftCols = _c.pinnedLeftCols, pinnedRightCols = _c.pinnedRightCols, leftShadowVisible = _c.leftShadowVisible, rightShadowVisible = _c.rightShadowVisible, onScroll = _c.onScroll, handleSort = _c.handleSort, onResetSorting = _c.onResetSorting, renderSortingSymbol = _c.renderSortingSymbol;
|
28
28
|
useImperativeHandle(ref, function () { return ({
|
29
29
|
onResetSorting: onResetSorting,
|
@@ -224,8 +224,9 @@ var VirtualDataTable = function (props, ref) {
|
|
224
224
|
left: left,
|
225
225
|
zIndex: 1,
|
226
226
|
width: width,
|
227
|
-
backgroundColor: (onRowClick &&
|
228
|
-
|
227
|
+
backgroundColor: (onRowClick && rowDataIndex === rowIndex
|
228
|
+
? hover
|
229
|
+
: normal) || "background.paper",
|
229
230
|
"&::after": index === pinnedLeftCols.length - 1 && leftShadowVisible
|
230
231
|
? {
|
231
232
|
position: "absolute",
|
@@ -244,8 +245,9 @@ var VirtualDataTable = function (props, ref) {
|
|
244
245
|
var align = column.align, width = column.width, Body = column.Body, accessor = column.accessor;
|
245
246
|
return (_jsx(TableCell, __assign({ variant: "footer", align: align, sx: {
|
246
247
|
width: width,
|
247
|
-
backgroundColor: (onRowClick &&
|
248
|
-
|
248
|
+
backgroundColor: (onRowClick && rowDataIndex === rowIndex
|
249
|
+
? hover
|
250
|
+
: normal) || "background.paper",
|
249
251
|
} }, { children: cloneElement(Body, { column: column, row: row, rows: rows, rowIndex: rowIndex, options: options }) }), accessor));
|
250
252
|
}), pinnedRightCols.map(function (column, index) {
|
251
253
|
var align = column.align, width = column.width, Body = column.Body, accessor = column.accessor;
|
@@ -257,8 +259,9 @@ var VirtualDataTable = function (props, ref) {
|
|
257
259
|
right: right,
|
258
260
|
zIndex: 1,
|
259
261
|
width: width,
|
260
|
-
backgroundColor: (onRowClick &&
|
261
|
-
|
262
|
+
backgroundColor: (onRowClick && rowDataIndex === rowIndex
|
263
|
+
? hover
|
264
|
+
: normal) || "background.paper",
|
262
265
|
"&::after": index === 0 && rightShadowVisible
|
263
266
|
? {
|
264
267
|
position: "absolute",
|
@@ -276,11 +279,13 @@ var VirtualDataTable = function (props, ref) {
|
|
276
279
|
})] }));
|
277
280
|
}, [
|
278
281
|
rows,
|
282
|
+
rowDataIndex,
|
279
283
|
normalCols,
|
280
284
|
pinnedLeftCols,
|
281
285
|
pinnedRightCols,
|
282
286
|
leftShadowVisible,
|
283
287
|
rightShadowVisible,
|
288
|
+
handleCustomizeRowBgColor,
|
284
289
|
]);
|
285
290
|
var VirtuosoTableComponents = useMemo(function () { return ({
|
286
291
|
EmptyPlaceholder: function () { return (_jsx(TableRow, { children: _jsx(TableCell, __assign({ colSpan: columns.length }, { children: _jsx(Typography, __assign({ align: "center", variant: "body1", fontSize: 14, fontWeight: 600 }, { children: noDataText })) })) })); },
|
@@ -307,10 +312,10 @@ var VirtualDataTable = function (props, ref) {
|
|
307
312
|
cursor: onRowClick ? "pointer" : "default",
|
308
313
|
backgroundColor: onRowClick ? hover : normal,
|
309
314
|
},
|
310
|
-
}, onMouseEnter: function (
|
311
|
-
|
315
|
+
}, onMouseEnter: function () {
|
316
|
+
setRowDataIndex(props["data-index"] || props["data-item-index"]);
|
312
317
|
}, onMouseLeave: function () {
|
313
|
-
|
318
|
+
setRowDataIndex(null);
|
314
319
|
}, onClick: onRowClick
|
315
320
|
? function () {
|
316
321
|
onRowClick(props.item);
|
@@ -324,7 +329,7 @@ var VirtualDataTable = function (props, ref) {
|
|
324
329
|
},
|
325
330
|
TableBody: forwardRef(function (props, ref) { return (_jsx(TableBody, __assign({}, props, { ref: ref }))); }),
|
326
331
|
TableFoot: forwardRef(function (props, ref) { return (_jsx(TableFooter, __assign({}, props, { ref: ref }))); }),
|
327
|
-
}); }, [onRowClick, onContextMenu,
|
332
|
+
}); }, [onRowClick, onContextMenu, handleCustomizeRowBgColor]);
|
328
333
|
return (_jsx(TableVirtuoso, { data: rows, style: { height: height }, onResize: onScroll, onScroll: onScroll, components: VirtuosoTableComponents, fixedHeaderContent: fixedHeaderContent, fixedFooterContent: fixedFooterContent, itemContent: itemContent, followOutput: "smooth", increaseViewportBy: 5 }));
|
329
334
|
};
|
330
335
|
export default forwardRef(VirtualDataTable);
|
package/index.d.ts
CHANGED
@@ -30,7 +30,6 @@ export * from "./TextInput";
|
|
30
30
|
export * from "./ToastPrompt";
|
31
31
|
export * from "./VideoPlayerModal";
|
32
32
|
export * from "./VirtualDataTable";
|
33
|
-
export * from "./VirtualGrid";
|
34
33
|
export { default as AlertDialog } from "./AlertDialog";
|
35
34
|
export { default as Autocomplete } from "./Autocomplete";
|
36
35
|
export { default as AutocompleteWithFilter } from "./AutocompleteWithFilter";
|
@@ -60,4 +59,3 @@ export { default as TablePagination } from "./TablePagination";
|
|
60
59
|
export { default as TextInput } from "./TextInput";
|
61
60
|
export { default as VideoPlayerModal } from "./VideoPlayerModal";
|
62
61
|
export { default as VirtualDataTable } from "./VirtualDataTable";
|
63
|
-
export { default as VirtualGrid } from "./VirtualGrid";
|
package/index.js
CHANGED
@@ -30,7 +30,6 @@ export * from "./TextInput";
|
|
30
30
|
export * from "./ToastPrompt";
|
31
31
|
export * from "./VideoPlayerModal";
|
32
32
|
export * from "./VirtualDataTable";
|
33
|
-
export * from "./VirtualGrid";
|
34
33
|
export { default as AlertDialog } from "./AlertDialog";
|
35
34
|
export { default as Autocomplete } from "./Autocomplete";
|
36
35
|
export { default as AutocompleteWithFilter } from "./AutocompleteWithFilter";
|
@@ -60,4 +59,3 @@ export { default as TablePagination } from "./TablePagination";
|
|
60
59
|
export { default as TextInput } from "./TextInput";
|
61
60
|
export { default as VideoPlayerModal } from "./VideoPlayerModal";
|
62
61
|
export { default as VirtualDataTable } from "./VirtualDataTable";
|
63
|
-
export { default as VirtualGrid } from "./VirtualGrid";
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@symply.io/basic-components",
|
3
|
-
"version": "1.7.0-
|
3
|
+
"version": "1.7.0-beta.1",
|
4
4
|
"description": "Basic and reusable components for all frontend of Symply apps",
|
5
5
|
"keywords": [
|
6
6
|
"react",
|
@@ -56,7 +56,6 @@
|
|
56
56
|
"@mui/material": "5.11.0",
|
57
57
|
"@mui/system": "5.11.0",
|
58
58
|
"@reach/router": "^1.3.4",
|
59
|
-
"@tanstack/react-virtual": "^3.10.8",
|
60
59
|
"color-alpha": "^1.1.3",
|
61
60
|
"react-dropzone": "14.2.3",
|
62
61
|
"react-player": "2.11.0",
|
@@ -1,4 +0,0 @@
|
|
1
|
-
import type { VirtualGridBodyProps } from "../types";
|
2
|
-
declare function VirtualGridBody<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>>(props: VirtualGridBodyProps<RowProps, ExtendedProps>): import("react/jsx-runtime").JSX.Element;
|
3
|
-
declare const _default: typeof VirtualGridBody;
|
4
|
-
export default _default;
|
@@ -1,37 +0,0 @@
|
|
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 { memo } from "react";
|
25
|
-
import TableRow from "@mui/material/TableRow";
|
26
|
-
import TableBody from "@mui/material/TableBody";
|
27
|
-
import TableCell from "@mui/material/TableCell";
|
28
|
-
import GridBodyRow from "./GridBodyRow";
|
29
|
-
import { useGridVirtualizer } from "../GridVirtualizerContext";
|
30
|
-
function VirtualGridBody(props) {
|
31
|
-
var rows = props.rows, columns = props.columns, _a = props.noDataText, noDataText = _a === void 0 ? "No Data!" : _a, rest = __rest(props, ["rows", "columns", "noDataText"]);
|
32
|
-
var virtualRows = useGridVirtualizer().virtualRows;
|
33
|
-
return (_jsx(TableBody, { children: virtualRows.length > 0 ? (virtualRows.map(function (virtualRow, index) {
|
34
|
-
return (_jsx(GridBodyRow, __assign({ rowIndex: index, virtualRow: virtualRow, rows: rows, columns: columns }, rest), "Virtual_Grid_Body_Row_".concat(virtualRow.key)));
|
35
|
-
})) : (_jsx(TableRow, { children: _jsx(TableCell, __assign({ colSpan: columns.length, align: "center" }, { children: noDataText })) })) }));
|
36
|
-
}
|
37
|
-
export default memo(VirtualGridBody);
|
@@ -1,4 +0,0 @@
|
|
1
|
-
import type { VirtualGridBodyRowProps } from "../types";
|
2
|
-
declare function VirtualGridBodyRow<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>>(props: VirtualGridBodyRowProps<RowProps, ExtendedProps>): import("react/jsx-runtime").JSX.Element;
|
3
|
-
declare const _default: typeof VirtualGridBodyRow;
|
4
|
-
export default _default;
|
@@ -1,144 +0,0 @@
|
|
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, useState, useMemo } from "react";
|
14
|
-
import TableRow from "@mui/material/TableRow";
|
15
|
-
import TableCell from "@mui/material/TableCell";
|
16
|
-
import useMediaQuery from "@mui/material/useMediaQuery";
|
17
|
-
import useTheme from "@mui/material/styles/useTheme";
|
18
|
-
import { useGridVirtualizer } from "../GridVirtualizerContext";
|
19
|
-
function VirtualGridBodyRow(props) {
|
20
|
-
var rows = props.rows, columns = props.columns, rowIndex = props.rowIndex, virtualRow = props.virtualRow, onRowClick = props.onRowClick, onContextMenu = props.onContextMenu, onCustomizeRowBgColor = props.onCustomizeRowBgColor;
|
21
|
-
var theme = useTheme();
|
22
|
-
var isUpMd = useMediaQuery(theme.breakpoints.up("md"));
|
23
|
-
var _a = useGridVirtualizer(), leftShadowVisible = _a.leftShadowVisible, rightShadowVisible = _a.rightShadowVisible, onMeasureElement = _a.onMeasureElement;
|
24
|
-
var row = useMemo(function () { return rows[virtualRow.index]; }, [rows, virtualRow]);
|
25
|
-
var _b = useMemo(function () {
|
26
|
-
if (isUpMd) {
|
27
|
-
var left = columns.filter(function (c) { return c.fixable === "left"; });
|
28
|
-
var right = columns.filter(function (c) { return c.fixable === "right"; });
|
29
|
-
var dynamic = columns.filter(function (c) { return !c.fixable; });
|
30
|
-
return [left, dynamic, right];
|
31
|
-
}
|
32
|
-
else {
|
33
|
-
return [[], columns, []];
|
34
|
-
}
|
35
|
-
}, [isUpMd, columns]), fixedLeftCols = _b[0], dynamicCols = _b[1], fixedRightCols = _b[2];
|
36
|
-
var _c = useMemo(function () {
|
37
|
-
if (onCustomizeRowBgColor) {
|
38
|
-
var regex = /^#(\d|[a-f]|[A-F]){6}/i;
|
39
|
-
var _a = onCustomizeRowBgColor({ row: row, columns: columns }), normal_1 = _a.normal, hover_1 = _a.hover;
|
40
|
-
return {
|
41
|
-
normal: normal_1 && regex.test(normal_1) ? normal_1 : "#FEFEFE",
|
42
|
-
hover: hover_1 && regex.test(hover_1) ? hover_1 : "#F2F1F3",
|
43
|
-
};
|
44
|
-
}
|
45
|
-
return { normal: "#FEFEFE", hover: "#F2F1F3" };
|
46
|
-
}, [row, columns, onCustomizeRowBgColor]), normal = _c.normal, hover = _c.hover;
|
47
|
-
var _d = useState(), rowEl = _d[0], setRowEl = _d[1];
|
48
|
-
return (_jsxs(TableRow, __assign({ sx: {
|
49
|
-
backgroundColor: normal,
|
50
|
-
width: "100%",
|
51
|
-
height: "".concat(virtualRow.size, "px"),
|
52
|
-
transform: "translateY(".concat(virtualRow.start - rowIndex * virtualRow.size, "px)"),
|
53
|
-
"&:hover": {
|
54
|
-
cursor: onRowClick ? "pointer" : "default",
|
55
|
-
backgroundColor: onRowClick ? hover : normal,
|
56
|
-
},
|
57
|
-
}, "data-index": virtualRow.index, onMouseEnter: function (event) {
|
58
|
-
setRowEl(event.currentTarget);
|
59
|
-
}, onMouseLeave: function () {
|
60
|
-
setRowEl(undefined);
|
61
|
-
}, onClick: onRowClick
|
62
|
-
? function () {
|
63
|
-
onRowClick(row);
|
64
|
-
}
|
65
|
-
: undefined, onContextMenu: function (event) {
|
66
|
-
event.preventDefault();
|
67
|
-
if (onContextMenu) {
|
68
|
-
onContextMenu(event, row);
|
69
|
-
}
|
70
|
-
} }, { children: [fixedLeftCols.map(function (col, index) {
|
71
|
-
var accessor = col.accessor, Cell = col.Cell, width = col.width, _a = col.align, align = _a === void 0 ? "center" : _a;
|
72
|
-
var left = fixedLeftCols
|
73
|
-
.slice(0, index)
|
74
|
-
.reduce(function (w, t) { return w + (t.width || 0); }, 0);
|
75
|
-
return (_jsx(TableCell, __assign({ align: align, sx: {
|
76
|
-
left: left,
|
77
|
-
zIndex: 10,
|
78
|
-
position: "sticky",
|
79
|
-
width: width,
|
80
|
-
backgroundColor: onRowClick && rowEl ? hover : normal,
|
81
|
-
"&::after": index === fixedLeftCols.length - 1 && leftShadowVisible
|
82
|
-
? {
|
83
|
-
position: "absolute",
|
84
|
-
top: 0,
|
85
|
-
right: 0,
|
86
|
-
bottom: "-1px",
|
87
|
-
width: "20px",
|
88
|
-
transform: "translateX(100%)",
|
89
|
-
transition: "box-shadow .3s",
|
90
|
-
content: "''",
|
91
|
-
boxShadow: "inset 10px 0 10px -8px rgba(0, 0, 0, 0.1)",
|
92
|
-
}
|
93
|
-
: undefined,
|
94
|
-
} }, { children: cloneElement(Cell, {
|
95
|
-
column: col,
|
96
|
-
rows: rows,
|
97
|
-
row: row,
|
98
|
-
rowIndex: virtualRow.index,
|
99
|
-
}) }), "Virtual_Grid_Body_Row_".concat(virtualRow.index, "_").concat(accessor)));
|
100
|
-
}), dynamicCols.map(function (col) {
|
101
|
-
var accessor = col.accessor, Cell = col.Cell, width = col.width, _a = col.align, align = _a === void 0 ? "center" : _a;
|
102
|
-
return (_jsx(TableCell, __assign({ align: align, sx: {
|
103
|
-
zIndex: 9,
|
104
|
-
width: width,
|
105
|
-
backgroundColor: onRowClick && rowEl ? hover : normal,
|
106
|
-
} }, { children: cloneElement(Cell, {
|
107
|
-
column: col,
|
108
|
-
rows: rows,
|
109
|
-
row: row,
|
110
|
-
rowIndex: virtualRow.index,
|
111
|
-
}) }), "Virtual_Grid_Body_Row_".concat(virtualRow.index, "_").concat(accessor)));
|
112
|
-
}), fixedRightCols.map(function (col, index) {
|
113
|
-
var accessor = col.accessor, Cell = col.Cell, width = col.width, _a = col.align, align = _a === void 0 ? "center" : _a;
|
114
|
-
var right = fixedRightCols
|
115
|
-
.slice(0, fixedRightCols.length - 1 - index)
|
116
|
-
.reduce(function (w, t) { return w + (t.width || 0); }, 0);
|
117
|
-
return (_jsx(TableCell, __assign({ align: align, sx: {
|
118
|
-
right: right,
|
119
|
-
width: width,
|
120
|
-
position: "sticky",
|
121
|
-
zIndex: 10,
|
122
|
-
backgroundColor: onRowClick && rowEl ? hover : normal,
|
123
|
-
"&::after": index === 0 && rightShadowVisible
|
124
|
-
? {
|
125
|
-
position: "absolute",
|
126
|
-
top: 0,
|
127
|
-
left: 0,
|
128
|
-
bottom: "-1px",
|
129
|
-
width: "20px",
|
130
|
-
transform: "translateX(-100%)",
|
131
|
-
transition: "box-shadow .3s",
|
132
|
-
content: "''",
|
133
|
-
boxShadow: "inset -10px 0 10px -8px rgba(0, 0, 0, 0.1)",
|
134
|
-
}
|
135
|
-
: undefined,
|
136
|
-
} }, { children: cloneElement(Cell, {
|
137
|
-
column: col,
|
138
|
-
rows: rows,
|
139
|
-
row: row,
|
140
|
-
rowIndex: virtualRow.index,
|
141
|
-
}) }), "Virtual_Grid_Body_Row_".concat(virtualRow.index, "_").concat(accessor)));
|
142
|
-
})] })));
|
143
|
-
}
|
144
|
-
export default memo(VirtualGridBodyRow);
|
@@ -1,4 +0,0 @@
|
|
1
|
-
import type { VirtualGridFooterProps } from "../types";
|
2
|
-
declare function VirtualGridFooter<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>>(props: VirtualGridFooterProps<RowProps, ExtendedProps>): import("react/jsx-runtime").JSX.Element;
|
3
|
-
declare const _default: typeof VirtualGridFooter;
|
4
|
-
export default _default;
|
@@ -1,109 +0,0 @@
|
|
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 VirtualGridFooter(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
|
-
} }, { children: _jsxs(TableRow, __assign({ sx: {
|
41
|
-
backgroundColor: "".concat(footerBgColor || "#eaf0f6", " !important"),
|
42
|
-
color: "".concat(footerTextColor || "inherit", " !important"),
|
43
|
-
width: "100%",
|
44
|
-
} }, { children: [fixedLeftFooters.map(function (footer, index) {
|
45
|
-
var accessor = footer.accessor, Cell = footer.Cell, _a = footer.align, align = _a === void 0 ? "center" : _a, width = footer.width;
|
46
|
-
var left = fixedLeftFooters
|
47
|
-
.slice(0, index)
|
48
|
-
.reduce(function (w, t) { return w + (t.width || 0); }, 0);
|
49
|
-
return (_jsx(TableCell, __assign({ align: align, sx: {
|
50
|
-
position: "sticky",
|
51
|
-
backgroundColor: "".concat(footerBgColor || "#eaf0f6", " !important"),
|
52
|
-
color: "".concat(footerTextColor || "inherit", " !important"),
|
53
|
-
zIndex: 10,
|
54
|
-
left: left,
|
55
|
-
width: width,
|
56
|
-
userSelect: "none",
|
57
|
-
"&::after": index === fixedLeftFooters.length - 1 && leftShadowVisible
|
58
|
-
? {
|
59
|
-
position: "absolute",
|
60
|
-
top: 0,
|
61
|
-
right: 0,
|
62
|
-
bottom: "-1px",
|
63
|
-
width: "20px",
|
64
|
-
transform: "translateX(100%)",
|
65
|
-
transition: "box-shadow .3s",
|
66
|
-
content: "''",
|
67
|
-
boxShadow: "inset 10px 0 10px -8px rgba(0, 0, 0, 0.1)",
|
68
|
-
}
|
69
|
-
: undefined,
|
70
|
-
} }, { children: cloneElement(Cell) }), "Virtual_Grid_Footer_Col_".concat(accessor)));
|
71
|
-
}), dynamicFooters.map(function (footer) {
|
72
|
-
var accessor = footer.accessor, Cell = footer.Cell, _a = footer.align, align = _a === void 0 ? "center" : _a, width = footer.width;
|
73
|
-
return (_jsx(TableCell, __assign({ align: align, sx: {
|
74
|
-
zIndex: 9,
|
75
|
-
width: width,
|
76
|
-
userSelect: "none",
|
77
|
-
backgroundColor: "".concat(footerBgColor || "#eaf0f6", " !important"),
|
78
|
-
color: "".concat(footerTextColor || "inherit", " !important"),
|
79
|
-
} }, { children: cloneElement(Cell) }), "Virtual_Grid_Footer_Col_".concat(accessor)));
|
80
|
-
}), fixedRightFooters.map(function (footer, index) {
|
81
|
-
var accessor = footer.accessor, Cell = footer.Cell, _a = footer.align, align = _a === void 0 ? "center" : _a, width = footer.width;
|
82
|
-
var right = fixedRightFooters
|
83
|
-
.slice(0, fixedRightFooters.length - 1 - index)
|
84
|
-
.reduce(function (w, t) { return w + (t.width || 0); }, 0);
|
85
|
-
return (_jsx(TableCell, __assign({ align: align, sx: {
|
86
|
-
position: "sticky",
|
87
|
-
zIndex: 10,
|
88
|
-
right: right,
|
89
|
-
width: width,
|
90
|
-
backgroundColor: "".concat(footerBgColor || "#eaf0f6", " !important"),
|
91
|
-
color: "".concat(footerTextColor || "inherit", " !important"),
|
92
|
-
userSelect: "none",
|
93
|
-
"&::after": index === 0 && rightShadowVisible
|
94
|
-
? {
|
95
|
-
position: "absolute",
|
96
|
-
top: 0,
|
97
|
-
left: 0,
|
98
|
-
bottom: "-1px",
|
99
|
-
width: "20px",
|
100
|
-
transform: "translateX(-100%)",
|
101
|
-
transition: "box-shadow .3s",
|
102
|
-
content: "''",
|
103
|
-
boxShadow: "inset -10px 0 10px -8px rgba(0, 0, 0, 0.1)",
|
104
|
-
}
|
105
|
-
: undefined,
|
106
|
-
} }, { children: cloneElement(Cell) }), "Virtual_Grid_Footer_Col_".concat(accessor)));
|
107
|
-
})] })) })));
|
108
|
-
}
|
109
|
-
export default memo(VirtualGridFooter);
|
@@ -1,4 +0,0 @@
|
|
1
|
-
import type { VirtualGridHeaderProps } from "../types";
|
2
|
-
declare function VirtualGridHeader<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>>(props: VirtualGridHeaderProps<RowProps, ExtendedProps>): import("react/jsx-runtime").JSX.Element;
|
3
|
-
declare const _default: typeof VirtualGridHeader;
|
4
|
-
export default _default;
|
@@ -1,114 +0,0 @@
|
|
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 VirtualGridHeader(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 } }, { children: _jsxs(TableRow, __assign({ sx: {
|
37
|
-
backgroundColor: "".concat(headerBgColor || "#eaf0f6", " !important"),
|
38
|
-
color: "".concat(headerTextColor || "inherit", " !important"),
|
39
|
-
width: "100%",
|
40
|
-
} }, { children: [fixedLeftHeaders.map(function (header, index) {
|
41
|
-
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;
|
42
|
-
var left = fixedLeftHeaders
|
43
|
-
.slice(0, index)
|
44
|
-
.reduce(function (w, t) { return w + (t.width || 0); }, 0);
|
45
|
-
return (_jsx(TableCell, __assign({ title: title, align: align, sx: {
|
46
|
-
position: "sticky",
|
47
|
-
backgroundColor: "".concat(headerBgColor || "#eaf0f6", " !important"),
|
48
|
-
color: "".concat(headerTextColor || "inherit", " !important"),
|
49
|
-
zIndex: 10,
|
50
|
-
left: left,
|
51
|
-
width: width,
|
52
|
-
userSelect: "none",
|
53
|
-
cursor: sortable ? "pointer" : "default",
|
54
|
-
"&::after": index === fixedLeftHeaders.length - 1 && leftShadowVisible
|
55
|
-
? {
|
56
|
-
position: "absolute",
|
57
|
-
top: 0,
|
58
|
-
right: 0,
|
59
|
-
bottom: "-1px",
|
60
|
-
width: "20px",
|
61
|
-
transform: "translateX(100%)",
|
62
|
-
transition: "box-shadow .3s",
|
63
|
-
content: "''",
|
64
|
-
boxShadow: "inset 10px 0 10px -8px rgba(0, 0, 0, 0.1)",
|
65
|
-
}
|
66
|
-
: undefined,
|
67
|
-
}, onClick: function () {
|
68
|
-
onSort({ accessor: accessor });
|
69
|
-
} }, { children: cloneElement(Cell) }), "Virtual_Grid_Header_Col_".concat(accessor)));
|
70
|
-
}), dynamicHeaders.map(function (header) {
|
71
|
-
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;
|
72
|
-
return (_jsx(TableCell, __assign({ title: title, align: align, sx: {
|
73
|
-
zIndex: 9,
|
74
|
-
width: width,
|
75
|
-
userSelect: "none",
|
76
|
-
cursor: sortable ? "pointer" : "default",
|
77
|
-
backgroundColor: "".concat(headerBgColor || "#eaf0f6", " !important"),
|
78
|
-
color: "".concat(headerTextColor || "inherit", " !important"),
|
79
|
-
}, onClick: function () {
|
80
|
-
onSort({ accessor: accessor });
|
81
|
-
} }, { children: cloneElement(Cell) }), "Virtual_Grid_Header_Col_".concat(accessor)));
|
82
|
-
}), fixedRightHeaders.map(function (header, index) {
|
83
|
-
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;
|
84
|
-
var right = fixedRightHeaders
|
85
|
-
.slice(0, fixedRightHeaders.length - 1 - index)
|
86
|
-
.reduce(function (w, t) { return w + (t.width || 0); }, 0);
|
87
|
-
return (_jsx(TableCell, __assign({ title: title, align: align, sx: {
|
88
|
-
position: "sticky",
|
89
|
-
backgroundColor: "".concat(headerBgColor || "#eaf0f6", " !important"),
|
90
|
-
color: "".concat(headerTextColor || "inherit", " !important"),
|
91
|
-
zIndex: 10,
|
92
|
-
right: right,
|
93
|
-
width: width,
|
94
|
-
userSelect: "none",
|
95
|
-
cursor: sortable ? "pointer" : "default",
|
96
|
-
"&::after": index === 0 && rightShadowVisible
|
97
|
-
? {
|
98
|
-
position: "absolute",
|
99
|
-
top: 0,
|
100
|
-
left: 0,
|
101
|
-
bottom: "-1px",
|
102
|
-
width: "20px",
|
103
|
-
transform: "translateX(-100%)",
|
104
|
-
transition: "box-shadow .3s",
|
105
|
-
content: "''",
|
106
|
-
boxShadow: "inset -10px 0 10px -8px rgba(0, 0, 0, 0.1)",
|
107
|
-
}
|
108
|
-
: undefined,
|
109
|
-
}, onClick: function () {
|
110
|
-
onSort({ accessor: accessor });
|
111
|
-
} }, { children: cloneElement(Cell) }), "Virtual_Grid_Header_Col_".concat(accessor)));
|
112
|
-
})] })) })));
|
113
|
-
}
|
114
|
-
export default memo(VirtualGridHeader);
|
@@ -1,4 +0,0 @@
|
|
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
|
-
declare const _default: typeof VirtualGridCore;
|
4
|
-
export default _default;
|
@@ -1,34 +0,0 @@
|
|
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, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
13
|
-
import { memo } from "react";
|
14
|
-
import Grid from "@mui/material/Grid";
|
15
|
-
import Table from "@mui/material/Table";
|
16
|
-
import TableContainer from "@mui/material/TableContainer";
|
17
|
-
import TableBody from "./GridBody";
|
18
|
-
import TableHeader from "./GridHeader";
|
19
|
-
import TableFooter from "./GridFooter";
|
20
|
-
import { useGridVirtualizer } from "../GridVirtualizerContext";
|
21
|
-
function VirtualGridCore(props) {
|
22
|
-
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;
|
23
|
-
var _f = useGridVirtualizer(), tableRef = _f.tableRef, getTotalSize = _f.getTotalSize, onProcessShadowVisible = _f.onProcessShadowVisible;
|
24
|
-
return (_jsx(TableContainer, __assign({ ref: tableRef, onScroll: onProcessShadowVisible, sx: {
|
25
|
-
maxHeight: "inherit",
|
26
|
-
borderWidth: "thin",
|
27
|
-
borderColor: "#e5e5e5",
|
28
|
-
borderStyle: "solid",
|
29
|
-
borderRadius: "4px",
|
30
|
-
borderCollapse: "unset !important",
|
31
|
-
transition: "all 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms",
|
32
|
-
} }, { children: _jsx(Grid, __assign({ sx: { height: "".concat(getTotalSize(), "px") } }, { 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, {}))] })) })) })));
|
33
|
-
}
|
34
|
-
export default memo(VirtualGridCore);
|
@@ -1,3 +0,0 @@
|
|
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;
|
@@ -1,108 +0,0 @@
|
|
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 } from "react/jsx-runtime";
|
13
|
-
import { useRef, useMemo, useState, useEffect, useContext, useCallback, createContext, } from "react";
|
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({
|
22
|
-
tableRef: { current: null },
|
23
|
-
virtualRows: [],
|
24
|
-
leftShadowVisible: false,
|
25
|
-
rightShadowVisible: false,
|
26
|
-
getTotalSize: function () { return 0; },
|
27
|
-
onMeasureElement: function () { },
|
28
|
-
onProcessShadowVisible: function () { },
|
29
|
-
});
|
30
|
-
export function GridVirtualizerContextProvider(props) {
|
31
|
-
var children = props.children, rows = props.rows, columns = props.columns, dense = props.dense, estimateRowHeight = props.estimateRowHeight;
|
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
|
-
}, []);
|
56
|
-
var measureElementHeight = useMemo(function () {
|
57
|
-
return typeof window !== "undefined" &&
|
58
|
-
navigator.userAgent.indexOf("Firefox") === -1
|
59
|
-
? function (element) { return element === null || element === void 0 ? void 0 : element.getBoundingClientRect().height; }
|
60
|
-
: undefined;
|
61
|
-
}, []);
|
62
|
-
var rowVirtualizer = useVirtualizer({
|
63
|
-
count: rows.length,
|
64
|
-
getScrollElement: function () { return tableRef.current; },
|
65
|
-
estimateSize: function () { return estimateRowHeight || (dense ? 48 : 72); },
|
66
|
-
measureElement: measureElementHeight,
|
67
|
-
overscan: Math.round(rows.length / (2 * PI)),
|
68
|
-
scrollToFn: scrollToFn,
|
69
|
-
});
|
70
|
-
var _a = useState(false), leftShadowVisible = _a[0], setLeftShadowVisible = _a[1];
|
71
|
-
var _b = useState(false), rightShadowVisible = _b[0], setRightShadowVisible = _b[1];
|
72
|
-
var measureElement = rowVirtualizer.measureElement, getVirtualItems = rowVirtualizer.getVirtualItems, getTotalSize = rowVirtualizer.getTotalSize;
|
73
|
-
var virtualRows = getVirtualItems();
|
74
|
-
var onProcessShadowVisible = useCallback(function () {
|
75
|
-
if (tableRef.current) {
|
76
|
-
var target = tableRef.current;
|
77
|
-
var scrollLeft = target.scrollLeft;
|
78
|
-
var scrollWidth = target.scrollWidth;
|
79
|
-
var clientWidth = target.clientWidth;
|
80
|
-
var hasScrollBar = scrollWidth > clientWidth;
|
81
|
-
setLeftShadowVisible(hasScrollBar && scrollLeft > 0);
|
82
|
-
setRightShadowVisible(hasScrollBar && scrollWidth - scrollLeft > clientWidth + 1);
|
83
|
-
}
|
84
|
-
}, []);
|
85
|
-
useEffect(function () {
|
86
|
-
if (columns) {
|
87
|
-
onProcessShadowVisible();
|
88
|
-
}
|
89
|
-
}, [columns, onProcessShadowVisible]);
|
90
|
-
useEffect(function () {
|
91
|
-
window.addEventListener("resize", onProcessShadowVisible);
|
92
|
-
}, [onProcessShadowVisible]);
|
93
|
-
useEffect(function () { return function () {
|
94
|
-
window.removeEventListener("scroll", onProcessShadowVisible);
|
95
|
-
}; }, [onProcessShadowVisible]);
|
96
|
-
return (_jsx(GridVirtualizerContext.Provider, __assign({ value: {
|
97
|
-
tableRef: tableRef,
|
98
|
-
virtualRows: virtualRows,
|
99
|
-
leftShadowVisible: leftShadowVisible,
|
100
|
-
rightShadowVisible: rightShadowVisible,
|
101
|
-
getTotalSize: getTotalSize,
|
102
|
-
onMeasureElement: measureElement,
|
103
|
-
onProcessShadowVisible: onProcessShadowVisible,
|
104
|
-
} }, { children: children })));
|
105
|
-
}
|
106
|
-
export var useGridVirtualizer = function () {
|
107
|
-
return useContext(GridVirtualizerContext);
|
108
|
-
};
|
package/VirtualGrid/index.d.ts
DELETED
@@ -1,6 +0,0 @@
|
|
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 };
|
package/VirtualGrid/index.js
DELETED
@@ -1,36 +0,0 @@
|
|
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 estimateRowHeight = props.estimateRowHeight, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor, rows = props.rows, columns = props.columns, dense = props.dense, rest = __rest(props, ["estimateRowHeight", "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, estimateRowHeight: estimateRowHeight }, { children: _jsx(VirtualGridCore, __assign({}, rest, { rows: rows, columns: columns, dense: dense })) })) })));
|
33
|
-
}
|
34
|
-
export default VirtualGrid;
|
35
|
-
export * from "./types";
|
36
|
-
export { useVirtualGrid };
|
package/VirtualGrid/types.d.ts
DELETED
@@ -1,104 +0,0 @@
|
|
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
|
-
};
|
83
|
-
export declare type VirtualGridProps<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>> = VirtualGridCoreProps<RowProps, ExtendedProps> & {
|
84
|
-
estimateRowHeight?: number;
|
85
|
-
primaryColor?: CSSProperties["color"];
|
86
|
-
secondaryColor?: CSSProperties["color"];
|
87
|
-
};
|
88
|
-
export interface GridVirtualizerContextProviderProps<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>> {
|
89
|
-
dense?: boolean;
|
90
|
-
children: ReactNode;
|
91
|
-
rows: Array<RowProps>;
|
92
|
-
estimateRowHeight?: number;
|
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 {};
|
package/VirtualGrid/types.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1,103 +0,0 @@
|
|
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;
|