@symply.io/basic-components 1.1.1 → 1.1.2-beta.10
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 +3 -0
- package/DataTable/TableBody.js +32 -0
- package/DataTable/TableBodyRow.d.ts +3 -0
- package/DataTable/TableBodyRow.js +100 -0
- package/DataTable/TableFooter.d.ts +3 -0
- package/DataTable/TableFooter.js +91 -0
- package/DataTable/TableHeader.d.ts +3 -0
- package/DataTable/TableHeader.js +100 -0
- package/DataTable/index.d.ts +4 -0
- package/DataTable/index.js +58 -0
- package/DataTable/types.d.ts +74 -0
- package/DataTable/types.js +1 -0
- package/DataTable/useTable.d.ts +3 -0
- package/DataTable/useTable.js +94 -0
- package/README.md +63 -1
- package/Sidebar/SidebarItem.js +7 -6
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +1 -1
@@ -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({ 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;
|
@@ -0,0 +1,100 @@
|
|
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 } 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, leftShadowVisible = props.leftShadowVisible, rightShadowVisible = props.rightShadowVisible, onRowClick = props.onRowClick;
|
20
|
+
var _a = useState(), rowEl = _a[0], setRowEl = _a[1];
|
21
|
+
var theme = useTheme();
|
22
|
+
var isUpMd = useMediaQuery(theme.breakpoints.up("md"));
|
23
|
+
var fixedLeftCols = isUpMd ? columns.filter(function (c) { return c.fixable === "left"; }) : [];
|
24
|
+
var fixedRightCols = isUpMd
|
25
|
+
? columns.filter(function (c) { return c.fixable === "right"; })
|
26
|
+
: [];
|
27
|
+
var dynamicCols = isUpMd ? columns.filter(function (c) { return !c.fixable; }) : columns;
|
28
|
+
return (_jsxs(TableRow, __assign({ sx: {
|
29
|
+
"&:hover": {
|
30
|
+
cursor: onRowClick ? "pointer" : "default",
|
31
|
+
backgroundColor: onRowClick ? "#F2F1F3" : "#FEFEFE"
|
32
|
+
}
|
33
|
+
}, onMouseEnter: function (event) {
|
34
|
+
setRowEl(event.currentTarget);
|
35
|
+
}, onMouseLeave: function () {
|
36
|
+
setRowEl(undefined);
|
37
|
+
}, onClick: onRowClick
|
38
|
+
? function () {
|
39
|
+
onRowClick(row);
|
40
|
+
}
|
41
|
+
: undefined }, { children: [fixedLeftCols.map(function (col, index) {
|
42
|
+
var accessor = col.accessor, Cell = col.Cell, width = col.width, _a = col.align, align = _a === void 0 ? "center" : _a;
|
43
|
+
var left = fixedLeftCols
|
44
|
+
.slice(0, index)
|
45
|
+
.reduce(function (w, t) { return w + (t.width || 0); }, 0);
|
46
|
+
return (_jsx(TableCell, __assign({ align: align, sx: {
|
47
|
+
width: width,
|
48
|
+
left: left,
|
49
|
+
position: "sticky",
|
50
|
+
zIndex: 10,
|
51
|
+
backgroundColor: onRowClick && rowEl ? "#F2F1F3" : "#FEFEFE",
|
52
|
+
"&::after": index === fixedLeftCols.length - 1 && leftShadowVisible
|
53
|
+
? {
|
54
|
+
position: "absolute",
|
55
|
+
top: 0,
|
56
|
+
right: 0,
|
57
|
+
bottom: "-1px",
|
58
|
+
width: "20px",
|
59
|
+
transform: "translateX(100%)",
|
60
|
+
transition: "box-shadow .3s",
|
61
|
+
content: "''",
|
62
|
+
boxShadow: "inset 10px 0 10px -8px rgba(0, 0, 0, 0.1)"
|
63
|
+
}
|
64
|
+
: undefined
|
65
|
+
} }, { children: cloneElement(Cell, { column: col, rows: rows, row: row }) }), accessor));
|
66
|
+
}), dynamicCols.map(function (col) {
|
67
|
+
var accessor = col.accessor, Cell = col.Cell, width = col.width, _a = col.align, align = _a === void 0 ? "center" : _a;
|
68
|
+
return (_jsx(TableCell, __assign({ align: align, sx: {
|
69
|
+
width: width,
|
70
|
+
zIndex: 9,
|
71
|
+
backgroundColor: onRowClick && rowEl ? "#F2F1F3" : "#FEFEFE"
|
72
|
+
} }, { children: cloneElement(Cell, { column: col, rows: rows, row: row }) }), accessor));
|
73
|
+
}), fixedRightCols.map(function (col, index) {
|
74
|
+
var accessor = col.accessor, Cell = col.Cell, width = col.width, _a = col.align, align = _a === void 0 ? "center" : _a;
|
75
|
+
var right = fixedRightCols
|
76
|
+
.slice(0, fixedRightCols.length - 1 - index)
|
77
|
+
.reduce(function (w, t) { return w + (t.width || 0); }, 0);
|
78
|
+
return (_jsx(TableCell, __assign({ align: align, sx: {
|
79
|
+
width: width,
|
80
|
+
right: right,
|
81
|
+
position: "sticky",
|
82
|
+
zIndex: 10,
|
83
|
+
backgroundColor: onRowClick && rowEl ? "#F2F1F3" : "#FEFEFE",
|
84
|
+
"&::after": index === 0 && rightShadowVisible
|
85
|
+
? {
|
86
|
+
position: "absolute",
|
87
|
+
top: 0,
|
88
|
+
left: 0,
|
89
|
+
bottom: "-1px",
|
90
|
+
width: "20px",
|
91
|
+
transform: "translateX(-100%)",
|
92
|
+
transition: "box-shadow .3s",
|
93
|
+
content: "''",
|
94
|
+
boxShadow: "inset -10px 0 10px -8px rgba(0, 0, 0, 0.1)"
|
95
|
+
}
|
96
|
+
: undefined
|
97
|
+
} }, { children: cloneElement(Cell, { column: col, rows: rows, row: row }) }), accessor));
|
98
|
+
})] })));
|
99
|
+
}
|
100
|
+
export default TableBodyRow;
|
@@ -0,0 +1,91 @@
|
|
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 } from "react";
|
14
|
+
import TableRow from "@mui/material/TableRow";
|
15
|
+
import Footer from "@mui/material/TableFooter";
|
16
|
+
import TableCell from "@mui/material/TableCell";
|
17
|
+
import useMediaQuery from "@mui/material/useMediaQuery";
|
18
|
+
import useTheme from "@mui/material/styles/useTheme";
|
19
|
+
function TableFooter(props) {
|
20
|
+
var footers = props.footers, leftShadowVisible = props.leftShadowVisible, rightShadowVisible = props.rightShadowVisible;
|
21
|
+
var theme = useTheme();
|
22
|
+
var isUpMd = useMediaQuery(theme.breakpoints.up("md"));
|
23
|
+
var fixedLeftFooters = isUpMd
|
24
|
+
? footers.filter(function (f) { return f.fixable === "left"; })
|
25
|
+
: [];
|
26
|
+
var fixedRightFooters = isUpMd
|
27
|
+
? footers.filter(function (f) { return f.fixable === "right"; })
|
28
|
+
: [];
|
29
|
+
var dynamicFooters = isUpMd ? footers.filter(function (f) { return !f.fixable; }) : footers;
|
30
|
+
return (_jsx(Footer, { children: _jsxs(TableRow, __assign({ sx: { backgroundColor: "#eaf0f6" } }, { children: [fixedLeftFooters.map(function (footer, index) {
|
31
|
+
var accessor = footer.accessor, Cell = footer.Cell, _a = footer.align, align = _a === void 0 ? "center" : _a, width = footer.width;
|
32
|
+
var left = fixedLeftFooters
|
33
|
+
.slice(0, index)
|
34
|
+
.reduce(function (w, t) { return w + (t.width || 0); }, 0);
|
35
|
+
return (_jsx(TableCell, __assign({ align: align, sx: {
|
36
|
+
position: "sticky",
|
37
|
+
backgroundColor: "#eaf0f6",
|
38
|
+
zIndex: 10,
|
39
|
+
left: left,
|
40
|
+
width: width,
|
41
|
+
userSelect: "none",
|
42
|
+
"&::after": index === fixedLeftFooters.length - 1 && leftShadowVisible
|
43
|
+
? {
|
44
|
+
position: "absolute",
|
45
|
+
top: 0,
|
46
|
+
right: 0,
|
47
|
+
bottom: "-1px",
|
48
|
+
width: "20px",
|
49
|
+
transform: "translateX(100%)",
|
50
|
+
transition: "box-shadow .3s",
|
51
|
+
content: "''",
|
52
|
+
boxShadow: "inset 10px 0 10px -8px rgba(0, 0, 0, 0.1)"
|
53
|
+
}
|
54
|
+
: undefined
|
55
|
+
} }, { children: cloneElement(Cell) }), accessor));
|
56
|
+
}), dynamicFooters.map(function (footer) {
|
57
|
+
var accessor = footer.accessor, Cell = footer.Cell, _a = footer.align, align = _a === void 0 ? "center" : _a, width = footer.width;
|
58
|
+
return (_jsx(TableCell, __assign({ align: align, sx: {
|
59
|
+
zIndex: 9,
|
60
|
+
width: width,
|
61
|
+
userSelect: "none"
|
62
|
+
} }, { children: cloneElement(Cell) }), accessor));
|
63
|
+
}), fixedRightFooters.map(function (footer, index) {
|
64
|
+
var accessor = footer.accessor, Cell = footer.Cell, _a = footer.align, align = _a === void 0 ? "center" : _a, width = footer.width;
|
65
|
+
var right = fixedRightFooters
|
66
|
+
.slice(0, fixedRightFooters.length - 1 - index)
|
67
|
+
.reduce(function (w, t) { return w + (t.width || 0); }, 0);
|
68
|
+
return (_jsx(TableCell, __assign({ align: align, sx: {
|
69
|
+
position: "sticky",
|
70
|
+
zIndex: 10,
|
71
|
+
width: width,
|
72
|
+
right: right,
|
73
|
+
backgroundColor: "#eaf0f6",
|
74
|
+
userSelect: "none",
|
75
|
+
"&::after": index === 0 && rightShadowVisible
|
76
|
+
? {
|
77
|
+
position: "absolute",
|
78
|
+
top: 0,
|
79
|
+
left: 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) }), accessor));
|
89
|
+
})] })) }));
|
90
|
+
}
|
91
|
+
export default TableFooter;
|
@@ -0,0 +1,100 @@
|
|
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 } from "react";
|
14
|
+
import TableRow from "@mui/material/TableRow";
|
15
|
+
import TableHead from "@mui/material/TableHead";
|
16
|
+
import TableCell from "@mui/material/TableCell";
|
17
|
+
import useMediaQuery from "@mui/material/useMediaQuery";
|
18
|
+
import useTheme from "@mui/material/styles/useTheme";
|
19
|
+
function TableHeader(props) {
|
20
|
+
var headers = props.headers, leftShadowVisible = props.leftShadowVisible, rightShadowVisible = props.rightShadowVisible;
|
21
|
+
var theme = useTheme();
|
22
|
+
var isUpMd = useMediaQuery(theme.breakpoints.up("md"));
|
23
|
+
var fixedLeftHeaders = isUpMd
|
24
|
+
? headers.filter(function (h) { return h.fixable === "left"; })
|
25
|
+
: [];
|
26
|
+
var fixedRightHeaders = isUpMd
|
27
|
+
? headers.filter(function (h) { return h.fixable === "right"; })
|
28
|
+
: [];
|
29
|
+
var dynamicHeaders = isUpMd ? headers.filter(function (h) { return !h.fixable; }) : headers;
|
30
|
+
return (_jsx(TableHead, { children: _jsxs(TableRow, __assign({ sx: { backgroundColor: "#eaf0f6" } }, { children: [fixedLeftHeaders.map(function (header, index) {
|
31
|
+
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;
|
32
|
+
var left = fixedLeftHeaders
|
33
|
+
.slice(0, index)
|
34
|
+
.reduce(function (w, t) { return w + (t.width || 0); }, 0);
|
35
|
+
return (_jsx(TableCell, __assign({ title: title, align: align, sx: {
|
36
|
+
position: "sticky",
|
37
|
+
backgroundColor: "#eaf0f6",
|
38
|
+
zIndex: 10,
|
39
|
+
width: width,
|
40
|
+
left: left,
|
41
|
+
userSelect: "none",
|
42
|
+
cursor: sortable ? "pointer" : "default",
|
43
|
+
"&::after": index === fixedLeftHeaders.length - 1 && leftShadowVisible
|
44
|
+
? {
|
45
|
+
position: "absolute",
|
46
|
+
top: 0,
|
47
|
+
right: 0,
|
48
|
+
bottom: "-1px",
|
49
|
+
width: "20px",
|
50
|
+
transform: "translateX(100%)",
|
51
|
+
transition: "box-shadow .3s",
|
52
|
+
content: "''",
|
53
|
+
boxShadow: "inset 10px 0 10px -8px rgba(0, 0, 0, 0.1)"
|
54
|
+
}
|
55
|
+
: undefined
|
56
|
+
}, onClick: function () {
|
57
|
+
onSort({ accessor: accessor });
|
58
|
+
} }, { children: cloneElement(Cell) }), accessor));
|
59
|
+
}), dynamicHeaders.map(function (header) {
|
60
|
+
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;
|
61
|
+
return (_jsx(TableCell, __assign({ title: title, align: align, sx: {
|
62
|
+
width: width,
|
63
|
+
zIndex: 9,
|
64
|
+
userSelect: "none",
|
65
|
+
cursor: sortable ? "pointer" : "default"
|
66
|
+
}, onClick: function () {
|
67
|
+
onSort({ accessor: accessor });
|
68
|
+
} }, { children: cloneElement(Cell) }), accessor));
|
69
|
+
}), fixedRightHeaders.map(function (header, index) {
|
70
|
+
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;
|
71
|
+
var right = fixedRightHeaders
|
72
|
+
.slice(0, fixedRightHeaders.length - 1 - index)
|
73
|
+
.reduce(function (w, t) { return w + (t.width || 0); }, 0);
|
74
|
+
return (_jsx(TableCell, __assign({ title: title, align: align, sx: {
|
75
|
+
position: "sticky",
|
76
|
+
backgroundColor: "#eaf0f6",
|
77
|
+
zIndex: 10,
|
78
|
+
width: width,
|
79
|
+
right: right,
|
80
|
+
userSelect: "none",
|
81
|
+
cursor: sortable ? "pointer" : "default",
|
82
|
+
"&::after": index === 0 && rightShadowVisible
|
83
|
+
? {
|
84
|
+
position: "absolute",
|
85
|
+
top: 0,
|
86
|
+
left: 0,
|
87
|
+
bottom: "-1px",
|
88
|
+
width: "20px",
|
89
|
+
transform: "translateX(-100%)",
|
90
|
+
transition: "box-shadow .3s",
|
91
|
+
content: "''",
|
92
|
+
boxShadow: "inset -10px 0 10px -8px rgba(0, 0, 0, 0.1)"
|
93
|
+
}
|
94
|
+
: undefined
|
95
|
+
}, onClick: function () {
|
96
|
+
onSort({ accessor: accessor });
|
97
|
+
} }, { children: cloneElement(Cell) }), accessor));
|
98
|
+
})] })) }));
|
99
|
+
}
|
100
|
+
export default TableHeader;
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import { DataTableProps, KvProps } from "./types";
|
2
|
+
declare function DataTable<RowProps extends KvProps, ExtendedProps extends KvProps>(props: DataTableProps<RowProps, ExtendedProps>): JSX.Element;
|
3
|
+
export default DataTable;
|
4
|
+
export { default as useDataTable } from "./useTable";
|
@@ -0,0 +1,58 @@
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
2
|
+
__assign = Object.assign || function(t) {
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
+
s = arguments[i];
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
+
t[p] = s[p];
|
7
|
+
}
|
8
|
+
return t;
|
9
|
+
};
|
10
|
+
return __assign.apply(this, arguments);
|
11
|
+
};
|
12
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
13
|
+
import { useState, useCallback, useRef, useEffect } from "react";
|
14
|
+
import Table from "@mui/material/Table";
|
15
|
+
import TableContainer from "@mui/material/TableContainer";
|
16
|
+
import ThemeProvider from "@mui/material/styles/ThemeProvider";
|
17
|
+
import useCustomTheme from "../useCustomTheme";
|
18
|
+
import TableBody from "./TableBody";
|
19
|
+
import TableHeader from "./TableHeader";
|
20
|
+
import TableFooter from "./TableFooter";
|
21
|
+
function DataTable(props) {
|
22
|
+
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, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor, onRowClick = props.onRowClick;
|
23
|
+
var theme = useCustomTheme({ primaryColor: primaryColor, secondaryColor: secondaryColor });
|
24
|
+
var tableRef = useRef(null);
|
25
|
+
var _f = useState(false), leftShadowVisible = _f[0], setLeftShadowVisible = _f[1];
|
26
|
+
var _g = useState(false), rightShadowVisible = _g[0], setRightShadowVisible = _g[1];
|
27
|
+
var onProcessShadowVisible = useCallback(function () {
|
28
|
+
if (tableRef.current) {
|
29
|
+
var target = tableRef.current;
|
30
|
+
var scrollLeft = target.scrollLeft;
|
31
|
+
var scrollWidth = target.scrollWidth;
|
32
|
+
var clientWidth = target.clientWidth;
|
33
|
+
var hasScrollBar = scrollWidth > clientWidth;
|
34
|
+
setLeftShadowVisible(hasScrollBar && scrollLeft > 0);
|
35
|
+
setRightShadowVisible(hasScrollBar && scrollWidth - scrollLeft !== clientWidth);
|
36
|
+
}
|
37
|
+
}, []);
|
38
|
+
useEffect(function () {
|
39
|
+
if (columns) {
|
40
|
+
onProcessShadowVisible();
|
41
|
+
}
|
42
|
+
}, [columns, onProcessShadowVisible]);
|
43
|
+
useEffect(function () {
|
44
|
+
window.addEventListener("resize", onProcessShadowVisible);
|
45
|
+
}, [onProcessShadowVisible]);
|
46
|
+
useEffect(function () { return function () {
|
47
|
+
window.removeEventListener("scroll", onProcessShadowVisible);
|
48
|
+
}; }, [onProcessShadowVisible]);
|
49
|
+
return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsx(TableContainer, __assign({ ref: tableRef, onScroll: onProcessShadowVisible, sx: {
|
50
|
+
borderWidth: "thin",
|
51
|
+
borderColor: "#e5e5e5",
|
52
|
+
borderStyle: "solid",
|
53
|
+
borderRadius: "4px",
|
54
|
+
borderCollapse: "unset !important"
|
55
|
+
} }, { children: _jsxs(Table, __assign({ sx: { minWidth: 600, tableLayout: "fixed" }, stickyHeader: stickyHeader, size: dense ? "small" : "medium" }, { children: [_jsx(TableHeader, { headers: headers, leftShadowVisible: leftShadowVisible, rightShadowVisible: rightShadowVisible }), _jsx(TableBody, { rows: rows, columns: columns, noDataText: noDataText, onRowClick: onRowClick, leftShadowVisible: leftShadowVisible, rightShadowVisible: rightShadowVisible }), footers.length > 0 ? (_jsx(TableFooter, { footers: footers, leftShadowVisible: leftShadowVisible, rightShadowVisible: rightShadowVisible })) : (_jsx(_Fragment, {}))] })) })) })));
|
56
|
+
}
|
57
|
+
export default DataTable;
|
58
|
+
export { default as useDataTable } from "./useTable";
|
@@ -0,0 +1,74 @@
|
|
1
|
+
import { ReactElement, CSSProperties } from "react";
|
2
|
+
export declare type OrderType = "ASC" | "DESC" | "NONE";
|
3
|
+
export declare type KvProps = Record<string, unknown>;
|
4
|
+
export declare type SortingProps = {
|
5
|
+
accessor: string;
|
6
|
+
order: OrderType;
|
7
|
+
};
|
8
|
+
declare type InitialStateProps = {
|
9
|
+
sortBy?: SortingProps;
|
10
|
+
};
|
11
|
+
export declare type ColumnProps = {
|
12
|
+
headerTip?: string;
|
13
|
+
Header: ReactElement;
|
14
|
+
Body: ReactElement;
|
15
|
+
Footer?: ReactElement;
|
16
|
+
align?: "left" | "center" | "right";
|
17
|
+
accessor: string;
|
18
|
+
sortable?: boolean;
|
19
|
+
fixable?: "left" | "right";
|
20
|
+
width?: number;
|
21
|
+
};
|
22
|
+
export declare type UseTableBaseProps<RowProps extends KvProps> = {
|
23
|
+
data: Array<RowProps>;
|
24
|
+
columns: Array<ColumnProps>;
|
25
|
+
initialState?: InitialStateProps;
|
26
|
+
disableSortBy?: boolean;
|
27
|
+
onSort?: (props: SortingProps) => unknown;
|
28
|
+
};
|
29
|
+
export declare type UseTableProps<RowProps extends KvProps, ExtendedProps extends KvProps> = UseTableBaseProps<RowProps> & ExtendedProps;
|
30
|
+
export declare type TableHeaderCellProps<RowProps extends KvProps, ExtendedProps extends KvProps> = Pick<ColumnProps, "align" | "accessor" | "fixable" | "width"> & Omit<UseTableProps<RowProps, ExtendedProps>, keyof UseTableBaseProps<RowProps>> & {
|
31
|
+
Cell: ReactElement;
|
32
|
+
title: string;
|
33
|
+
onSort: ({ accessor }: Pick<SortingProps, "accessor">) => unknown;
|
34
|
+
};
|
35
|
+
export declare type TableBodyCellProps<RowProps extends KvProps, ExtendedProps extends KvProps> = Pick<ColumnProps, "align" | "accessor" | "fixable" | "width"> & Omit<UseTableProps<RowProps, ExtendedProps>, keyof UseTableBaseProps<RowProps>> & {
|
36
|
+
Cell: ReactElement;
|
37
|
+
};
|
38
|
+
export declare type TableFooterCellProps<RowProps extends KvProps, ExtendedProps extends KvProps> = Pick<ColumnProps, "align" | "accessor" | "fixable" | "width"> & Omit<UseTableProps<RowProps, ExtendedProps>, keyof UseTableBaseProps<RowProps>> & {
|
39
|
+
Cell: ReactElement;
|
40
|
+
};
|
41
|
+
export declare type UserTableReturns<RowProps extends KvProps, ExtendedProps extends KvProps> = {
|
42
|
+
headers: Array<TableHeaderCellProps<RowProps, ExtendedProps>>;
|
43
|
+
footers: Array<TableFooterCellProps<RowProps, ExtendedProps>>;
|
44
|
+
columns: Array<TableBodyCellProps<RowProps, ExtendedProps>>;
|
45
|
+
rows: Array<RowProps>;
|
46
|
+
};
|
47
|
+
export declare type TableHeaderProps<RowProps extends KvProps, ExtendedProps extends KvProps> = {
|
48
|
+
headers: Array<TableHeaderCellProps<RowProps, ExtendedProps>>;
|
49
|
+
leftShadowVisible?: boolean;
|
50
|
+
rightShadowVisible?: boolean;
|
51
|
+
};
|
52
|
+
export declare type TableBodyProps<RowProps extends KvProps, ExtendedProps extends KvProps> = {
|
53
|
+
columns: Array<TableBodyCellProps<RowProps, ExtendedProps>>;
|
54
|
+
rows: Array<RowProps>;
|
55
|
+
leftShadowVisible?: boolean;
|
56
|
+
rightShadowVisible?: boolean;
|
57
|
+
noDataText?: string;
|
58
|
+
onRowClick?: (row: RowProps) => unknown;
|
59
|
+
};
|
60
|
+
export declare type TableBodyRowProps<RowProps extends KvProps, ExtendedProps extends KvProps> = Omit<TableBodyProps<RowProps, ExtendedProps>, "noDataText"> & {
|
61
|
+
row: RowProps;
|
62
|
+
};
|
63
|
+
export declare type TableFooterProps<RowProps extends KvProps, ExtendedProps extends KvProps> = {
|
64
|
+
footers: Array<TableFooterCellProps<RowProps, ExtendedProps>>;
|
65
|
+
leftShadowVisible?: boolean;
|
66
|
+
rightShadowVisible?: boolean;
|
67
|
+
};
|
68
|
+
export declare type DataTableProps<RowProps extends KvProps, ExtendedProps extends KvProps> = Omit<TableHeaderProps<RowProps, ExtendedProps>, "leftShadowVisible" | "rightShadowVisible"> & Omit<TableBodyProps<RowProps, ExtendedProps>, "leftShadowVisible" | "rightShadowVisible"> & Omit<TableFooterProps<RowProps, ExtendedProps>, "leftShadowVisible" | "rightShadowVisible"> & {
|
69
|
+
dense?: boolean;
|
70
|
+
stickyHeader?: boolean;
|
71
|
+
primaryColor?: CSSProperties["color"];
|
72
|
+
secondaryColor?: CSSProperties["color"];
|
73
|
+
};
|
74
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,94 @@
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
2
|
+
__assign = Object.assign || function(t) {
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
+
s = arguments[i];
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
+
t[p] = s[p];
|
7
|
+
}
|
8
|
+
return t;
|
9
|
+
};
|
10
|
+
return __assign.apply(this, arguments);
|
11
|
+
};
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
13
|
+
var t = {};
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
15
|
+
t[p] = s[p];
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
19
|
+
t[p[i]] = s[p[i]];
|
20
|
+
}
|
21
|
+
return t;
|
22
|
+
};
|
23
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
24
|
+
import { cloneElement, useState, useMemo, useCallback } from "react";
|
25
|
+
function useTable(props) {
|
26
|
+
var data = props.data, columns = props.columns, initialState = props.initialState, disableSortBy = props.disableSortBy, onSort = props.onSort, rest = __rest(props, ["data", "columns", "initialState", "disableSortBy", "onSort"]);
|
27
|
+
if (!data) {
|
28
|
+
throw new Error('"data" is required but got null or undefined');
|
29
|
+
}
|
30
|
+
if (!columns) {
|
31
|
+
throw new Error('"columns" is required but got null or undefined');
|
32
|
+
}
|
33
|
+
var sortBy = (initialState || {}).sortBy;
|
34
|
+
var _a = sortBy || {}, accessor = _a.accessor, order = _a.order;
|
35
|
+
var _b = useState({
|
36
|
+
accessor: accessor || "",
|
37
|
+
order: !!accessor ? order || "NONE" : "NONE"
|
38
|
+
}), sortingProps = _b[0], setSortingProps = _b[1];
|
39
|
+
var handleSort = useCallback(function (_a) {
|
40
|
+
var accessor = _a.accessor;
|
41
|
+
if (!disableSortBy) {
|
42
|
+
var newSortingProps = __assign({}, sortingProps);
|
43
|
+
if (accessor !== sortingProps.accessor ||
|
44
|
+
sortingProps.order === "NONE") {
|
45
|
+
newSortingProps = { accessor: accessor, order: "ASC" };
|
46
|
+
}
|
47
|
+
else if (sortingProps.order === "ASC") {
|
48
|
+
newSortingProps = __assign(__assign({}, sortingProps), { order: "DESC" });
|
49
|
+
}
|
50
|
+
else {
|
51
|
+
newSortingProps = __assign(__assign({}, sortingProps), { order: "NONE" });
|
52
|
+
}
|
53
|
+
if (onSort) {
|
54
|
+
onSort(__assign({}, newSortingProps));
|
55
|
+
}
|
56
|
+
setSortingProps(__assign({}, newSortingProps));
|
57
|
+
}
|
58
|
+
}, [disableSortBy, onSort, sortingProps]);
|
59
|
+
var renderSortingSymbol = useCallback(function (accessor) {
|
60
|
+
var field = sortingProps.accessor, order = sortingProps.order;
|
61
|
+
if (accessor !== field || order === "NONE") {
|
62
|
+
return "";
|
63
|
+
}
|
64
|
+
if (order === "ASC") {
|
65
|
+
return "↑";
|
66
|
+
}
|
67
|
+
return "↓";
|
68
|
+
}, [sortingProps]);
|
69
|
+
var rows = useMemo(function () { return data.map(function (d) { return (__assign({}, d)); }); }, [data]);
|
70
|
+
var cols = useMemo(function () {
|
71
|
+
return columns.map(function (col) {
|
72
|
+
var Body = col.Body;
|
73
|
+
return __assign(__assign({ Cell: cloneElement(Body || _jsx(_Fragment, {}), { column: col }) }, col), rest);
|
74
|
+
});
|
75
|
+
}, [columns, rest]);
|
76
|
+
var headers = useMemo(function () {
|
77
|
+
return columns.map(function (col) {
|
78
|
+
var Header = col.Header, accessor = col.accessor, sortable = col.sortable, headerTip = col.headerTip;
|
79
|
+
var canSortBy = sortable && !disableSortBy;
|
80
|
+
return __assign(__assign({ Cell: (_jsxs(_Fragment, { children: [cloneElement(Header || _jsx(_Fragment, {}), { column: col }), canSortBy && renderSortingSymbol(accessor)] })), title: "".concat(headerTip || "").concat(canSortBy ? " (Click to sort)" : ""), sortable: canSortBy, onSort: canSortBy ? handleSort : function () { } }, col), rest);
|
81
|
+
});
|
82
|
+
}, [columns, disableSortBy, handleSort, renderSortingSymbol, rest]);
|
83
|
+
var footers = useMemo(function () {
|
84
|
+
return columns.map(function (col) {
|
85
|
+
var Footer = col.Footer;
|
86
|
+
return __assign(__assign({ Cell: cloneElement(Footer || _jsx(_Fragment, {}), {
|
87
|
+
column: col,
|
88
|
+
rows: rows
|
89
|
+
}) }, col), rest);
|
90
|
+
});
|
91
|
+
}, [columns, rest, rows]);
|
92
|
+
return { headers: headers, footers: footers, columns: cols, rows: rows };
|
93
|
+
}
|
94
|
+
export default useTable;
|
package/README.md
CHANGED
@@ -15,11 +15,12 @@
|
|
15
15
|
- [Autocomplete](#autocomplete)
|
16
16
|
- [AutocompleteWithFilter](#autocompletewithfilter)
|
17
17
|
- [BasicModal](#basicmodal)
|
18
|
-
- [BasicTable](#basictable)
|
18
|
+
- [BasicTable [⚠️Deprecated]](#basictable)
|
19
19
|
- [BreadCrumbs](#breadcrumbs)
|
20
20
|
- [CheckBox](#checkbox)
|
21
21
|
- [CheckBoxGroup](#checkboxgroup)
|
22
22
|
- [Copyright](#copyright)
|
23
|
+
- [DataTable](#datatable)
|
23
24
|
- [DateInput](#dateinput)
|
24
25
|
- [FullDateInput](#fulldateinput)
|
25
26
|
- [MonthDayInput](#monthdayinput)
|
@@ -206,6 +207,8 @@ import BasicModal from '@symply.io/basic-components/BasicModal';
|
|
206
207
|
|
207
208
|
Reusable table component
|
208
209
|
|
210
|
+
⚠️ This component will be deprecated in the next release. Please use [`DataTable`](#datatable) instead.
|
211
|
+
|
209
212
|
<h5>Import</h5>
|
210
213
|
|
211
214
|
```tsx
|
@@ -343,6 +346,65 @@ import Copyright from '@symply.io/basic-components/Copyright';
|
|
343
346
|
|
344
347
|
|
345
348
|
|
349
|
+
<h3>DataTable</h3>
|
350
|
+
|
351
|
+
Reusable table component
|
352
|
+
|
353
|
+
<h5>Import</h5>
|
354
|
+
|
355
|
+
```tsx
|
356
|
+
import { DataTable, useDataTable } from '@symply.io/basic-components';
|
357
|
+
// or
|
358
|
+
import DataTable, { useDataTable } from '@symply.io/basic-components/DataTable';
|
359
|
+
```
|
360
|
+
|
361
|
+
<h5>Column Props (ColumnProps)</h5>
|
362
|
+
|
363
|
+
| Name | Type | Default | Required | Description |
|
364
|
+
| --------- | ----------------------------- | ------- | -------- | ------------------------------------------------------------ |
|
365
|
+
| accessor | string | | true | The key of the column, it should be unique. |
|
366
|
+
| align | "left" \|"center" \|"right" | | false | The alignment of the column. |
|
367
|
+
| Body | ReactElement | | true | The component to render the column body cell. |
|
368
|
+
| fixable | "left" \| "right" \|undefined | | false | If not undefined, the column can be frozen. <br/>⚠️ It doesn't work with IE11. |
|
369
|
+
| Footer | ReactElement | | false | The component to render the column footer cell. |
|
370
|
+
| Header | ReactElement | | true | The component to render the column header cell. |
|
371
|
+
| headerTip | string | | false | The tip title text when the mouse is over the header. |
|
372
|
+
| sortable | bool | | false | If true, the column can be sortable. |
|
373
|
+
| width | number | | false | The fixed width of cells. |
|
374
|
+
|
375
|
+
<h5>Hook Props</h5>
|
376
|
+
|
377
|
+
| Name | Type | Default | Required | Description |
|
378
|
+
| ------------- | -------------------------- | ------- | -------- | ------------------------------------------- |
|
379
|
+
| columns | Array\<IColumn\> | | true | table columns |
|
380
|
+
| data | Array<{ [name]: unknown }> | | true | table data/rows |
|
381
|
+
| disableSortBy | bool | | false | If true, the whole table can't be sortable. |
|
382
|
+
| initialState | { sortBy?: SortByProps } | | false | Set the initial states |
|
383
|
+
| onSort | func | | false | The function for sorting rows. |
|
384
|
+
|
385
|
+
<h5>Hook Returns</h5>
|
386
|
+
|
387
|
+
| Name | Type | Description |
|
388
|
+
| ------- | -------------------- | ------------------------- |
|
389
|
+
| headers | Array\<IHeader\> | The cells for the header. |
|
390
|
+
| columns | Array\<IBodyColumn\> | The cells for the body. |
|
391
|
+
| footers | Array\<IFooter> | The cells for the footer. |
|
392
|
+
| rows | Array<IRow\> | The rows for the table. |
|
393
|
+
|
394
|
+
<h5>Component Props</h5>
|
395
|
+
|
396
|
+
| Name | Type | Default | Required | Description |
|
397
|
+
| ------------ | -------------------- | ---------- | -------- | ------------------------------------------------------- |
|
398
|
+
| headers | Array\<IHeader\> | | true | The cells for the header. (from the hook) |
|
399
|
+
| columns | Array\<IBodyColumn\> | | true | The cells for the body. (from the hook) |
|
400
|
+
| dense | bool | | false | If `true` the table size/density would be tight. |
|
401
|
+
| noDataText | string | 'No Data!' | false | The text when no data rendered. |
|
402
|
+
| rows | Array<IRow\> | | true | The rows for the table. (from the hook) |
|
403
|
+
| stickyHeader | bool | | false | Set the header sticky.<br/>⚠️ It doesn't work with IE11. |
|
404
|
+
| footers | Array\<IFooter> | [] | false | The cells for the footer. (from the hook) |
|
405
|
+
|
406
|
+
|
407
|
+
|
346
408
|
<h3>DateInput</h3>
|
347
409
|
|
348
410
|
<h4>FullDateInput</h4>
|
package/Sidebar/SidebarItem.js
CHANGED
@@ -10,27 +10,28 @@ 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 colorAlpha from "color-alpha";
|
14
13
|
import Chip from "@mui/material/Chip";
|
15
|
-
import ListItem from "@mui/material/ListItem";
|
16
14
|
import ListItemText from "@mui/material/ListItemText";
|
17
15
|
import ListItemIcon from "@mui/material/ListItemIcon";
|
16
|
+
import ListItemButton from "@mui/material/ListItemButton";
|
18
17
|
import LockIcon from "@mui/icons-material/LockRounded";
|
19
|
-
import useTheme from "@mui/material/styles
|
18
|
+
import { useTheme, alpha } from "@mui/material/styles";
|
20
19
|
import ChevronRightIcon from "@mui/icons-material/ChevronRight";
|
21
20
|
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
|
22
21
|
function SidebarItem(props) {
|
23
22
|
var icon = props.icon, name = props.name, active = props.active, expand = props.expand, lock = props.lock, beta = props.beta, isSub = props.isSub, hasChildren = props.hasChildren, _a = props.betaTagColor, betaTagColor = _a === void 0 ? "#00A2A9" : _a, _b = props.showIconOnly, showIconOnly = _b === void 0 ? false : _b, onClick = props.onClick;
|
24
23
|
var theme = useTheme();
|
25
|
-
return (_jsxs(
|
24
|
+
return (_jsxs(ListItemButton, __assign({ onClick: onClick, disabled: lock, sx: {
|
26
25
|
paddingLeft: isSub ? theme.spacing(4) : undefined,
|
27
26
|
display: "flex",
|
28
27
|
width: "100%",
|
29
28
|
"&:hover": {
|
30
|
-
backgroundColor:
|
29
|
+
backgroundColor: alpha(theme.palette.primary.main, active
|
30
|
+
? theme.palette.action.activatedOpacity
|
31
|
+
: theme.palette.action.selectedOpacity)
|
31
32
|
},
|
32
33
|
backgroundColor: active
|
33
|
-
?
|
34
|
+
? alpha(theme.palette.primary.main, theme.palette.action.activatedOpacity)
|
34
35
|
: undefined
|
35
36
|
} }, { children: [_jsx(ListItemIcon, __assign({ sx: {
|
36
37
|
color: active ? theme.palette.primary.main : undefined,
|
package/index.d.ts
CHANGED
@@ -6,6 +6,7 @@ export * from "./BasicTable";
|
|
6
6
|
export * from "./BreadCrumbs";
|
7
7
|
export * from "./CheckBox";
|
8
8
|
export * from "./Copyright";
|
9
|
+
export * from "./DataTable";
|
9
10
|
export * from "./DateInput";
|
10
11
|
export * from "./DigitInput";
|
11
12
|
export * from "./DynamicHeaderBar";
|
@@ -33,6 +34,7 @@ export { default as BasicModal } from "./BasicModal";
|
|
33
34
|
export { default as BasicTable } from "./BasicTable";
|
34
35
|
export { default as BreadCrumbs } from "./BreadCrumbs";
|
35
36
|
export { default as Copyright } from "./Copyright";
|
37
|
+
export { default as DataTable } from "./DataTable";
|
36
38
|
export { default as DigitInput } from "./DigitInput";
|
37
39
|
export { default as DynamicHeaderBar } from "./DynamicHeaderBar";
|
38
40
|
export { default as FeinInput } from "./FeinInput";
|
package/index.js
CHANGED
@@ -6,6 +6,7 @@ export * from "./BasicTable";
|
|
6
6
|
export * from "./BreadCrumbs";
|
7
7
|
export * from "./CheckBox";
|
8
8
|
export * from "./Copyright";
|
9
|
+
export * from "./DataTable";
|
9
10
|
export * from "./DateInput";
|
10
11
|
export * from "./DigitInput";
|
11
12
|
export * from "./DynamicHeaderBar";
|
@@ -33,6 +34,7 @@ export { default as BasicModal } from "./BasicModal";
|
|
33
34
|
export { default as BasicTable } from "./BasicTable";
|
34
35
|
export { default as BreadCrumbs } from "./BreadCrumbs";
|
35
36
|
export { default as Copyright } from "./Copyright";
|
37
|
+
export { default as DataTable } from "./DataTable";
|
36
38
|
export { default as DigitInput } from "./DigitInput";
|
37
39
|
export { default as DynamicHeaderBar } from "./DynamicHeaderBar";
|
38
40
|
export { default as FeinInput } from "./FeinInput";
|