@symply.io/basic-components 1.7.0-alpha.1 → 1.7.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ import type { VirtualTableProps, TVirtualTableRow } from "./types";
2
+ declare function VirtualDataTable<RowProps extends TVirtualTableRow>(props: VirtualTableProps<RowProps>): import("react/jsx-runtime").JSX.Element;
3
+ export default VirtualDataTable;
@@ -0,0 +1,167 @@
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, Fragment as _Fragment } from "react/jsx-runtime";
13
+ import { forwardRef, cloneElement, useMemo, useCallback } from "react";
14
+ import { TableVirtuoso } from "react-virtuoso";
15
+ import Paper from "@mui/material/Paper";
16
+ import Table from "@mui/material/Table";
17
+ import TableRow from "@mui/material/TableRow";
18
+ import TableBody from "@mui/material/TableBody";
19
+ import TableCell from "@mui/material/TableCell";
20
+ import TableHead from "@mui/material/TableHead";
21
+ import TableFooter from "@mui/material/TableFooter";
22
+ import TableContainer from "@mui/material/TableContainer";
23
+ import useMediaQuery from "@mui/material/useMediaQuery";
24
+ import useTheme from "@mui/material/styles/useTheme";
25
+ function VirtualDataTable(props) {
26
+ var rows = props.rows, columns = props.columns, dense = props.dense;
27
+ var theme = useTheme();
28
+ var isUpMd = useMediaQuery(theme.breakpoints.up("md"));
29
+ var _a = useMemo(function () {
30
+ if (isUpMd) {
31
+ var left = columns.filter(function (c) { return c.fixable === "left"; });
32
+ var right = columns.filter(function (c) { return c.fixable === "right"; });
33
+ var dynamic = columns.filter(function (c) { return !c.fixable; });
34
+ return [left, dynamic, right];
35
+ }
36
+ else {
37
+ return [[], columns, []];
38
+ }
39
+ }, [isUpMd, columns]), pinnedLeftCols = _a[0], normalCols = _a[1], pinnedRightCols = _a[2];
40
+ var VirtuosoTableComponents = useMemo(function () { return ({
41
+ Scroller: forwardRef(function (props, ref) { return (_jsx(TableContainer, __assign({ component: Paper }, props, { ref: ref, sx: {
42
+ maxHeight: "inherit",
43
+ borderWidth: "thin",
44
+ borderColor: "#e5e5e5",
45
+ borderStyle: "solid",
46
+ borderRadius: "4px",
47
+ borderCollapse: "unset !important",
48
+ transition: "all 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms",
49
+ } }))); }),
50
+ Table: function (props) { return (_jsx(Table, __assign({}, props, { size: dense ? "small" : "medium", sx: {
51
+ borderCollapse: "separate",
52
+ minWidth: 600,
53
+ tableLayout: "fixed",
54
+ } }))); },
55
+ TableHead: forwardRef(function (props, ref) { return (_jsx(TableHead, __assign({}, props, { ref: ref }))); }),
56
+ TableRow: TableRow,
57
+ TableBody: forwardRef(function (props, ref) { return (_jsx(TableBody, __assign({}, props, { ref: ref }))); }),
58
+ TableFoot: forwardRef(function (props, ref) { return (_jsx(TableFooter, __assign({}, props, { ref: ref }))); }),
59
+ }); }, []);
60
+ var fixedHeaderContent = useCallback(function () {
61
+ return (_jsxs(TableRow, { children: [pinnedLeftCols.map(function (column, index) {
62
+ var align = column.align, width = column.width, Header = column.Header, accessor = column.accessor, headerTip = column.headerTip, sortable = column.sortable;
63
+ var left = pinnedLeftCols
64
+ .slice(0, index)
65
+ .reduce(function (w, t) { return w + (t.width || 0); }, 0);
66
+ return (_jsx(TableCell, __assign({ variant: "head", title: headerTip, align: align, sx: {
67
+ position: "sticky",
68
+ left: left,
69
+ zIndex: 20,
70
+ width: width,
71
+ cursor: sortable ? "pointer" : "default",
72
+ backgroundColor: "background.paper",
73
+ } }, { children: cloneElement(Header) }), accessor));
74
+ }), normalCols.map(function (column) {
75
+ var align = column.align, width = column.width, Header = column.Header, accessor = column.accessor, headerTip = column.headerTip, sortable = column.sortable;
76
+ return (_jsx(TableCell, __assign({ variant: "head", title: headerTip, align: align, sx: {
77
+ zIndex: 9,
78
+ width: width,
79
+ cursor: sortable ? "pointer" : "default",
80
+ backgroundColor: "background.paper",
81
+ } }, { children: cloneElement(Header) }), accessor));
82
+ }), pinnedRightCols.map(function (column, index) {
83
+ var align = column.align, width = column.width, Header = column.Header, accessor = column.accessor, headerTip = column.headerTip, sortable = column.sortable;
84
+ var right = pinnedRightCols
85
+ .slice(0, pinnedRightCols.length - 1 - index)
86
+ .reduce(function (w, t) { return w + (t.width || 0); }, 0);
87
+ return (_jsx(TableCell, __assign({ variant: "head", title: headerTip, align: align, sx: {
88
+ position: "sticky",
89
+ right: right,
90
+ zIndex: 20,
91
+ width: width,
92
+ cursor: sortable ? "pointer" : "default",
93
+ backgroundColor: "background.paper",
94
+ } }, { children: cloneElement(Header) }), accessor));
95
+ })] }));
96
+ }, []);
97
+ var fixedFooterContent = useCallback(function () {
98
+ return (_jsxs(TableRow, { children: [pinnedLeftCols.map(function (column, index) {
99
+ var align = column.align, width = column.width, Footer = column.Footer, accessor = column.accessor;
100
+ var left = pinnedLeftCols
101
+ .slice(0, index)
102
+ .reduce(function (w, t) { return w + (t.width || 0); }, 0);
103
+ return (_jsx(TableCell, __assign({ variant: "footer", align: align, sx: {
104
+ position: "sticky",
105
+ left: left,
106
+ zIndex: 20,
107
+ width: width,
108
+ backgroundColor: "background.paper",
109
+ } }, { children: Footer ? cloneElement(Footer) : _jsx(_Fragment, {}) }), accessor));
110
+ }), normalCols.map(function (column) {
111
+ var align = column.align, width = column.width, Footer = column.Footer, accessor = column.accessor;
112
+ return (_jsx(TableCell, __assign({ variant: "footer", align: align, sx: {
113
+ zIndex: 9,
114
+ width: width,
115
+ backgroundColor: "background.paper",
116
+ } }, { children: Footer ? cloneElement(Footer) : _jsx(_Fragment, {}) }), accessor));
117
+ }), pinnedRightCols.map(function (column, index) {
118
+ var align = column.align, width = column.width, Footer = column.Footer, accessor = column.accessor;
119
+ var right = pinnedRightCols
120
+ .slice(0, pinnedRightCols.length - 1 - index)
121
+ .reduce(function (w, t) { return w + (t.width || 0); }, 0);
122
+ return (_jsx(TableCell, __assign({ variant: "footer", align: align, sx: {
123
+ position: "sticky",
124
+ right: right,
125
+ zIndex: 20,
126
+ width: width,
127
+ backgroundColor: "background.paper",
128
+ } }, { children: Footer ? cloneElement(Footer) : _jsx(_Fragment, {}) }), accessor));
129
+ })] }));
130
+ }, []);
131
+ var itemContent = useCallback(function (rowIndex, row) {
132
+ return (_jsxs(_Fragment, { children: [pinnedLeftCols.map(function (column, index) {
133
+ var align = column.align, width = column.width, Body = column.Body, accessor = column.accessor;
134
+ var left = pinnedLeftCols
135
+ .slice(0, index)
136
+ .reduce(function (w, t) { return w + (t.width || 0); }, 0);
137
+ return (_jsx(TableCell, __assign({ variant: "footer", align: align, sx: {
138
+ position: "sticky",
139
+ left: left,
140
+ zIndex: 20,
141
+ width: width,
142
+ backgroundColor: "background.paper",
143
+ } }, { children: cloneElement(Body, { column: column, row: row, rows: rows, rowIndex: rowIndex }) }), accessor));
144
+ }), normalCols.map(function (column) {
145
+ var align = column.align, width = column.width, Body = column.Body, accessor = column.accessor;
146
+ return (_jsx(TableCell, __assign({ variant: "footer", align: align, sx: {
147
+ zIndex: 9,
148
+ width: width,
149
+ backgroundColor: "background.paper",
150
+ } }, { children: cloneElement(Body, { column: column, row: row, rows: rows, rowIndex: rowIndex }) }), accessor));
151
+ }), pinnedRightCols.map(function (column, index) {
152
+ var align = column.align, width = column.width, Body = column.Body, accessor = column.accessor;
153
+ var right = pinnedRightCols
154
+ .slice(0, pinnedRightCols.length - 1 - index)
155
+ .reduce(function (w, t) { return w + (t.width || 0); }, 0);
156
+ return (_jsx(TableCell, __assign({ variant: "footer", align: align, sx: {
157
+ position: "sticky",
158
+ right: right,
159
+ zIndex: 20,
160
+ width: width,
161
+ backgroundColor: "background.paper",
162
+ } }, { children: cloneElement(Body, { column: column, row: row, rows: rows, rowIndex: rowIndex }) }), accessor));
163
+ })] }));
164
+ }, []);
165
+ return (_jsx(TableVirtuoso, { data: rows, components: VirtuosoTableComponents, fixedHeaderContent: fixedHeaderContent, fixedFooterContent: fixedFooterContent, itemContent: itemContent }));
166
+ }
167
+ export default VirtualDataTable;
@@ -0,0 +1,20 @@
1
+ import type { ReactElement, CSSProperties } from "react";
2
+ export declare type TVirtualTableRow = Record<string, any>;
3
+ export declare type TVirtualTableColumn = {
4
+ headerTip?: string;
5
+ Header: ReactElement;
6
+ Body: ReactElement;
7
+ Footer?: ReactElement;
8
+ align?: "left" | "center" | "right";
9
+ accessor: string;
10
+ sortable?: boolean;
11
+ fixable?: "left" | "right";
12
+ width: number;
13
+ };
14
+ export interface VirtualTableProps<RowProps extends TVirtualTableRow> {
15
+ dense?: boolean;
16
+ rows: Array<RowProps>;
17
+ columns: Array<TVirtualTableColumn>;
18
+ primaryColor?: CSSProperties["color"];
19
+ secondaryColor?: CSSProperties["color"];
20
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,3 +1,4 @@
1
1
  import type { VirtualGridBodyProps } from "../types";
2
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
- export default VirtualGridBody;
3
+ declare const _default: typeof VirtualGridBody;
4
+ export default _default;
@@ -21,21 +21,17 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  return t;
22
22
  };
23
23
  import { jsx as _jsx } from "react/jsx-runtime";
24
+ import { memo } from "react";
24
25
  import TableRow from "@mui/material/TableRow";
25
26
  import TableBody from "@mui/material/TableBody";
26
27
  import TableCell from "@mui/material/TableCell";
27
- import TableBodyRow from "./TableBodyRow";
28
+ import GridBodyRow from "./GridBodyRow";
28
29
  import { useGridVirtualizer } from "../GridVirtualizerContext";
29
30
  function VirtualGridBody(props) {
30
31
  var rows = props.rows, columns = props.columns, _a = props.noDataText, noDataText = _a === void 0 ? "No Data!" : _a, rest = __rest(props, ["rows", "columns", "noDataText"]);
31
- var _b = useGridVirtualizer(), virtualRows = _b.virtualRows, getTotalSize = _b.getTotalSize;
32
- return (_jsx(TableBody, __assign({ sx: {
33
- height: "".concat(getTotalSize(), "px"),
34
- width: "100%",
35
- position: "relative",
36
- display: "grid",
37
- } }, { children: virtualRows.length > 0 ? (virtualRows.map(function (virtualRow) {
38
- return (_jsx(TableBodyRow, __assign({ rowIndex: virtualRow.index, virtualRow: virtualRow, rows: rows, columns: columns }, rest), "DataTable_".concat(virtualRow.index)));
39
- })) : (_jsx(TableRow, { children: _jsx(TableCell, __assign({ colSpan: columns.length, align: "center" }, { children: 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 })) })) }));
40
36
  }
41
- export default VirtualGridBody;
37
+ export default memo(VirtualGridBody);
@@ -0,0 +1,4 @@
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;
@@ -10,20 +10,19 @@ var __assign = (this && this.__assign) || function () {
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
- import { cloneElement, useState, useMemo } from "react";
13
+ import { memo, cloneElement, useState, useMemo } from "react";
14
14
  import TableRow from "@mui/material/TableRow";
15
15
  import TableCell from "@mui/material/TableCell";
16
16
  import useMediaQuery from "@mui/material/useMediaQuery";
17
17
  import useTheme from "@mui/material/styles/useTheme";
18
18
  import { useGridVirtualizer } from "../GridVirtualizerContext";
19
- function TableBodyRow(props) {
19
+ function VirtualGridBodyRow(props) {
20
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 _a = useState(), rowEl = _a[0], setRowEl = _a[1];
22
21
  var theme = useTheme();
23
22
  var isUpMd = useMediaQuery(theme.breakpoints.up("md"));
24
- var _b = useGridVirtualizer(), leftShadowVisible = _b.leftShadowVisible, rightShadowVisible = _b.rightShadowVisible, onMeasureElement = _b.onMeasureElement;
23
+ var _a = useGridVirtualizer(), leftShadowVisible = _a.leftShadowVisible, rightShadowVisible = _a.rightShadowVisible, onMeasureElement = _a.onMeasureElement;
25
24
  var row = useMemo(function () { return rows[virtualRow.index]; }, [rows, virtualRow]);
26
- var _c = useMemo(function () {
25
+ var _b = useMemo(function () {
27
26
  if (isUpMd) {
28
27
  var left = columns.filter(function (c) { return c.fixable === "left"; });
29
28
  var right = columns.filter(function (c) { return c.fixable === "right"; });
@@ -33,8 +32,8 @@ function TableBodyRow(props) {
33
32
  else {
34
33
  return [[], columns, []];
35
34
  }
36
- }, [isUpMd, columns]), fixedLeftCols = _c[0], dynamicCols = _c[1], fixedRightCols = _c[2];
37
- var _d = useMemo(function () {
35
+ }, [isUpMd, columns]), fixedLeftCols = _b[0], dynamicCols = _b[1], fixedRightCols = _b[2];
36
+ var _c = useMemo(function () {
38
37
  if (onCustomizeRowBgColor) {
39
38
  var regex = /^#(\d|[a-f]|[A-F]){6}/i;
40
39
  var _a = onCustomizeRowBgColor({ row: row, columns: columns }), normal_1 = _a.normal, hover_1 = _a.hover;
@@ -44,18 +43,18 @@ function TableBodyRow(props) {
44
43
  };
45
44
  }
46
45
  return { normal: "#FEFEFE", hover: "#F2F1F3" };
47
- }, [row, columns, onCustomizeRowBgColor]), normal = _d.normal, hover = _d.hover;
46
+ }, [row, columns, onCustomizeRowBgColor]), normal = _c.normal, hover = _c.hover;
47
+ var _d = useState(), rowEl = _d[0], setRowEl = _d[1];
48
48
  return (_jsxs(TableRow, __assign({ sx: {
49
49
  backgroundColor: normal,
50
50
  width: "100%",
51
- position: "absolute",
52
- display: "flex",
53
- transform: "translateY(".concat(virtualRow.start, "px)"),
51
+ height: "".concat(virtualRow.size, "px"),
52
+ transform: "translateY(".concat(virtualRow.start - rowIndex * virtualRow.size, "px)"),
54
53
  "&:hover": {
55
54
  cursor: onRowClick ? "pointer" : "default",
56
55
  backgroundColor: onRowClick ? hover : normal,
57
56
  },
58
- }, "data-index": virtualRow.index, ref: function (node) { return onMeasureElement(node); }, onMouseEnter: function (event) {
57
+ }, "data-index": virtualRow.index, onMouseEnter: function (event) {
59
58
  setRowEl(event.currentTarget);
60
59
  }, onMouseLeave: function () {
61
60
  setRowEl(undefined);
@@ -74,11 +73,10 @@ function TableBodyRow(props) {
74
73
  .slice(0, index)
75
74
  .reduce(function (w, t) { return w + (t.width || 0); }, 0);
76
75
  return (_jsx(TableCell, __assign({ align: align, sx: {
77
- minWidth: width,
78
76
  left: left,
79
- position: "sticky",
80
- display: "flex",
81
77
  zIndex: 10,
78
+ position: "sticky",
79
+ width: width,
82
80
  backgroundColor: onRowClick && rowEl ? hover : normal,
83
81
  "&::after": index === fixedLeftCols.length - 1 && leftShadowVisible
84
82
  ? {
@@ -93,26 +91,34 @@ function TableBodyRow(props) {
93
91
  boxShadow: "inset 10px 0 10px -8px rgba(0, 0, 0, 0.1)",
94
92
  }
95
93
  : undefined,
96
- } }, { children: cloneElement(Cell, { column: col, rows: rows, row: row, rowIndex: rowIndex }) }), accessor));
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)));
97
100
  }), dynamicCols.map(function (col) {
98
101
  var accessor = col.accessor, Cell = col.Cell, width = col.width, _a = col.align, align = _a === void 0 ? "center" : _a;
99
102
  return (_jsx(TableCell, __assign({ align: align, sx: {
100
- minWidth: width,
101
103
  zIndex: 9,
102
- display: "flex",
104
+ width: width,
103
105
  backgroundColor: onRowClick && rowEl ? hover : normal,
104
- } }, { children: cloneElement(Cell, { column: col, rows: rows, row: row, rowIndex: rowIndex }) }), accessor));
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)));
105
112
  }), fixedRightCols.map(function (col, index) {
106
113
  var accessor = col.accessor, Cell = col.Cell, width = col.width, _a = col.align, align = _a === void 0 ? "center" : _a;
107
114
  var right = fixedRightCols
108
115
  .slice(0, fixedRightCols.length - 1 - index)
109
116
  .reduce(function (w, t) { return w + (t.width || 0); }, 0);
110
117
  return (_jsx(TableCell, __assign({ align: align, sx: {
111
- minWidth: width,
112
118
  right: right,
119
+ width: width,
113
120
  position: "sticky",
114
121
  zIndex: 10,
115
- display: "flex",
116
122
  backgroundColor: onRowClick && rowEl ? hover : normal,
117
123
  "&::after": index === 0 && rightShadowVisible
118
124
  ? {
@@ -127,7 +133,12 @@ function TableBodyRow(props) {
127
133
  boxShadow: "inset -10px 0 10px -8px rgba(0, 0, 0, 0.1)",
128
134
  }
129
135
  : undefined,
130
- } }, { children: cloneElement(Cell, { column: col, rows: rows, row: row, rowIndex: rowIndex }) }), accessor));
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)));
131
142
  })] })));
132
143
  }
133
- export default TableBodyRow;
144
+ export default memo(VirtualGridBodyRow);
@@ -0,0 +1,4 @@
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;
@@ -17,7 +17,7 @@ import TableCell from "@mui/material/TableCell";
17
17
  import useMediaQuery from "@mui/material/useMediaQuery";
18
18
  import useTheme from "@mui/material/styles/useTheme";
19
19
  import { useGridVirtualizer } from "../GridVirtualizerContext";
20
- function TableFooter(props) {
20
+ function VirtualGridFooter(props) {
21
21
  var _a = props.footers, footers = _a === void 0 ? [] : _a, footerBgColor = props.footerBgColor, footerTextColor = props.footerTextColor, noData = props.noData;
22
22
  var theme = useTheme();
23
23
  var isUpMd = useMediaQuery(theme.breakpoints.up("md"));
@@ -37,11 +37,9 @@ function TableFooter(props) {
37
37
  position: "sticky",
38
38
  bottom: "-1px",
39
39
  zIndex: 20,
40
- display: "grid",
41
40
  } }, { children: _jsxs(TableRow, __assign({ sx: {
42
41
  backgroundColor: "".concat(footerBgColor || "#eaf0f6", " !important"),
43
42
  color: "".concat(footerTextColor || "inherit", " !important"),
44
- display: "flex",
45
43
  width: "100%",
46
44
  } }, { children: [fixedLeftFooters.map(function (footer, index) {
47
45
  var accessor = footer.accessor, Cell = footer.Cell, _a = footer.align, align = _a === void 0 ? "center" : _a, width = footer.width;
@@ -54,8 +52,7 @@ function TableFooter(props) {
54
52
  color: "".concat(footerTextColor || "inherit", " !important"),
55
53
  zIndex: 10,
56
54
  left: left,
57
- minWidth: width,
58
- display: "flex",
55
+ width: width,
59
56
  userSelect: "none",
60
57
  "&::after": index === fixedLeftFooters.length - 1 && leftShadowVisible
61
58
  ? {
@@ -70,17 +67,16 @@ function TableFooter(props) {
70
67
  boxShadow: "inset 10px 0 10px -8px rgba(0, 0, 0, 0.1)",
71
68
  }
72
69
  : undefined,
73
- } }, { children: cloneElement(Cell) }), accessor));
70
+ } }, { children: cloneElement(Cell) }), "Virtual_Grid_Footer_Col_".concat(accessor)));
74
71
  }), dynamicFooters.map(function (footer) {
75
72
  var accessor = footer.accessor, Cell = footer.Cell, _a = footer.align, align = _a === void 0 ? "center" : _a, width = footer.width;
76
73
  return (_jsx(TableCell, __assign({ align: align, sx: {
77
74
  zIndex: 9,
78
- minWidth: width,
79
- display: "flex",
75
+ width: width,
80
76
  userSelect: "none",
81
77
  backgroundColor: "".concat(footerBgColor || "#eaf0f6", " !important"),
82
78
  color: "".concat(footerTextColor || "inherit", " !important"),
83
- } }, { children: cloneElement(Cell) }), accessor));
79
+ } }, { children: cloneElement(Cell) }), "Virtual_Grid_Footer_Col_".concat(accessor)));
84
80
  }), fixedRightFooters.map(function (footer, index) {
85
81
  var accessor = footer.accessor, Cell = footer.Cell, _a = footer.align, align = _a === void 0 ? "center" : _a, width = footer.width;
86
82
  var right = fixedRightFooters
@@ -89,9 +85,8 @@ function TableFooter(props) {
89
85
  return (_jsx(TableCell, __assign({ align: align, sx: {
90
86
  position: "sticky",
91
87
  zIndex: 10,
92
- minWidth: width,
93
88
  right: right,
94
- display: "flex",
89
+ width: width,
95
90
  backgroundColor: "".concat(footerBgColor || "#eaf0f6", " !important"),
96
91
  color: "".concat(footerTextColor || "inherit", " !important"),
97
92
  userSelect: "none",
@@ -108,7 +103,7 @@ function TableFooter(props) {
108
103
  boxShadow: "inset -10px 0 10px -8px rgba(0, 0, 0, 0.1)",
109
104
  }
110
105
  : undefined,
111
- } }, { children: cloneElement(Cell) }), accessor));
106
+ } }, { children: cloneElement(Cell) }), "Virtual_Grid_Footer_Col_".concat(accessor)));
112
107
  })] })) })));
113
108
  }
114
- export default memo(TableFooter);
109
+ export default memo(VirtualGridFooter);
@@ -0,0 +1,4 @@
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;
@@ -17,7 +17,7 @@ import TableCell from "@mui/material/TableCell";
17
17
  import useMediaQuery from "@mui/material/useMediaQuery";
18
18
  import useTheme from "@mui/material/styles/useTheme";
19
19
  import { useGridVirtualizer } from "../GridVirtualizerContext";
20
- function TableHeader(props) {
20
+ function VirtualGridHeader(props) {
21
21
  var headers = props.headers, headerBgColor = props.headerBgColor, headerTextColor = props.headerTextColor, noData = props.noData;
22
22
  var theme = useTheme();
23
23
  var isUpMd = useMediaQuery(theme.breakpoints.up("md"));
@@ -33,10 +33,9 @@ function TableHeader(props) {
33
33
  return [[], headers, []];
34
34
  }
35
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: {
36
+ return (_jsx(TableHead, __assign({ sx: { position: "sticky", top: 0, zIndex: 20 } }, { children: _jsxs(TableRow, __assign({ sx: {
37
37
  backgroundColor: "".concat(headerBgColor || "#eaf0f6", " !important"),
38
38
  color: "".concat(headerTextColor || "inherit", " !important"),
39
- display: "flex",
40
39
  width: "100%",
41
40
  } }, { children: [fixedLeftHeaders.map(function (header, index) {
42
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;
@@ -48,9 +47,8 @@ function TableHeader(props) {
48
47
  backgroundColor: "".concat(headerBgColor || "#eaf0f6", " !important"),
49
48
  color: "".concat(headerTextColor || "inherit", " !important"),
50
49
  zIndex: 10,
51
- minWidth: width,
52
50
  left: left,
53
- display: "flex",
51
+ width: width,
54
52
  userSelect: "none",
55
53
  cursor: sortable ? "pointer" : "default",
56
54
  "&::after": index === fixedLeftHeaders.length - 1 && leftShadowVisible
@@ -68,20 +66,19 @@ function TableHeader(props) {
68
66
  : undefined,
69
67
  }, onClick: function () {
70
68
  onSort({ accessor: accessor });
71
- } }, { children: cloneElement(Cell) }), accessor));
69
+ } }, { children: cloneElement(Cell) }), "Virtual_Grid_Header_Col_".concat(accessor)));
72
70
  }), dynamicHeaders.map(function (header) {
73
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;
74
72
  return (_jsx(TableCell, __assign({ title: title, align: align, sx: {
75
- minWidth: width,
76
73
  zIndex: 9,
74
+ width: width,
77
75
  userSelect: "none",
78
- display: "flex",
79
76
  cursor: sortable ? "pointer" : "default",
80
77
  backgroundColor: "".concat(headerBgColor || "#eaf0f6", " !important"),
81
78
  color: "".concat(headerTextColor || "inherit", " !important"),
82
79
  }, onClick: function () {
83
80
  onSort({ accessor: accessor });
84
- } }, { children: cloneElement(Cell) }), accessor));
81
+ } }, { children: cloneElement(Cell) }), "Virtual_Grid_Header_Col_".concat(accessor)));
85
82
  }), fixedRightHeaders.map(function (header, index) {
86
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;
87
84
  var right = fixedRightHeaders
@@ -92,9 +89,8 @@ function TableHeader(props) {
92
89
  backgroundColor: "".concat(headerBgColor || "#eaf0f6", " !important"),
93
90
  color: "".concat(headerTextColor || "inherit", " !important"),
94
91
  zIndex: 10,
95
- minWidth: width,
96
92
  right: right,
97
- display: "flex",
93
+ width: width,
98
94
  userSelect: "none",
99
95
  cursor: sortable ? "pointer" : "default",
100
96
  "&::after": index === 0 && rightShadowVisible
@@ -112,7 +108,7 @@ function TableHeader(props) {
112
108
  : undefined,
113
109
  }, onClick: function () {
114
110
  onSort({ accessor: accessor });
115
- } }, { children: cloneElement(Cell) }), accessor));
111
+ } }, { children: cloneElement(Cell) }), "Virtual_Grid_Header_Col_".concat(accessor)));
116
112
  })] })) })));
117
113
  }
118
- export default memo(TableHeader);
114
+ export default memo(VirtualGridHeader);
@@ -1,3 +1,4 @@
1
1
  import type { VirtualGridCoreProps } from "../types";
2
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;
3
+ declare const _default: typeof VirtualGridCore;
4
+ export default _default;
@@ -10,15 +10,17 @@ var __assign = (this && this.__assign) || function () {
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
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";
13
15
  import Table from "@mui/material/Table";
14
16
  import TableContainer from "@mui/material/TableContainer";
15
- import TableBody from "./TableBody";
16
- import TableHeader from "./TableHeader";
17
- import TableFooter from "./TableFooter";
17
+ import TableBody from "./GridBody";
18
+ import TableHeader from "./GridHeader";
19
+ import TableFooter from "./GridFooter";
18
20
  import { useGridVirtualizer } from "../GridVirtualizerContext";
19
21
  function VirtualGridCore(props) {
20
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;
21
- var _f = useGridVirtualizer(), tableRef = _f.tableRef, onProcessShadowVisible = _f.onProcessShadowVisible;
23
+ var _f = useGridVirtualizer(), tableRef = _f.tableRef, getTotalSize = _f.getTotalSize, onProcessShadowVisible = _f.onProcessShadowVisible;
22
24
  return (_jsx(TableContainer, __assign({ ref: tableRef, onScroll: onProcessShadowVisible, sx: {
23
25
  maxHeight: "inherit",
24
26
  borderWidth: "thin",
@@ -27,6 +29,6 @@ function VirtualGridCore(props) {
27
29
  borderRadius: "4px",
28
30
  borderCollapse: "unset !important",
29
31
  transition: "all 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms",
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, {}))] })) })));
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, {}))] })) })) })));
31
33
  }
32
- export default VirtualGridCore;
34
+ export default memo(VirtualGridCore);
@@ -10,7 +10,7 @@ var __assign = (this && this.__assign) || function () {
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
- import { useRef, useState, useEffect, useContext, useCallback, createContext, } from "react";
13
+ import { useRef, useMemo, useState, useEffect, useContext, useCallback, createContext, } from "react";
14
14
  import { useVirtualizer, elementScroll } from "@tanstack/react-virtual";
15
15
  var PI = 3.1415965359;
16
16
  function easeInOutQuint(t) {
@@ -28,7 +28,7 @@ var GridVirtualizerContext = createContext({
28
28
  onProcessShadowVisible: function () { },
29
29
  });
30
30
  export function GridVirtualizerContextProvider(props) {
31
- var children = props.children, rows = props.rows, columns = props.columns, dense = props.dense;
31
+ var children = props.children, rows = props.rows, columns = props.columns, dense = props.dense, estimateRowHeight = props.estimateRowHeight;
32
32
  var tableRef = useRef(null);
33
33
  var scrollingRef = useRef();
34
34
  var scrollToFn = useCallback(function (offset, canSmooth, instance) {
@@ -53,15 +53,18 @@ export function GridVirtualizerContextProvider(props) {
53
53
  };
54
54
  requestAnimationFrame(run);
55
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
+ }, []);
56
62
  var rowVirtualizer = useVirtualizer({
57
63
  count: rows.length,
58
64
  getScrollElement: function () { return tableRef.current; },
59
- estimateSize: function () { return (dense ? 48 : 72); },
60
- measureElement: typeof window !== "undefined" &&
61
- navigator.userAgent.indexOf("Firefox") === -1
62
- ? function (element) { return element === null || element === void 0 ? void 0 : element.getBoundingClientRect().height; }
63
- : undefined,
64
- overscan: Math.round(rows.length / PI),
65
+ estimateSize: function () { return estimateRowHeight || (dense ? 48 : 72); },
66
+ measureElement: measureElementHeight,
67
+ overscan: Math.round(rows.length / (2 * PI)),
65
68
  scrollToFn: scrollToFn,
66
69
  });
67
70
  var _a = useState(false), leftShadowVisible = _a[0], setLeftShadowVisible = _a[1];
@@ -27,9 +27,9 @@ import useVirtualGrid from "./useVirtualGrid";
27
27
  import VirtualGridCore from "./GridCore";
28
28
  import { GridVirtualizerContextProvider } from "./GridVirtualizerContext";
29
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"]);
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
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 })) })) })));
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
33
  }
34
34
  export default VirtualGrid;
35
35
  export * from "./types";
@@ -79,10 +79,9 @@ export declare type VirtualGridFooterProps<RowProps extends Record<string, any>,
79
79
  };
80
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
81
  dense?: boolean;
82
- primaryColor?: CSSProperties["color"];
83
- secondaryColor?: CSSProperties["color"];
84
82
  };
85
83
  export declare type VirtualGridProps<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>> = VirtualGridCoreProps<RowProps, ExtendedProps> & {
84
+ estimateRowHeight?: number;
86
85
  primaryColor?: CSSProperties["color"];
87
86
  secondaryColor?: CSSProperties["color"];
88
87
  };
@@ -90,6 +89,7 @@ export interface GridVirtualizerContextProviderProps<RowProps extends Record<str
90
89
  dense?: boolean;
91
90
  children: ReactNode;
92
91
  rows: Array<RowProps>;
92
+ estimateRowHeight?: number;
93
93
  columns: Array<VirtualGridBodyCellProps<RowProps, ExtendedProps>>;
94
94
  }
95
95
  export interface IGridVirtualizerContext {
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 "./VirtualDataTable";
32
33
  export * from "./VirtualGrid";
33
34
  export { default as AlertDialog } from "./AlertDialog";
34
35
  export { default as Autocomplete } from "./Autocomplete";
@@ -58,4 +59,5 @@ export { default as TabGroup } from "./TabGroup";
58
59
  export { default as TablePagination } from "./TablePagination";
59
60
  export { default as TextInput } from "./TextInput";
60
61
  export { default as VideoPlayerModal } from "./VideoPlayerModal";
62
+ export { default as VirtualDataTable } from "./VirtualDataTable";
61
63
  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 "./VirtualDataTable";
32
33
  export * from "./VirtualGrid";
33
34
  export { default as AlertDialog } from "./AlertDialog";
34
35
  export { default as Autocomplete } from "./Autocomplete";
@@ -58,4 +59,5 @@ export { default as TabGroup } from "./TabGroup";
58
59
  export { default as TablePagination } from "./TablePagination";
59
60
  export { default as TextInput } from "./TextInput";
60
61
  export { default as VideoPlayerModal } from "./VideoPlayerModal";
62
+ export { default as VirtualDataTable } from "./VirtualDataTable";
61
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-alpha.1",
3
+ "version": "1.7.0-alpha.3",
4
4
  "description": "Basic and reusable components for all frontend of Symply apps",
5
5
  "keywords": [
6
6
  "react",
@@ -60,6 +60,7 @@
60
60
  "color-alpha": "^1.1.3",
61
61
  "react-dropzone": "14.2.3",
62
62
  "react-player": "2.11.0",
63
+ "react-virtuoso": "^4.12.0",
63
64
  "rifm": "^0.12.1"
64
65
  },
65
66
  "resolutions": {
@@ -1,3 +0,0 @@
1
- import type { VirtualGridBodyRowProps } from "../types";
2
- declare function TableBodyRow<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>>(props: VirtualGridBodyRowProps<RowProps, ExtendedProps>): import("react/jsx-runtime").JSX.Element;
3
- export default TableBodyRow;
@@ -1,5 +0,0 @@
1
- /// <reference types="react" />
2
- import type { VirtualGridFooterProps } from "../types";
3
- declare function TableFooter<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>>(props: VirtualGridFooterProps<RowProps, ExtendedProps>): import("react/jsx-runtime").JSX.Element;
4
- declare const _default: import("react").MemoExoticComponent<typeof TableFooter>;
5
- export default _default;
@@ -1,5 +0,0 @@
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;