@symply.io/basic-components 1.6.10 → 1.6.11-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DataTable/TableBody.d.ts +1 -1
- package/DataTable/TableBody.js +4 -2
- package/DataTable/TableBodyRow.d.ts +1 -1
- package/DataTable/TableBodyRow.js +11 -9
- package/DataTable/TableFooter.d.ts +4 -2
- package/DataTable/TableFooter.js +2 -2
- package/DataTable/TableHeader.d.ts +4 -2
- package/DataTable/TableHeader.js +2 -2
- package/DataTable/index.d.ts +1 -1
- package/DataTable/index.js +14 -2
- package/DataTable/types.d.ts +7 -6
- package/DataTable/useTable.d.ts +2 -2
- package/DataTable/useTable.js +1 -1
- package/README.md +0 -1
- package/package.json +2 -1
package/DataTable/TableBody.d.ts
CHANGED
@@ -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;
|
package/DataTable/TableBody.js
CHANGED
@@ -26,7 +26,9 @@ 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:
|
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 (virtualRow) {
|
31
|
+
return (_jsx(TableBodyRow, __assign({ rowIndex: virtualRow.index, virtualRow: virtualRow, rows: rows, columns: columns }, rest), "DataTable_".concat(virtualRow.key || virtualRow.index)));
|
32
|
+
})) : (_jsx(TableRow, { children: _jsx(TableCell, __assign({ colSpan: columns.length, align: "center" }, { children: noDataText })) })) }));
|
31
33
|
}
|
32
34
|
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;
|
@@ -16,10 +16,11 @@ 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
|
function TableBodyRow(props) {
|
19
|
-
var
|
19
|
+
var rows = props.rows, columns = props.columns, rowIndex = props.rowIndex, virtualRow = props.virtualRow, leftShadowVisible = props.leftShadowVisible, rightShadowVisible = props.rightShadowVisible, onRowClick = props.onRowClick, onContextMenu = props.onContextMenu, onCustomizeRowBgColor = props.onCustomizeRowBgColor;
|
20
20
|
var _a = useState(), rowEl = _a[0], setRowEl = _a[1];
|
21
21
|
var theme = useTheme();
|
22
22
|
var isUpMd = useMediaQuery(theme.breakpoints.up("md"));
|
23
|
+
var row = useMemo(function () { return rows[virtualRow.index]; }, [rows, virtualRow]);
|
23
24
|
var _b = useMemo(function () {
|
24
25
|
if (isUpMd) {
|
25
26
|
var left = columns.filter(function (c) { return c.fixable === "left"; });
|
@@ -37,17 +38,18 @@ function TableBodyRow(props) {
|
|
37
38
|
var _a = onCustomizeRowBgColor({ row: row, columns: columns }), normal_1 = _a.normal, hover_1 = _a.hover;
|
38
39
|
return {
|
39
40
|
normal: normal_1 && regex.test(normal_1) ? normal_1 : "#FEFEFE",
|
40
|
-
hover: hover_1 && regex.test(hover_1) ? hover_1 : "#F2F1F3"
|
41
|
+
hover: hover_1 && regex.test(hover_1) ? hover_1 : "#F2F1F3",
|
41
42
|
};
|
42
43
|
}
|
43
44
|
return { normal: "#FEFEFE", hover: "#F2F1F3" };
|
44
45
|
}, [row, columns, onCustomizeRowBgColor]), normal = _c.normal, hover = _c.hover;
|
45
46
|
return (_jsxs(TableRow, __assign({ sx: {
|
46
47
|
backgroundColor: normal,
|
48
|
+
transform: "translateY(".concat(virtualRow.start - rowIndex * virtualRow.size, "px)"),
|
47
49
|
"&:hover": {
|
48
50
|
cursor: onRowClick ? "pointer" : "default",
|
49
|
-
backgroundColor: onRowClick ? hover : normal
|
50
|
-
}
|
51
|
+
backgroundColor: onRowClick ? hover : normal,
|
52
|
+
},
|
51
53
|
}, onMouseEnter: function (event) {
|
52
54
|
setRowEl(event.currentTarget);
|
53
55
|
}, onMouseLeave: function () {
|
@@ -82,16 +84,16 @@ function TableBodyRow(props) {
|
|
82
84
|
transform: "translateX(100%)",
|
83
85
|
transition: "box-shadow .3s",
|
84
86
|
content: "''",
|
85
|
-
boxShadow: "inset 10px 0 10px -8px rgba(0, 0, 0, 0.1)"
|
87
|
+
boxShadow: "inset 10px 0 10px -8px rgba(0, 0, 0, 0.1)",
|
86
88
|
}
|
87
|
-
: undefined
|
89
|
+
: undefined,
|
88
90
|
} }, { children: cloneElement(Cell, { column: col, rows: rows, row: row, rowIndex: rowIndex }) }), accessor));
|
89
91
|
}), dynamicCols.map(function (col) {
|
90
92
|
var accessor = col.accessor, Cell = col.Cell, width = col.width, _a = col.align, align = _a === void 0 ? "center" : _a;
|
91
93
|
return (_jsx(TableCell, __assign({ align: align, sx: {
|
92
94
|
width: width,
|
93
95
|
zIndex: 9,
|
94
|
-
backgroundColor: onRowClick && rowEl ? hover : normal
|
96
|
+
backgroundColor: onRowClick && rowEl ? hover : normal,
|
95
97
|
} }, { children: cloneElement(Cell, { column: col, rows: rows, row: row, rowIndex: rowIndex }) }), accessor));
|
96
98
|
}), fixedRightCols.map(function (col, index) {
|
97
99
|
var accessor = col.accessor, Cell = col.Cell, width = col.width, _a = col.align, align = _a === void 0 ? "center" : _a;
|
@@ -114,9 +116,9 @@ function TableBodyRow(props) {
|
|
114
116
|
transform: "translateX(-100%)",
|
115
117
|
transition: "box-shadow .3s",
|
116
118
|
content: "''",
|
117
|
-
boxShadow: "inset -10px 0 10px -8px rgba(0, 0, 0, 0.1)"
|
119
|
+
boxShadow: "inset -10px 0 10px -8px rgba(0, 0, 0, 0.1)",
|
118
120
|
}
|
119
|
-
: undefined
|
121
|
+
: undefined,
|
120
122
|
} }, { children: cloneElement(Cell, { column: col, rows: rows, row: row, rowIndex: rowIndex }) }), accessor));
|
121
123
|
})] })));
|
122
124
|
}
|
@@ -1,3 +1,5 @@
|
|
1
|
-
|
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
|
-
|
4
|
+
declare const _default: import("react").MemoExoticComponent<typeof TableFooter>;
|
5
|
+
export default _default;
|
package/DataTable/TableFooter.js
CHANGED
@@ -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
|
-
|
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
|
-
|
4
|
+
declare const _default: import("react").MemoExoticComponent<typeof TableHeader>;
|
5
|
+
export default _default;
|
package/DataTable/TableHeader.js
CHANGED
@@ -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);
|
package/DataTable/index.d.ts
CHANGED
@@ -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";
|
package/DataTable/index.js
CHANGED
@@ -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.
|
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 : 72); },
|
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" },
|
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";
|
package/DataTable/types.d.ts
CHANGED
@@ -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
|
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,9 +73,9 @@ 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"> & {
|
75
|
-
row: RowProps;
|
76
|
+
export declare type TableBodyRowProps<RowProps extends KvProps, ExtendedProps extends KvProps> = Omit<TableBodyProps<RowProps, ExtendedProps>, "noDataText" | "virtualRows"> & {
|
76
77
|
rowIndex: number;
|
78
|
+
virtualRow: VirtualItem;
|
77
79
|
};
|
78
80
|
export declare type TableFooterProps<RowProps extends KvProps, ExtendedProps extends KvProps> = {
|
79
81
|
footers?: Array<TableFooterCellProps<RowProps, ExtendedProps>>;
|
@@ -83,9 +85,8 @@ export declare type TableFooterProps<RowProps extends KvProps, ExtendedProps ext
|
|
83
85
|
leftShadowVisible?: boolean;
|
84
86
|
rightShadowVisible?: boolean;
|
85
87
|
};
|
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"> & {
|
88
|
+
export declare type DataTableProps<RowProps extends KvProps, ExtendedProps extends KvProps> = Omit<TableHeaderProps<RowProps, ExtendedProps>, "leftShadowVisible" | "rightShadowVisible" | "noData"> & Omit<TableBodyProps<RowProps, ExtendedProps>, "leftShadowVisible" | "rightShadowVisible" | "virtualRows"> & 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
|
};
|
package/DataTable/useTable.d.ts
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
import {
|
2
|
-
declare function useTable<T extends KvProps, F extends KvProps>(props: UseTableProps<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;
|
package/DataTable/useTable.js
CHANGED
@@ -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
|
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.
|
3
|
+
"version": "1.6.11-alpha.2",
|
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",
|