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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/DataTable/{TableCore/TableBody.d.ts → TableBody.d.ts} +1 -1
  2. package/DataTable/TableBody.js +32 -0
  3. package/DataTable/{TableCore/TableBodyRow.d.ts → TableBodyRow.d.ts} +1 -1
  4. package/DataTable/TableBodyRow.js +123 -0
  5. package/DataTable/TableFooter.d.ts +3 -0
  6. package/DataTable/{TableCore/TableFooter.js → TableFooter.js} +5 -7
  7. package/DataTable/TableHeader.d.ts +3 -0
  8. package/DataTable/{TableCore/TableHeader.js → TableHeader.js} +5 -7
  9. package/DataTable/index.js +42 -16
  10. package/DataTable/types.d.ts +10 -23
  11. package/DataTable/useTable.d.ts +2 -2
  12. package/DataTable/useTable.js +3 -3
  13. package/README.md +71 -0
  14. package/VirtualGrid/GridCore/TableBody.d.ts +3 -0
  15. package/{DataTable/TableCore → VirtualGrid/GridCore}/TableBody.js +11 -6
  16. package/VirtualGrid/GridCore/TableBodyRow.d.ts +3 -0
  17. package/{DataTable/TableCore → VirtualGrid/GridCore}/TableBodyRow.js +11 -6
  18. package/VirtualGrid/GridCore/TableFooter.d.ts +5 -0
  19. package/VirtualGrid/GridCore/TableFooter.js +114 -0
  20. package/VirtualGrid/GridCore/TableHeader.d.ts +5 -0
  21. package/VirtualGrid/GridCore/TableHeader.js +118 -0
  22. package/VirtualGrid/GridCore/index.d.ts +3 -0
  23. package/{DataTable/TableCore → VirtualGrid/GridCore}/index.js +4 -4
  24. package/VirtualGrid/GridVirtualizerContext.d.ts +3 -0
  25. package/{DataTable/VirtualizerContext.js → VirtualGrid/GridVirtualizerContext.js} +14 -9
  26. package/VirtualGrid/index.d.ts +6 -0
  27. package/VirtualGrid/index.js +36 -0
  28. package/VirtualGrid/types.d.ts +104 -0
  29. package/VirtualGrid/types.js +1 -0
  30. package/VirtualGrid/useVirtualGrid.d.ts +3 -0
  31. package/VirtualGrid/useVirtualGrid.js +103 -0
  32. package/index.d.ts +2 -0
  33. package/index.js +2 -0
  34. package/package.json +1 -1
  35. package/DataTable/TableCore/TableFooter.d.ts +0 -5
  36. package/DataTable/TableCore/TableHeader.d.ts +0 -5
  37. package/DataTable/TableCore/index.d.ts +0 -3
  38. package/DataTable/VirtualizerContext.d.ts +0 -3
@@ -1,3 +1,3 @@
1
- import type { TableBodyProps, KvProps } from "../types";
1
+ import type { TableBodyProps, KvProps } from "./types";
2
2
  declare function TBody<RowProps extends KvProps, ExtendedProps extends KvProps>(props: TableBodyProps<RowProps, ExtendedProps>): import("react/jsx-runtime").JSX.Element;
3
3
  export default TBody;
@@ -0,0 +1,32 @@
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 TableRow from "@mui/material/TableRow";
25
+ import TableBody from "@mui/material/TableBody";
26
+ import TableCell from "@mui/material/TableCell";
27
+ import TableBodyRow from "./TableBodyRow";
28
+ function TBody(props) {
29
+ var rows = props.rows, columns = props.columns, _a = props.noDataText, noDataText = _a === void 0 ? "No Data!" : _a, rest = __rest(props, ["rows", "columns", "noDataText"]);
30
+ return (_jsx(TableBody, { children: rows.length > 0 ? (rows.map(function (row, index) { return (_jsx(TableBodyRow, __assign({ rowIndex: index, row: row, rows: rows, columns: columns }, rest), "DataTable_".concat(index))); })) : (_jsx(TableRow, { children: _jsx(TableCell, __assign({ colSpan: columns.length, align: "center" }, { children: noDataText })) })) }));
31
+ }
32
+ export default TBody;
@@ -1,3 +1,3 @@
1
- import type { TableBodyRowProps, KvProps } from "../types";
1
+ import type { TableBodyRowProps, KvProps } from "./types";
2
2
  declare function TableBodyRow<RowProps extends KvProps, ExtendedProps extends KvProps>(props: TableBodyRowProps<RowProps, ExtendedProps>): import("react/jsx-runtime").JSX.Element;
3
3
  export default TableBodyRow;
@@ -0,0 +1,123 @@
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 { 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
+ function TableBodyRow(props) {
19
+ var row = props.row, rows = props.rows, columns = props.columns, rowIndex = props.rowIndex, leftShadowVisible = props.leftShadowVisible, rightShadowVisible = props.rightShadowVisible, onRowClick = props.onRowClick, onContextMenu = props.onContextMenu, onCustomizeRowBgColor = props.onCustomizeRowBgColor;
20
+ var _a = useState(), rowEl = _a[0], setRowEl = _a[1];
21
+ var theme = useTheme();
22
+ var isUpMd = useMediaQuery(theme.breakpoints.up("md"));
23
+ var _b = useMemo(function () {
24
+ if (isUpMd) {
25
+ var left = columns.filter(function (c) { return c.fixable === "left"; });
26
+ var right = columns.filter(function (c) { return c.fixable === "right"; });
27
+ var dynamic = columns.filter(function (c) { return !c.fixable; });
28
+ return [left, dynamic, right];
29
+ }
30
+ else {
31
+ return [[], columns, []];
32
+ }
33
+ }, [isUpMd, columns]), fixedLeftCols = _b[0], dynamicCols = _b[1], fixedRightCols = _b[2];
34
+ var _c = useMemo(function () {
35
+ if (onCustomizeRowBgColor) {
36
+ var regex = /^#(\d|[a-f]|[A-F]){6}/i;
37
+ var _a = onCustomizeRowBgColor({ row: row, columns: columns }), normal_1 = _a.normal, hover_1 = _a.hover;
38
+ return {
39
+ normal: normal_1 && regex.test(normal_1) ? normal_1 : "#FEFEFE",
40
+ hover: hover_1 && regex.test(hover_1) ? hover_1 : "#F2F1F3"
41
+ };
42
+ }
43
+ return { normal: "#FEFEFE", hover: "#F2F1F3" };
44
+ }, [row, columns, onCustomizeRowBgColor]), normal = _c.normal, hover = _c.hover;
45
+ return (_jsxs(TableRow, __assign({ sx: {
46
+ backgroundColor: normal,
47
+ "&:hover": {
48
+ cursor: onRowClick ? "pointer" : "default",
49
+ backgroundColor: onRowClick ? hover : normal
50
+ }
51
+ }, onMouseEnter: function (event) {
52
+ setRowEl(event.currentTarget);
53
+ }, onMouseLeave: function () {
54
+ setRowEl(undefined);
55
+ }, onClick: onRowClick
56
+ ? function () {
57
+ onRowClick(row);
58
+ }
59
+ : undefined, onContextMenu: function (event) {
60
+ event.preventDefault();
61
+ if (onContextMenu) {
62
+ onContextMenu(event, row);
63
+ }
64
+ } }, { children: [fixedLeftCols.map(function (col, index) {
65
+ var accessor = col.accessor, Cell = col.Cell, width = col.width, _a = col.align, align = _a === void 0 ? "center" : _a;
66
+ var left = fixedLeftCols
67
+ .slice(0, index)
68
+ .reduce(function (w, t) { return w + (t.width || 0); }, 0);
69
+ return (_jsx(TableCell, __assign({ align: align, sx: {
70
+ width: width,
71
+ left: left,
72
+ position: "sticky",
73
+ zIndex: 10,
74
+ backgroundColor: onRowClick && rowEl ? hover : normal,
75
+ "&::after": index === fixedLeftCols.length - 1 && leftShadowVisible
76
+ ? {
77
+ position: "absolute",
78
+ top: 0,
79
+ right: 0,
80
+ bottom: "-1px",
81
+ width: "20px",
82
+ transform: "translateX(100%)",
83
+ transition: "box-shadow .3s",
84
+ content: "''",
85
+ boxShadow: "inset 10px 0 10px -8px rgba(0, 0, 0, 0.1)"
86
+ }
87
+ : undefined
88
+ } }, { children: cloneElement(Cell, { column: col, rows: rows, row: row, rowIndex: rowIndex }) }), accessor));
89
+ }), dynamicCols.map(function (col) {
90
+ var accessor = col.accessor, Cell = col.Cell, width = col.width, _a = col.align, align = _a === void 0 ? "center" : _a;
91
+ return (_jsx(TableCell, __assign({ align: align, sx: {
92
+ width: width,
93
+ zIndex: 9,
94
+ backgroundColor: onRowClick && rowEl ? hover : normal
95
+ } }, { children: cloneElement(Cell, { column: col, rows: rows, row: row, rowIndex: rowIndex }) }), accessor));
96
+ }), fixedRightCols.map(function (col, index) {
97
+ var accessor = col.accessor, Cell = col.Cell, width = col.width, _a = col.align, align = _a === void 0 ? "center" : _a;
98
+ var right = fixedRightCols
99
+ .slice(0, fixedRightCols.length - 1 - index)
100
+ .reduce(function (w, t) { return w + (t.width || 0); }, 0);
101
+ return (_jsx(TableCell, __assign({ align: align, sx: {
102
+ width: width,
103
+ right: right,
104
+ position: "sticky",
105
+ zIndex: 10,
106
+ backgroundColor: onRowClick && rowEl ? hover : normal,
107
+ "&::after": index === 0 && rightShadowVisible
108
+ ? {
109
+ position: "absolute",
110
+ top: 0,
111
+ left: 0,
112
+ bottom: "-1px",
113
+ width: "20px",
114
+ transform: "translateX(-100%)",
115
+ transition: "box-shadow .3s",
116
+ content: "''",
117
+ boxShadow: "inset -10px 0 10px -8px rgba(0, 0, 0, 0.1)"
118
+ }
119
+ : undefined
120
+ } }, { children: cloneElement(Cell, { column: col, rows: rows, row: row, rowIndex: rowIndex }) }), accessor));
121
+ })] })));
122
+ }
123
+ export default TableBodyRow;
@@ -0,0 +1,3 @@
1
+ import type { TableFooterProps, KvProps } from "./types";
2
+ declare function TableFooter<RowProps extends KvProps, ExtendedProps extends KvProps>(props: TableFooterProps<RowProps, ExtendedProps>): import("react/jsx-runtime").JSX.Element;
3
+ export default TableFooter;
@@ -10,19 +10,17 @@ 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 { memo, cloneElement, useMemo } from "react";
13
+ import { cloneElement, useMemo } from "react";
14
14
  import TableRow from "@mui/material/TableRow";
15
15
  import Footer from "@mui/material/TableFooter";
16
16
  import TableCell from "@mui/material/TableCell";
17
17
  import useMediaQuery from "@mui/material/useMediaQuery";
18
18
  import useTheme from "@mui/material/styles/useTheme";
19
- import { useTableVirtualizer } from "../VirtualizerContext";
20
19
  function TableFooter(props) {
21
- var _a = props.footers, footers = _a === void 0 ? [] : _a, footerBgColor = props.footerBgColor, footerTextColor = props.footerTextColor, noData = props.noData;
20
+ var _a = props.footers, footers = _a === void 0 ? [] : _a, footerBgColor = props.footerBgColor, footerTextColor = props.footerTextColor, noData = props.noData, leftShadowVisible = props.leftShadowVisible, rightShadowVisible = props.rightShadowVisible;
22
21
  var theme = useTheme();
23
22
  var isUpMd = useMediaQuery(theme.breakpoints.up("md"));
24
- var _b = useTableVirtualizer(), leftShadowVisible = _b.leftShadowVisible, rightShadowVisible = _b.rightShadowVisible;
25
- var _c = useMemo(function () {
23
+ var _b = useMemo(function () {
26
24
  if (isUpMd && !noData) {
27
25
  var left = footers.filter(function (f) { return f.fixable === "left"; });
28
26
  var right = footers.filter(function (f) { return f.fixable === "right"; });
@@ -32,7 +30,7 @@ function TableFooter(props) {
32
30
  else {
33
31
  return [[], footers, []];
34
32
  }
35
- }, [isUpMd, noData, footers]), fixedLeftFooters = _c[0], dynamicFooters = _c[1], fixedRightFooters = _c[2];
33
+ }, [isUpMd, noData, footers]), fixedLeftFooters = _b[0], dynamicFooters = _b[1], fixedRightFooters = _b[2];
36
34
  return (_jsx(Footer, __assign({ sx: { position: "sticky", bottom: "-1px", zIndex: 20 } }, { children: _jsxs(TableRow, __assign({ sx: {
37
35
  backgroundColor: "".concat(footerBgColor || "#eaf0f6", " !important"),
38
36
  color: "".concat(footerTextColor || "inherit", " !important"),
@@ -101,4 +99,4 @@ function TableFooter(props) {
101
99
  } }, { children: cloneElement(Cell) }), accessor));
102
100
  })] })) })));
103
101
  }
104
- export default memo(TableFooter);
102
+ export default TableFooter;
@@ -0,0 +1,3 @@
1
+ import type { TableHeaderProps, KvProps } from "./types";
2
+ declare function TableHeader<RowProps extends KvProps, ExtendedProps extends KvProps>(props: TableHeaderProps<RowProps, ExtendedProps>): import("react/jsx-runtime").JSX.Element;
3
+ export default TableHeader;
@@ -10,19 +10,17 @@ 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 { memo, cloneElement, useMemo } from "react";
13
+ import { cloneElement, useMemo } from "react";
14
14
  import TableRow from "@mui/material/TableRow";
15
15
  import TableHead from "@mui/material/TableHead";
16
16
  import TableCell from "@mui/material/TableCell";
17
17
  import useMediaQuery from "@mui/material/useMediaQuery";
18
18
  import useTheme from "@mui/material/styles/useTheme";
19
- import { useTableVirtualizer } from "../VirtualizerContext";
20
19
  function TableHeader(props) {
21
- var headers = props.headers, headerBgColor = props.headerBgColor, headerTextColor = props.headerTextColor, noData = props.noData;
20
+ var headers = props.headers, headerBgColor = props.headerBgColor, headerTextColor = props.headerTextColor, noData = props.noData, leftShadowVisible = props.leftShadowVisible, rightShadowVisible = props.rightShadowVisible;
22
21
  var theme = useTheme();
23
22
  var isUpMd = useMediaQuery(theme.breakpoints.up("md"));
24
- var _a = useTableVirtualizer(), leftShadowVisible = _a.leftShadowVisible, rightShadowVisible = _a.rightShadowVisible;
25
- var _b = useMemo(function () {
23
+ var _a = useMemo(function () {
26
24
  if (isUpMd && !noData) {
27
25
  var left = headers.filter(function (h) { return h.fixable === "left"; });
28
26
  var right = headers.filter(function (h) { return h.fixable === "right"; });
@@ -32,7 +30,7 @@ function TableHeader(props) {
32
30
  else {
33
31
  return [[], headers, []];
34
32
  }
35
- }, [isUpMd, noData, headers]), fixedLeftHeaders = _b[0], dynamicHeaders = _b[1], fixedRightHeaders = _b[2];
33
+ }, [isUpMd, noData, headers]), fixedLeftHeaders = _a[0], dynamicHeaders = _a[1], fixedRightHeaders = _a[2];
36
34
  return (_jsx(TableHead, __assign({ sx: { position: "sticky", top: 0, zIndex: 20 } }, { children: _jsxs(TableRow, __assign({ sx: {
37
35
  backgroundColor: "".concat(headerBgColor || "#eaf0f6", " !important"),
38
36
  color: "".concat(headerTextColor || "inherit", " !important"),
@@ -110,4 +108,4 @@ function TableHeader(props) {
110
108
  } }, { children: cloneElement(Cell) }), accessor));
111
109
  })] })) })));
112
110
  }
113
- export default memo(TableHeader);
111
+ export default TableHeader;
@@ -9,27 +9,53 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
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";
12
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { useState, useCallback, useRef, useEffect } from "react";
14
+ import Table from "@mui/material/Table";
15
+ import TableContainer from "@mui/material/TableContainer";
24
16
  import ThemeProvider from "@mui/material/styles/ThemeProvider";
25
17
  import useCustomTheme from "../useCustomTheme";
26
18
  import useDataTable from "./useTable";
27
- import TableCore from "./TableCore";
28
- import { VirtualizerContextProvider } from "./VirtualizerContext";
19
+ import TableBody from "./TableBody";
20
+ import TableHeader from "./TableHeader";
21
+ import TableFooter from "./TableFooter";
29
22
  function DataTable(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"]);
23
+ var _a = props.columns, columns = _a === void 0 ? [] : _a, _b = props.rows, rows = _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, dense = props.dense, headerBgColor = props.headerBgColor, headerTextColor = props.headerTextColor, footerBgColor = props.footerBgColor, footerTextColor = props.footerTextColor, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor, onRowClick = props.onRowClick, onContextMenu = props.onContextMenu, onCustomizeRowBgColor = props.onCustomizeRowBgColor;
31
24
  var theme = useCustomTheme({ primaryColor: primaryColor, secondaryColor: secondaryColor });
32
- return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsx(VirtualizerContextProvider, __assign({ rows: rows, columns: columns, dense: dense }, { children: _jsx(TableCore, __assign({}, rest, { rows: rows, columns: columns, dense: dense })) })) })));
25
+ var tableRef = useRef(null);
26
+ var _f = useState(false), leftShadowVisible = _f[0], setLeftShadowVisible = _f[1];
27
+ var _g = useState(false), rightShadowVisible = _g[0], setRightShadowVisible = _g[1];
28
+ var onProcessShadowVisible = useCallback(function () {
29
+ if (tableRef.current) {
30
+ var target = tableRef.current;
31
+ var scrollLeft = target.scrollLeft;
32
+ var scrollWidth = target.scrollWidth;
33
+ var clientWidth = target.clientWidth;
34
+ var hasScrollBar = scrollWidth > clientWidth;
35
+ setLeftShadowVisible(hasScrollBar && scrollLeft > 0);
36
+ setRightShadowVisible(hasScrollBar && scrollWidth - scrollLeft > clientWidth + 1);
37
+ }
38
+ }, []);
39
+ useEffect(function () {
40
+ if (columns) {
41
+ onProcessShadowVisible();
42
+ }
43
+ }, [columns, onProcessShadowVisible]);
44
+ useEffect(function () {
45
+ window.addEventListener("resize", onProcessShadowVisible);
46
+ }, [onProcessShadowVisible]);
47
+ useEffect(function () { return function () {
48
+ window.removeEventListener("scroll", onProcessShadowVisible);
49
+ }; }, [onProcessShadowVisible]);
50
+ return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsx(TableContainer, __assign({ ref: tableRef, onScroll: onProcessShadowVisible, sx: {
51
+ maxHeight: "inherit",
52
+ borderWidth: "thin",
53
+ borderColor: "#e5e5e5",
54
+ borderStyle: "solid",
55
+ borderRadius: "4px",
56
+ borderCollapse: "unset !important",
57
+ transition: "all 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms",
58
+ } }, { 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, leftShadowVisible: leftShadowVisible, rightShadowVisible: rightShadowVisible }), _jsx(TableBody, { rows: rows, columns: columns, noDataText: noDataText, onRowClick: onRowClick, onContextMenu: onContextMenu, onCustomizeRowBgColor: onCustomizeRowBgColor, leftShadowVisible: leftShadowVisible, rightShadowVisible: rightShadowVisible }), (footers === null || footers === void 0 ? void 0 : footers.length) > 0 ? (_jsx(TableFooter, { footers: footers, footerBgColor: footerBgColor, footerTextColor: footerTextColor, noData: rows.length === 0, leftShadowVisible: leftShadowVisible, rightShadowVisible: rightShadowVisible })) : (_jsx(_Fragment, {}))] })) })) })));
33
59
  }
34
60
  export default DataTable;
35
61
  export * from "./types";
@@ -1,5 +1,4 @@
1
- import type { ReactNode, RefObject, MouseEvent, ReactElement, CSSProperties } from "react";
2
- import type { VirtualItem } from "@tanstack/react-virtual";
1
+ import type { ReactElement, CSSProperties, MouseEvent } from "react";
3
2
  declare type HexColor = `#${string}`;
4
3
  export declare type CustomRowBgColor = {
5
4
  normal?: HexColor;
@@ -44,7 +43,7 @@ export declare type TableBodyCellProps<RowProps extends KvProps, ExtendedProps e
44
43
  export declare type TableFooterCellProps<RowProps extends KvProps, ExtendedProps extends KvProps> = Pick<ColumnProps, "align" | "accessor" | "fixable" | "width"> & Omit<UseTableProps<RowProps, ExtendedProps>, keyof UseTableBaseProps<RowProps>> & {
45
44
  Cell: ReactElement;
46
45
  };
47
- export declare type UseTableReturns<RowProps extends KvProps, ExtendedProps extends KvProps> = {
46
+ export declare type UserTableReturns<RowProps extends KvProps, ExtendedProps extends KvProps> = {
48
47
  headers: Array<TableHeaderCellProps<RowProps, ExtendedProps>>;
49
48
  footers: Array<TableFooterCellProps<RowProps, ExtendedProps>>;
50
49
  columns: Array<TableBodyCellProps<RowProps, ExtendedProps>>;
@@ -56,10 +55,14 @@ export declare type TableHeaderProps<RowProps extends KvProps, ExtendedProps ext
56
55
  headerBgColor?: CSSProperties["color"];
57
56
  headerTextColor?: CSSProperties["color"];
58
57
  noData?: boolean;
58
+ leftShadowVisible?: boolean;
59
+ rightShadowVisible?: boolean;
59
60
  };
60
61
  export declare type TableBodyProps<RowProps extends KvProps, ExtendedProps extends KvProps> = {
61
62
  columns: Array<TableBodyCellProps<RowProps, ExtendedProps>>;
62
63
  rows: Array<RowProps>;
64
+ leftShadowVisible?: boolean;
65
+ rightShadowVisible?: boolean;
63
66
  noDataText?: string;
64
67
  onRowClick?: (row: RowProps) => unknown;
65
68
  onContextMenu?: (event: MouseEvent<HTMLTableRowElement>, row: RowProps) => unknown;
@@ -69,36 +72,20 @@ export declare type TableBodyProps<RowProps extends KvProps, ExtendedProps exten
69
72
  }) => CustomRowBgColor;
70
73
  };
71
74
  export declare type TableBodyRowProps<RowProps extends KvProps, ExtendedProps extends KvProps> = Omit<TableBodyProps<RowProps, ExtendedProps>, "noDataText"> & {
75
+ row: RowProps;
72
76
  rowIndex: number;
73
- virtualRow: VirtualItem;
74
77
  };
75
78
  export declare type TableFooterProps<RowProps extends KvProps, ExtendedProps extends KvProps> = {
76
79
  footers?: Array<TableFooterCellProps<RowProps, ExtendedProps>>;
77
80
  footerBgColor?: CSSProperties["color"];
78
81
  footerTextColor?: CSSProperties["color"];
79
82
  noData?: boolean;
83
+ leftShadowVisible?: boolean;
84
+ rightShadowVisible?: boolean;
80
85
  };
81
- export declare type DataTableCoreProps<RowProps extends KvProps, ExtendedProps extends KvProps> = Omit<TableHeaderProps<RowProps, ExtendedProps>, "noData"> & TableBodyProps<RowProps, ExtendedProps> & Omit<TableFooterProps<RowProps, ExtendedProps>, "noData"> & {
86
+ export declare type DataTableProps<RowProps extends KvProps, ExtendedProps extends KvProps> = Omit<TableHeaderProps<RowProps, ExtendedProps>, "leftShadowVisible" | "rightShadowVisible" | "noData"> & Omit<TableBodyProps<RowProps, ExtendedProps>, "leftShadowVisible" | "rightShadowVisible"> & Omit<TableFooterProps<RowProps, ExtendedProps>, "leftShadowVisible" | "rightShadowVisible" | "noData"> & {
82
87
  dense?: boolean;
83
88
  primaryColor?: CSSProperties["color"];
84
89
  secondaryColor?: CSSProperties["color"];
85
90
  };
86
- export declare type DataTableProps<RowProps extends KvProps, ExtendedProps extends KvProps> = DataTableCoreProps<RowProps, ExtendedProps> & {
87
- primaryColor?: CSSProperties["color"];
88
- secondaryColor?: CSSProperties["color"];
89
- };
90
- export interface VirtualizerContextProviderProps<RowProps extends KvProps, ExtendedProps extends KvProps> {
91
- dense?: boolean;
92
- children: ReactNode;
93
- rows: Array<RowProps>;
94
- columns: Array<TableBodyCellProps<RowProps, ExtendedProps>>;
95
- }
96
- export interface IVirtualizerContext {
97
- tableRef: RefObject<HTMLDivElement>;
98
- virtualRows: Array<VirtualItem>;
99
- leftShadowVisible: boolean;
100
- rightShadowVisible: boolean;
101
- onMeasureElement: (node: Element | null | undefined) => void;
102
- onProcessShadowVisible: () => void;
103
- }
104
91
  export {};
@@ -1,3 +1,3 @@
1
- import type { KvProps, UseTableProps, UseTableReturns } from "./types";
2
- declare function useTable<T extends KvProps, F extends KvProps>(props: UseTableProps<T, F>): UseTableReturns<T, F>;
1
+ import type { UseTableProps, KvProps, UserTableReturns } from "./types";
2
+ declare function useTable<T extends KvProps, F extends KvProps>(props: UseTableProps<T, F>): UserTableReturns<T, F>;
3
3
  export default useTable;
@@ -35,7 +35,7 @@ function useTable(props) {
35
35
  var _a = sortBy || {}, accessor = _a.accessor, order = _a.order;
36
36
  return {
37
37
  accessor: accessor || "",
38
- order: !!accessor ? order || "NONE" : "NONE"
38
+ order: !!accessor ? order || "NONE" : "NONE",
39
39
  };
40
40
  }, [initialState]);
41
41
  var _a = useState(initialSortingProps), sortingProps = _a[0], setSortingProps = _a[1];
@@ -75,7 +75,7 @@ function useTable(props) {
75
75
  }
76
76
  return "↓";
77
77
  }, [sortingProps]);
78
- var rows = useMemo(function () { return data.map(function (d) { return d; }); }, [data]);
78
+ var rows = useMemo(function () { return data.map(function (d) { return (__assign({}, d)); }); }, [data]);
79
79
  var cols = useMemo(function () {
80
80
  return columns.map(function (col) {
81
81
  var Body = col.Body;
@@ -94,7 +94,7 @@ function useTable(props) {
94
94
  var Footer = col.Footer;
95
95
  return __assign(__assign({ Cell: cloneElement(Footer || _jsx(_Fragment, {}), {
96
96
  column: col,
97
- rows: rows
97
+ rows: rows,
98
98
  }) }, col), rest);
99
99
  });
100
100
  }, [columns, rest, rows]);
package/README.md CHANGED
@@ -968,6 +968,77 @@ import VideoPlayerModal from '@symply.io/basic-components/VideoPlayerModal';
968
968
 
969
969
 
970
970
 
971
+ <h3>VirtualGird</h3>
972
+
973
+ Reusable data grid component with virtualizer
974
+
975
+ <h5>Import</h5>
976
+
977
+ ```tsx
978
+ import { VirtualGird, useVirtualGrid } from '@symply.io/basic-components';
979
+ // or
980
+ import VirtualGird, { useVirtualGird } from '@symply.io/basic-components/VirtualGird';
981
+ ```
982
+
983
+ <h5>Column Props</h5>
984
+
985
+ | Name | Type | Default | Required | Description |
986
+ | --------- | ----------------------------- | ------- | -------- | ------------------------------------------------------------ |
987
+ | accessor | string | | true | The key of the column, it should be unique. |
988
+ | align | "left" \|"center" \|"right" | | false | The alignment of the column. |
989
+ | Body | ReactElement | | true | The component to render the column body cell. |
990
+ | fixable | "left" \| "right" \|undefined | | false | If not undefined, the column can be frozen. <br/>⚠️ It doesn't work with IE11. |
991
+ | Footer | ReactElement | | false | The component to render the column footer cell. |
992
+ | Header | ReactElement | | true | The component to render the column header cell. |
993
+ | headerTip | string | | false | The tip title text when the mouse is over the header. |
994
+ | sortable | bool | | false | If true, the column can be sortable. |
995
+ | width | number | | false | The fixed width of cells. |
996
+
997
+ <h5>Sorting Props</h5>
998
+
999
+ | Name | Type | Default | Required | Description |
1000
+ | -------- | ------------------------- | ------- | -------- | ---------------------- |
1001
+ | accessor | string | | true | The key of the column. |
1002
+ | order | "ASC" \| "DESC" \| "NONE" | | true | The sorting order. |
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
+
1024
+ <h5>Component Props</h5>
1025
+
1026
+ | Name | Type | Default | Required | Description |
1027
+ | --------------------- | ---------------------- | ---------- | -------- | ------------------------------------------------------------ |
1028
+ | columns | Array | [] | true | The cells for the body. (from the hook) |
1029
+ | dense | bool | | false | If `true` the table size/density would be tight. |
1030
+ | footers | Array | [] | false | The cells for the footer. (from the hook) |
1031
+ | footerBgColor | CSSProperties["color"] | | false | Customized footer background color. |
1032
+ | footerTextColor | CSSProperties["color"] | | false | Customized footer text color. |
1033
+ | headers | Array | | true | The cells for the header. (from the hook) |
1034
+ | headerBgColor | CSSProperties["color"] | | false | Customized header background color. |
1035
+ | headerTextColor | CSSProperties["color"] | | false | Customized header text color. |
1036
+ | noDataText | string | 'No Data!' | false | The text when no data rendered. |
1037
+ | onContextMenu | func | | false | The function for row right-clicking.<br />**Signature:**<br/>`function(event: MouseEvent, row: RowProps) => unknown` |
1038
+ | 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/>}` |
1039
+ | onRowClick | func | | false | The function for row clicking.<br />**Signature:**<br/>`function(row: RowProps) => unknown` |
1040
+ | rows | Array | | true | The rows for the table. (from the hook) |
1041
+
971
1042
 
972
1043
 
973
1044
  <h2>Changelog</h2>
@@ -0,0 +1,3 @@
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
+ export default VirtualGridBody;
@@ -25,12 +25,17 @@ import TableRow from "@mui/material/TableRow";
25
25
  import TableBody from "@mui/material/TableBody";
26
26
  import TableCell from "@mui/material/TableCell";
27
27
  import TableBodyRow from "./TableBodyRow";
28
- import { useTableVirtualizer } from "../VirtualizerContext";
29
- function TBody(props) {
28
+ import { useGridVirtualizer } from "../GridVirtualizerContext";
29
+ function VirtualGridBody(props) {
30
30
  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 virtualRows = useTableVirtualizer().virtualRows;
32
- return (_jsx(TableBody, { children: virtualRows.length > 0 ? (virtualRows.map(function (virtualRow) {
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) {
33
38
  return (_jsx(TableBodyRow, __assign({ rowIndex: virtualRow.index, virtualRow: virtualRow, rows: rows, columns: columns }, rest), "DataTable_".concat(virtualRow.index)));
34
- })) : (_jsx(TableRow, { children: _jsx(TableCell, __assign({ colSpan: columns.length, align: "center" }, { children: noDataText })) })) }));
39
+ })) : (_jsx(TableRow, { children: _jsx(TableCell, __assign({ colSpan: columns.length, align: "center" }, { children: noDataText })) })) })));
35
40
  }
36
- export default TBody;
41
+ export default VirtualGridBody;
@@ -0,0 +1,3 @@
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;
@@ -15,13 +15,13 @@ 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
- import { useTableVirtualizer } from "../VirtualizerContext";
18
+ import { useGridVirtualizer } from "../GridVirtualizerContext";
19
19
  function TableBodyRow(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
21
  var _a = useState(), rowEl = _a[0], setRowEl = _a[1];
22
22
  var theme = useTheme();
23
23
  var isUpMd = useMediaQuery(theme.breakpoints.up("md"));
24
- var _b = useTableVirtualizer(), leftShadowVisible = _b.leftShadowVisible, rightShadowVisible = _b.rightShadowVisible, onMeasureElement = _b.onMeasureElement;
24
+ var _b = useGridVirtualizer(), leftShadowVisible = _b.leftShadowVisible, rightShadowVisible = _b.rightShadowVisible, onMeasureElement = _b.onMeasureElement;
25
25
  var row = useMemo(function () { return rows[virtualRow.index]; }, [rows, virtualRow]);
26
26
  var _c = useMemo(function () {
27
27
  if (isUpMd) {
@@ -48,7 +48,9 @@ function TableBodyRow(props) {
48
48
  return (_jsxs(TableRow, __assign({ sx: {
49
49
  backgroundColor: normal,
50
50
  width: "100%",
51
- transform: "translateY(".concat(virtualRow.start - rowIndex * virtualRow.size, "px)"),
51
+ position: "absolute",
52
+ display: "flex",
53
+ transform: "translateY(".concat(virtualRow.start, "px)"),
52
54
  "&:hover": {
53
55
  cursor: onRowClick ? "pointer" : "default",
54
56
  backgroundColor: onRowClick ? hover : normal,
@@ -72,9 +74,10 @@ function TableBodyRow(props) {
72
74
  .slice(0, index)
73
75
  .reduce(function (w, t) { return w + (t.width || 0); }, 0);
74
76
  return (_jsx(TableCell, __assign({ align: align, sx: {
75
- width: width,
77
+ minWidth: width,
76
78
  left: left,
77
79
  position: "sticky",
80
+ display: "flex",
78
81
  zIndex: 10,
79
82
  backgroundColor: onRowClick && rowEl ? hover : normal,
80
83
  "&::after": index === fixedLeftCols.length - 1 && leftShadowVisible
@@ -94,8 +97,9 @@ function TableBodyRow(props) {
94
97
  }), dynamicCols.map(function (col) {
95
98
  var accessor = col.accessor, Cell = col.Cell, width = col.width, _a = col.align, align = _a === void 0 ? "center" : _a;
96
99
  return (_jsx(TableCell, __assign({ align: align, sx: {
97
- width: width,
100
+ minWidth: width,
98
101
  zIndex: 9,
102
+ display: "flex",
99
103
  backgroundColor: onRowClick && rowEl ? hover : normal,
100
104
  } }, { children: cloneElement(Cell, { column: col, rows: rows, row: row, rowIndex: rowIndex }) }), accessor));
101
105
  }), fixedRightCols.map(function (col, index) {
@@ -104,10 +108,11 @@ function TableBodyRow(props) {
104
108
  .slice(0, fixedRightCols.length - 1 - index)
105
109
  .reduce(function (w, t) { return w + (t.width || 0); }, 0);
106
110
  return (_jsx(TableCell, __assign({ align: align, sx: {
107
- width: width,
111
+ minWidth: width,
108
112
  right: right,
109
113
  position: "sticky",
110
114
  zIndex: 10,
115
+ display: "flex",
111
116
  backgroundColor: onRowClick && rowEl ? hover : normal,
112
117
  "&::after": index === 0 && rightShadowVisible
113
118
  ? {
@@ -0,0 +1,5 @@
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;