@symply.io/basic-components 1.6.10 → 1.6.11-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.
@@ -1,3 +1,3 @@
1
- import { 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;
@@ -26,7 +26,7 @@ import TableBody from "@mui/material/TableBody";
26
26
  import TableCell from "@mui/material/TableCell";
27
27
  import TableBodyRow from "./TableBodyRow";
28
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 })) })) }));
29
+ var rows = props.rows, columns = props.columns, virtualRows = props.virtualRows, _a = props.noDataText, noDataText = _a === void 0 ? "No Data!" : _a, rest = __rest(props, ["rows", "columns", "virtualRows", "noDataText"]);
30
+ return (_jsx(TableBody, { children: virtualRows.length > 0 ? (virtualRows.map(function (row) { return (_jsx(TableBodyRow, __assign({ rowIndex: row.index, row: rows[row.index], rows: rows, columns: columns }, rest), "DataTable_".concat(row.key || row.index))); })) : (_jsx(TableRow, { children: _jsx(TableCell, __assign({ colSpan: columns.length, align: "center" }, { children: noDataText })) })) }));
31
31
  }
32
32
  export default TBody;
@@ -1,3 +1,3 @@
1
- import { 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;
@@ -37,7 +37,7 @@ function TableBodyRow(props) {
37
37
  var _a = onCustomizeRowBgColor({ row: row, columns: columns }), normal_1 = _a.normal, hover_1 = _a.hover;
38
38
  return {
39
39
  normal: normal_1 && regex.test(normal_1) ? normal_1 : "#FEFEFE",
40
- hover: hover_1 && regex.test(hover_1) ? hover_1 : "#F2F1F3"
40
+ hover: hover_1 && regex.test(hover_1) ? hover_1 : "#F2F1F3",
41
41
  };
42
42
  }
43
43
  return { normal: "#FEFEFE", hover: "#F2F1F3" };
@@ -46,8 +46,8 @@ function TableBodyRow(props) {
46
46
  backgroundColor: normal,
47
47
  "&:hover": {
48
48
  cursor: onRowClick ? "pointer" : "default",
49
- backgroundColor: onRowClick ? hover : normal
50
- }
49
+ backgroundColor: onRowClick ? hover : normal,
50
+ },
51
51
  }, onMouseEnter: function (event) {
52
52
  setRowEl(event.currentTarget);
53
53
  }, onMouseLeave: function () {
@@ -82,16 +82,16 @@ function TableBodyRow(props) {
82
82
  transform: "translateX(100%)",
83
83
  transition: "box-shadow .3s",
84
84
  content: "''",
85
- boxShadow: "inset 10px 0 10px -8px rgba(0, 0, 0, 0.1)"
85
+ boxShadow: "inset 10px 0 10px -8px rgba(0, 0, 0, 0.1)",
86
86
  }
87
- : undefined
87
+ : undefined,
88
88
  } }, { children: cloneElement(Cell, { column: col, rows: rows, row: row, rowIndex: rowIndex }) }), accessor));
89
89
  }), dynamicCols.map(function (col) {
90
90
  var accessor = col.accessor, Cell = col.Cell, width = col.width, _a = col.align, align = _a === void 0 ? "center" : _a;
91
91
  return (_jsx(TableCell, __assign({ align: align, sx: {
92
92
  width: width,
93
93
  zIndex: 9,
94
- backgroundColor: onRowClick && rowEl ? hover : normal
94
+ backgroundColor: onRowClick && rowEl ? hover : normal,
95
95
  } }, { children: cloneElement(Cell, { column: col, rows: rows, row: row, rowIndex: rowIndex }) }), accessor));
96
96
  }), fixedRightCols.map(function (col, index) {
97
97
  var accessor = col.accessor, Cell = col.Cell, width = col.width, _a = col.align, align = _a === void 0 ? "center" : _a;
@@ -114,9 +114,9 @@ function TableBodyRow(props) {
114
114
  transform: "translateX(-100%)",
115
115
  transition: "box-shadow .3s",
116
116
  content: "''",
117
- boxShadow: "inset -10px 0 10px -8px rgba(0, 0, 0, 0.1)"
117
+ boxShadow: "inset -10px 0 10px -8px rgba(0, 0, 0, 0.1)",
118
118
  }
119
- : undefined
119
+ : undefined,
120
120
  } }, { children: cloneElement(Cell, { column: col, rows: rows, row: row, rowIndex: rowIndex }) }), accessor));
121
121
  })] })));
122
122
  }
@@ -1,3 +1,5 @@
1
- import { TableFooterProps, KvProps } from "./types";
1
+ /// <reference types="react" />
2
+ import type { TableFooterProps, KvProps } from "./types";
2
3
  declare function TableFooter<RowProps extends KvProps, ExtendedProps extends KvProps>(props: TableFooterProps<RowProps, ExtendedProps>): import("react/jsx-runtime").JSX.Element;
3
- export default TableFooter;
4
+ declare const _default: import("react").MemoExoticComponent<typeof TableFooter>;
5
+ export default _default;
@@ -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, jsxs as _jsxs } from "react/jsx-runtime";
13
- import { cloneElement, useMemo } from "react";
13
+ import { memo, 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";
@@ -99,4 +99,4 @@ function TableFooter(props) {
99
99
  } }, { children: cloneElement(Cell) }), accessor));
100
100
  })] })) })));
101
101
  }
102
- export default TableFooter;
102
+ export default memo(TableFooter);
@@ -1,3 +1,5 @@
1
- import { TableHeaderProps, KvProps } from "./types";
1
+ /// <reference types="react" />
2
+ import type { TableHeaderProps, KvProps } from "./types";
2
3
  declare function TableHeader<RowProps extends KvProps, ExtendedProps extends KvProps>(props: TableHeaderProps<RowProps, ExtendedProps>): import("react/jsx-runtime").JSX.Element;
3
- export default TableHeader;
4
+ declare const _default: import("react").MemoExoticComponent<typeof TableHeader>;
5
+ export default _default;
@@ -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, jsxs as _jsxs } from "react/jsx-runtime";
13
- import { cloneElement, useMemo } from "react";
13
+ import { memo, 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";
@@ -108,4 +108,4 @@ function TableHeader(props) {
108
108
  } }, { children: cloneElement(Cell) }), accessor));
109
109
  })] })) })));
110
110
  }
111
- export default TableHeader;
111
+ export default memo(TableHeader);
@@ -1,5 +1,5 @@
1
1
  import useDataTable from "./useTable";
2
- import { DataTableProps, KvProps } from "./types";
2
+ import type { DataTableProps, KvProps } from "./types";
3
3
  declare function DataTable<RowProps extends KvProps, ExtendedProps extends KvProps>(props: DataTableProps<RowProps, ExtendedProps>): import("react/jsx-runtime").JSX.Element;
4
4
  export default DataTable;
5
5
  export * from "./types";
@@ -14,17 +14,29 @@ import { useState, useCallback, useRef, useEffect } from "react";
14
14
  import Table from "@mui/material/Table";
15
15
  import TableContainer from "@mui/material/TableContainer";
16
16
  import ThemeProvider from "@mui/material/styles/ThemeProvider";
17
+ import { useVirtualizer } from "@tanstack/react-virtual";
17
18
  import useCustomTheme from "../useCustomTheme";
18
19
  import useDataTable from "./useTable";
19
20
  import TableBody from "./TableBody";
20
21
  import TableHeader from "./TableHeader";
21
22
  import TableFooter from "./TableFooter";
22
23
  function DataTable(props) {
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, stickyHeader = props.stickyHeader, 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;
24
+ 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, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor, onRowClick = props.onRowClick, onContextMenu = props.onContextMenu, onCustomizeRowBgColor = props.onCustomizeRowBgColor;
24
25
  var theme = useCustomTheme({ primaryColor: primaryColor, secondaryColor: secondaryColor });
25
26
  var tableRef = useRef(null);
27
+ var rowVirtualizer = useVirtualizer({
28
+ count: rows.length,
29
+ getScrollElement: function () { return tableRef.current; },
30
+ estimateSize: function () { return (dense ? 48 : 64); },
31
+ measureElement: typeof window !== "undefined" &&
32
+ navigator.userAgent.indexOf("Firefox") === -1
33
+ ? function (element) { return element === null || element === void 0 ? void 0 : element.getBoundingClientRect().height; }
34
+ : undefined,
35
+ overscan: 6,
36
+ });
26
37
  var _f = useState(false), leftShadowVisible = _f[0], setLeftShadowVisible = _f[1];
27
38
  var _g = useState(false), rightShadowVisible = _g[0], setRightShadowVisible = _g[1];
39
+ var virtualRows = rowVirtualizer.getVirtualItems();
28
40
  var onProcessShadowVisible = useCallback(function () {
29
41
  if (tableRef.current) {
30
42
  var target = tableRef.current;
@@ -55,7 +67,7 @@ function DataTable(props) {
55
67
  borderRadius: "4px",
56
68
  borderCollapse: "unset !important",
57
69
  transition: "all 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms",
58
- } }, { children: _jsxs(Table, __assign({ sx: { minWidth: 600, tableLayout: "fixed" }, stickyHeader: stickyHeader, 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, {}))] })) })) })));
70
+ } }, { 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, virtualRows: virtualRows, 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, {}))] })) })) })));
59
71
  }
60
72
  export default DataTable;
61
73
  export * from "./types";
@@ -1,4 +1,5 @@
1
- import { ReactElement, CSSProperties, MouseEvent } from "react";
1
+ import type { ReactElement, CSSProperties, MouseEvent } from "react";
2
+ import type { VirtualItem } from "@tanstack/react-virtual";
2
3
  declare type HexColor = `#${string}`;
3
4
  export declare type CustomRowBgColor = {
4
5
  normal?: HexColor;
@@ -43,7 +44,7 @@ export declare type TableBodyCellProps<RowProps extends KvProps, ExtendedProps e
43
44
  export declare type TableFooterCellProps<RowProps extends KvProps, ExtendedProps extends KvProps> = Pick<ColumnProps, "align" | "accessor" | "fixable" | "width"> & Omit<UseTableProps<RowProps, ExtendedProps>, keyof UseTableBaseProps<RowProps>> & {
44
45
  Cell: ReactElement;
45
46
  };
46
- export declare type UserTableReturns<RowProps extends KvProps, ExtendedProps extends KvProps> = {
47
+ export declare type UseTableReturns<RowProps extends KvProps, ExtendedProps extends KvProps> = {
47
48
  headers: Array<TableHeaderCellProps<RowProps, ExtendedProps>>;
48
49
  footers: Array<TableFooterCellProps<RowProps, ExtendedProps>>;
49
50
  columns: Array<TableBodyCellProps<RowProps, ExtendedProps>>;
@@ -61,6 +62,7 @@ export declare type TableHeaderProps<RowProps extends KvProps, ExtendedProps ext
61
62
  export declare type TableBodyProps<RowProps extends KvProps, ExtendedProps extends KvProps> = {
62
63
  columns: Array<TableBodyCellProps<RowProps, ExtendedProps>>;
63
64
  rows: Array<RowProps>;
65
+ virtualRows: Array<VirtualItem>;
64
66
  leftShadowVisible?: boolean;
65
67
  rightShadowVisible?: boolean;
66
68
  noDataText?: string;
@@ -71,7 +73,7 @@ export declare type TableBodyProps<RowProps extends KvProps, ExtendedProps exten
71
73
  columns: Array<TableBodyCellProps<RowProps, ExtendedProps>>;
72
74
  }) => CustomRowBgColor;
73
75
  };
74
- export declare type TableBodyRowProps<RowProps extends KvProps, ExtendedProps extends KvProps> = Omit<TableBodyProps<RowProps, ExtendedProps>, "noDataText"> & {
76
+ export declare type TableBodyRowProps<RowProps extends KvProps, ExtendedProps extends KvProps> = Omit<TableBodyProps<RowProps, ExtendedProps>, "noDataText" | "virtualRows"> & {
75
77
  row: RowProps;
76
78
  rowIndex: number;
77
79
  };
@@ -85,7 +87,6 @@ export declare type TableFooterProps<RowProps extends KvProps, ExtendedProps ext
85
87
  };
86
88
  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"> & {
87
89
  dense?: boolean;
88
- stickyHeader?: boolean;
89
90
  primaryColor?: CSSProperties["color"];
90
91
  secondaryColor?: CSSProperties["color"];
91
92
  };
@@ -1,3 +1,3 @@
1
- import { UseTableProps, KvProps, UserTableReturns } from "./types";
2
- declare function useTable<T extends KvProps, F extends KvProps>(props: UseTableProps<T, F>): UserTableReturns<T, F>;
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>;
3
3
  export default useTable;
@@ -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 (__assign({}, d)); }); }, [data]);
78
+ var rows = useMemo(function () { return data.map(function (d) { return d; }); }, [data]);
79
79
  var cols = useMemo(function () {
80
80
  return columns.map(function (col) {
81
81
  var Body = col.Body;
package/README.md CHANGED
@@ -384,7 +384,6 @@ import DataTable, { useDataTable } from '@symply.io/basic-components/DataTable';
384
384
  | 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/>}` |
385
385
  | onRowClick | func | | false | The function for row clicking.<br />**Signature:**<br/>`function(row: RowProps) => unknown` |
386
386
  | rows | Array<RowProps\> | | true | The rows for the table. (from the hook) |
387
- | stickyHeader | bool | | false | Set the header sticky.<br/>⚠️ It doesn't work with IE11. |
388
387
 
389
388
 
390
389
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symply.io/basic-components",
3
- "version": "1.6.10",
3
+ "version": "1.6.11-alpha.1",
4
4
  "description": "Basic and reusable components for all frontend of Symply apps",
5
5
  "keywords": [
6
6
  "react",
@@ -56,6 +56,7 @@
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",
59
60
  "color-alpha": "^1.1.3",
60
61
  "react-dropzone": "14.2.3",
61
62
  "react-player": "2.11.0",