@symply.io/basic-components 1.3.11-alpha.1 → 1.3.11-alpha.11
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/AlertDialog/index.js +8 -30
- package/Autocomplete/index.js +10 -32
- package/Autocomplete/useInteractions.js +3 -3
- package/AutocompleteWithFilter/index.js +12 -35
- package/BasicModal/Content.js +5 -16
- package/BasicModal/index.js +9 -31
- package/BreadCrumbs/index.js +8 -19
- package/CheckBox/CheckBox.js +4 -26
- package/CheckBox/CheckBoxGroup.js +2 -24
- package/Copyright/index.js +3 -14
- package/DataTable/TableBody.js +2 -24
- package/DataTable/TableBodyRow.js +41 -52
- package/DataTable/TableFooter.js +30 -41
- package/DataTable/TableHeader.js +36 -47
- package/DataTable/index.js +17 -28
- package/DataTable/useTable.js +46 -54
- package/DateInput/FullDateInput/index.js +20 -42
- package/DateInput/FullDateInput/useInteractions.js +10 -10
- package/DateInput/MonthDayInput/index.js +14 -36
- package/DateInput/MonthDayInput/useInteractions.js +9 -9
- package/DateInput/MonthYearInput/index.js +14 -36
- package/DateInput/MonthYearInput/useInteractions.js +9 -9
- package/DigitInput/index.js +6 -28
- package/DigitInput/useInteractions.js +9 -9
- package/DynamicHeaderBar/HeaderBar.js +6 -17
- package/DynamicHeaderBar/HeaderButtons.js +13 -24
- package/DynamicHeaderBar/HeaderLine.js +2 -2
- package/DynamicHeaderBar/index.js +15 -26
- package/FeinInput/index.js +16 -38
- package/FeinInput/useInteractions.js +9 -9
- package/FileUploader/index.js +11 -33
- package/FileUploader/useInteractions.js +29 -44
- package/FormRadioGroup/index.js +4 -29
- package/FormSelector/MultipleSelector.js +9 -32
- package/FormSelector/SimpleSelector.js +9 -32
- package/FormSelector/useInteractions.js +7 -7
- package/HelpCaption/index.js +6 -17
- package/HelpCaption/useInteractions.js +2 -2
- package/LoadingModal/Modal.js +4 -15
- package/LoadingModal/useLoadingModal.js +15 -33
- package/MenuButtonGroup/MenuItem.js +3 -14
- package/MenuButtonGroup/index.js +14 -82
- package/NumberInput/index.js +5 -27
- package/NumberInput/useInteractions.js +17 -17
- package/PasswordInput/ConfirmPassword.js +6 -28
- package/PasswordInput/Password.js +15 -37
- package/PhoneNumberInput/index.js +17 -39
- package/PhoneNumberInput/useInteractions.js +10 -10
- package/Sidebar/SidebarItem.js +6 -17
- package/Sidebar/SidebarItemsGroup.js +10 -21
- package/Sidebar/SidebarLink.js +5 -27
- package/Sidebar/index.js +6 -17
- package/SocialInput/index.js +18 -40
- package/SocialInput/useInteractions.js +14 -14
- package/TabGroup/index.js +14 -25
- package/TablePagination/Actions.js +4 -15
- package/TablePagination/index.js +3 -14
- package/TablePagination/useInteractions.js +9 -9
- package/TextInput/index.js +8 -30
- package/TextInput/useInteractions.js +4 -4
- package/ToastPrompt/Prompt.d.ts +3 -0
- package/ToastPrompt/Prompt.js +63 -0
- package/ToastPrompt/index.d.ts +2 -13
- package/ToastPrompt/index.js +10 -25
- package/ToastPrompt/types.d.ts +35 -0
- package/ToastPrompt/types.js +1 -0
- package/ToastPrompt/useInteractions.d.ts +14 -0
- package/ToastPrompt/useInteractions.js +27 -0
- package/VideoPlayerModal/index.js +5 -27
- package/package.json +1 -1
- package/useCustomTheme.js +11 -16
- package/utils/uuid.js +10 -11
- package/ToastPrompt/Logics.d.ts +0 -12
- package/ToastPrompt/Logics.js +0 -37
- package/ToastPrompt/Presentation.d.ts +0 -16
- package/ToastPrompt/Presentation.js +0 -82
@@ -1,14 +1,3 @@
|
|
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
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
13
2
|
import { cloneElement, useState, useMemo } from "react";
|
14
3
|
import TableRow from "@mui/material/TableRow";
|
@@ -16,54 +5,54 @@ import TableCell from "@mui/material/TableCell";
|
|
16
5
|
import useMediaQuery from "@mui/material/useMediaQuery";
|
17
6
|
import useTheme from "@mui/material/styles/useTheme";
|
18
7
|
function TableBodyRow(props) {
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
8
|
+
const { row, rows, columns, leftShadowVisible, rightShadowVisible, onRowClick, onCustomizeRowBgColor } = props;
|
9
|
+
const [rowEl, setRowEl] = useState();
|
10
|
+
const theme = useTheme();
|
11
|
+
const isUpMd = useMediaQuery(theme.breakpoints.up("md"));
|
12
|
+
const [fixedLeftCols, dynamicCols, fixedRightCols] = useMemo(() => {
|
24
13
|
if (isUpMd) {
|
25
|
-
|
26
|
-
|
27
|
-
|
14
|
+
const left = columns.filter(c => c.fixable === "left");
|
15
|
+
const right = columns.filter(c => c.fixable === "right");
|
16
|
+
const dynamic = columns.filter(c => !c.fixable);
|
28
17
|
return [left, dynamic, right];
|
29
18
|
}
|
30
19
|
else {
|
31
20
|
return [[], columns, []];
|
32
21
|
}
|
33
|
-
}, [isUpMd, columns])
|
34
|
-
|
22
|
+
}, [isUpMd, columns]);
|
23
|
+
const { normal, hover } = useMemo(() => {
|
35
24
|
if (onCustomizeRowBgColor) {
|
36
|
-
|
37
|
-
|
25
|
+
const regex = /^#(\d|[a-f]|[A-F]){6}/i;
|
26
|
+
const { normal, hover } = onCustomizeRowBgColor({ row, columns });
|
38
27
|
return {
|
39
|
-
normal:
|
40
|
-
hover:
|
28
|
+
normal: normal && regex.test(normal) ? normal : "#FEFEFE",
|
29
|
+
hover: hover && regex.test(hover) ? hover : "#F2F1F3"
|
41
30
|
};
|
42
31
|
}
|
43
32
|
return { normal: "#FEFEFE", hover: "#F2F1F3" };
|
44
|
-
}, [row, columns, onCustomizeRowBgColor])
|
45
|
-
return (_jsxs(TableRow,
|
33
|
+
}, [row, columns, onCustomizeRowBgColor]);
|
34
|
+
return (_jsxs(TableRow, { sx: {
|
46
35
|
backgroundColor: normal,
|
47
36
|
"&:hover": {
|
48
37
|
cursor: onRowClick ? "pointer" : "default",
|
49
38
|
backgroundColor: onRowClick ? hover : normal
|
50
39
|
}
|
51
|
-
}, onMouseEnter:
|
40
|
+
}, onMouseEnter: event => {
|
52
41
|
setRowEl(event.currentTarget);
|
53
|
-
}, onMouseLeave:
|
42
|
+
}, onMouseLeave: () => {
|
54
43
|
setRowEl(undefined);
|
55
44
|
}, onClick: onRowClick
|
56
|
-
?
|
45
|
+
? () => {
|
57
46
|
onRowClick(row);
|
58
47
|
}
|
59
|
-
: undefined
|
60
|
-
|
61
|
-
|
48
|
+
: undefined, children: [fixedLeftCols.map((col, index) => {
|
49
|
+
const { accessor, Cell, width, align = "center" } = col;
|
50
|
+
const left = fixedLeftCols
|
62
51
|
.slice(0, index)
|
63
|
-
.reduce(
|
64
|
-
return (_jsx(TableCell,
|
65
|
-
width
|
66
|
-
left
|
52
|
+
.reduce((w, t) => w + (t.width || 0), 0);
|
53
|
+
return (_jsx(TableCell, { align: align, sx: {
|
54
|
+
width,
|
55
|
+
left,
|
67
56
|
position: "sticky",
|
68
57
|
zIndex: 10,
|
69
58
|
backgroundColor: onRowClick && rowEl ? hover : normal,
|
@@ -80,22 +69,22 @@ function TableBodyRow(props) {
|
|
80
69
|
boxShadow: "inset 10px 0 10px -8px rgba(0, 0, 0, 0.1)"
|
81
70
|
}
|
82
71
|
: undefined
|
83
|
-
}
|
84
|
-
}), dynamicCols.map(
|
85
|
-
|
86
|
-
return (_jsx(TableCell,
|
87
|
-
width
|
72
|
+
}, children: cloneElement(Cell, { column: col, rows, row }) }, accessor));
|
73
|
+
}), dynamicCols.map(col => {
|
74
|
+
const { accessor, Cell, width, align = "center" } = col;
|
75
|
+
return (_jsx(TableCell, { align: align, sx: {
|
76
|
+
width,
|
88
77
|
zIndex: 9,
|
89
78
|
backgroundColor: onRowClick && rowEl ? hover : normal
|
90
|
-
}
|
91
|
-
}), fixedRightCols.map(
|
92
|
-
|
93
|
-
|
79
|
+
}, children: cloneElement(Cell, { column: col, rows, row }) }, accessor));
|
80
|
+
}), fixedRightCols.map((col, index) => {
|
81
|
+
const { accessor, Cell, width, align = "center" } = col;
|
82
|
+
const right = fixedRightCols
|
94
83
|
.slice(0, fixedRightCols.length - 1 - index)
|
95
|
-
.reduce(
|
96
|
-
return (_jsx(TableCell,
|
97
|
-
width
|
98
|
-
right
|
84
|
+
.reduce((w, t) => w + (t.width || 0), 0);
|
85
|
+
return (_jsx(TableCell, { align: align, sx: {
|
86
|
+
width,
|
87
|
+
right,
|
99
88
|
position: "sticky",
|
100
89
|
zIndex: 10,
|
101
90
|
backgroundColor: onRowClick && rowEl ? hover : normal,
|
@@ -112,7 +101,7 @@ function TableBodyRow(props) {
|
|
112
101
|
boxShadow: "inset -10px 0 10px -8px rgba(0, 0, 0, 0.1)"
|
113
102
|
}
|
114
103
|
: undefined
|
115
|
-
}
|
116
|
-
})] }))
|
104
|
+
}, children: cloneElement(Cell, { column: col, rows, row }) }, accessor));
|
105
|
+
})] }));
|
117
106
|
}
|
118
107
|
export default TableBodyRow;
|
package/DataTable/TableFooter.js
CHANGED
@@ -1,14 +1,3 @@
|
|
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
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
13
2
|
import { cloneElement, useMemo } from "react";
|
14
3
|
import TableRow from "@mui/material/TableRow";
|
@@ -17,31 +6,31 @@ import TableCell from "@mui/material/TableCell";
|
|
17
6
|
import useMediaQuery from "@mui/material/useMediaQuery";
|
18
7
|
import useTheme from "@mui/material/styles/useTheme";
|
19
8
|
function TableFooter(props) {
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
9
|
+
const { footers, noData, leftShadowVisible, rightShadowVisible } = props;
|
10
|
+
const theme = useTheme();
|
11
|
+
const isUpMd = useMediaQuery(theme.breakpoints.up("md"));
|
12
|
+
const [fixedLeftFooters, dynamicFooters, fixedRightFooters] = useMemo(() => {
|
24
13
|
if (isUpMd && !noData) {
|
25
|
-
|
26
|
-
|
27
|
-
|
14
|
+
const left = footers.filter(f => f.fixable === "left");
|
15
|
+
const right = footers.filter(f => f.fixable === "right");
|
16
|
+
const dynamic = footers.filter(f => !f.fixable);
|
28
17
|
return [left, dynamic, right];
|
29
18
|
}
|
30
19
|
else {
|
31
20
|
return [[], footers, []];
|
32
21
|
}
|
33
|
-
}, [isUpMd, noData, footers])
|
34
|
-
return (_jsx(Footer,
|
35
|
-
|
36
|
-
|
22
|
+
}, [isUpMd, noData, footers]);
|
23
|
+
return (_jsx(Footer, { sx: { position: "sticky", bottom: "-1px", zIndex: 20 }, children: _jsxs(TableRow, { sx: { backgroundColor: "#eaf0f6" }, children: [fixedLeftFooters.map((footer, index) => {
|
24
|
+
const { accessor, Cell, align = "center", width } = footer;
|
25
|
+
const left = fixedLeftFooters
|
37
26
|
.slice(0, index)
|
38
|
-
.reduce(
|
39
|
-
return (_jsx(TableCell,
|
27
|
+
.reduce((w, t) => w + (t.width || 0), 0);
|
28
|
+
return (_jsx(TableCell, { align: align, sx: {
|
40
29
|
position: "sticky",
|
41
30
|
backgroundColor: "#eaf0f6",
|
42
31
|
zIndex: 10,
|
43
|
-
left
|
44
|
-
width
|
32
|
+
left,
|
33
|
+
width,
|
45
34
|
userSelect: "none",
|
46
35
|
"&::after": index === fixedLeftFooters.length - 1 && leftShadowVisible
|
47
36
|
? {
|
@@ -56,24 +45,24 @@ function TableFooter(props) {
|
|
56
45
|
boxShadow: "inset 10px 0 10px -8px rgba(0, 0, 0, 0.1)"
|
57
46
|
}
|
58
47
|
: undefined
|
59
|
-
}
|
60
|
-
}), dynamicFooters.map(
|
61
|
-
|
62
|
-
return (_jsx(TableCell,
|
48
|
+
}, children: cloneElement(Cell) }, accessor));
|
49
|
+
}), dynamicFooters.map(footer => {
|
50
|
+
const { accessor, Cell, align = "center", width } = footer;
|
51
|
+
return (_jsx(TableCell, { align: align, sx: {
|
63
52
|
zIndex: 9,
|
64
|
-
width
|
53
|
+
width,
|
65
54
|
userSelect: "none"
|
66
|
-
}
|
67
|
-
}), fixedRightFooters.map(
|
68
|
-
|
69
|
-
|
55
|
+
}, children: cloneElement(Cell) }, accessor));
|
56
|
+
}), fixedRightFooters.map((footer, index) => {
|
57
|
+
const { accessor, Cell, align = "center", width } = footer;
|
58
|
+
const right = fixedRightFooters
|
70
59
|
.slice(0, fixedRightFooters.length - 1 - index)
|
71
|
-
.reduce(
|
72
|
-
return (_jsx(TableCell,
|
60
|
+
.reduce((w, t) => w + (t.width || 0), 0);
|
61
|
+
return (_jsx(TableCell, { align: align, sx: {
|
73
62
|
position: "sticky",
|
74
63
|
zIndex: 10,
|
75
|
-
width
|
76
|
-
right
|
64
|
+
width,
|
65
|
+
right,
|
77
66
|
backgroundColor: "#eaf0f6",
|
78
67
|
userSelect: "none",
|
79
68
|
"&::after": index === 0 && rightShadowVisible
|
@@ -89,7 +78,7 @@ function TableFooter(props) {
|
|
89
78
|
boxShadow: "inset -10px 0 10px -8px rgba(0, 0, 0, 0.1)"
|
90
79
|
}
|
91
80
|
: undefined
|
92
|
-
}
|
93
|
-
})] })
|
81
|
+
}, children: cloneElement(Cell) }, accessor));
|
82
|
+
})] }) }));
|
94
83
|
}
|
95
84
|
export default TableFooter;
|
package/DataTable/TableHeader.js
CHANGED
@@ -1,14 +1,3 @@
|
|
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
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
13
2
|
import { cloneElement, useMemo } from "react";
|
14
3
|
import TableRow from "@mui/material/TableRow";
|
@@ -17,31 +6,31 @@ import TableCell from "@mui/material/TableCell";
|
|
17
6
|
import useMediaQuery from "@mui/material/useMediaQuery";
|
18
7
|
import useTheme from "@mui/material/styles/useTheme";
|
19
8
|
function TableHeader(props) {
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
9
|
+
const { headers, noData, leftShadowVisible, rightShadowVisible } = props;
|
10
|
+
const theme = useTheme();
|
11
|
+
const isUpMd = useMediaQuery(theme.breakpoints.up("md"));
|
12
|
+
const [fixedLeftHeaders, dynamicHeaders, fixedRightHeaders] = useMemo(() => {
|
24
13
|
if (isUpMd && !noData) {
|
25
|
-
|
26
|
-
|
27
|
-
|
14
|
+
const left = headers.filter(h => h.fixable === "left");
|
15
|
+
const right = headers.filter(h => h.fixable === "right");
|
16
|
+
const dynamic = headers.filter(h => !h.fixable);
|
28
17
|
return [left, dynamic, right];
|
29
18
|
}
|
30
19
|
else {
|
31
20
|
return [[], headers, []];
|
32
21
|
}
|
33
|
-
}, [isUpMd, noData, headers])
|
34
|
-
return (_jsx(TableHead,
|
35
|
-
|
36
|
-
|
22
|
+
}, [isUpMd, noData, headers]);
|
23
|
+
return (_jsx(TableHead, { sx: { position: "sticky", top: 0, zIndex: 20 }, children: _jsxs(TableRow, { sx: { backgroundColor: "#eaf0f6" }, children: [fixedLeftHeaders.map((header, index) => {
|
24
|
+
const { accessor, Cell, align = "center", width, title, sortable = false, onSort } = header;
|
25
|
+
const left = fixedLeftHeaders
|
37
26
|
.slice(0, index)
|
38
|
-
.reduce(
|
39
|
-
return (_jsx(TableCell,
|
27
|
+
.reduce((w, t) => w + (t.width || 0), 0);
|
28
|
+
return (_jsx(TableCell, { title: title, align: align, sx: {
|
40
29
|
position: "sticky",
|
41
30
|
backgroundColor: "#eaf0f6",
|
42
31
|
zIndex: 10,
|
43
|
-
width
|
44
|
-
left
|
32
|
+
width,
|
33
|
+
left,
|
45
34
|
userSelect: "none",
|
46
35
|
cursor: sortable ? "pointer" : "default",
|
47
36
|
"&::after": index === fixedLeftHeaders.length - 1 && leftShadowVisible
|
@@ -57,30 +46,30 @@ function TableHeader(props) {
|
|
57
46
|
boxShadow: "inset 10px 0 10px -8px rgba(0, 0, 0, 0.1)"
|
58
47
|
}
|
59
48
|
: undefined
|
60
|
-
}, onClick:
|
61
|
-
onSort({ accessor
|
62
|
-
}
|
63
|
-
}), dynamicHeaders.map(
|
64
|
-
|
65
|
-
return (_jsx(TableCell,
|
66
|
-
width
|
49
|
+
}, onClick: () => {
|
50
|
+
onSort({ accessor });
|
51
|
+
}, children: cloneElement(Cell) }, accessor));
|
52
|
+
}), dynamicHeaders.map(header => {
|
53
|
+
const { accessor, Cell, align = "center", width, title, sortable = false, onSort } = header;
|
54
|
+
return (_jsx(TableCell, { title: title, align: align, sx: {
|
55
|
+
width,
|
67
56
|
zIndex: 9,
|
68
57
|
userSelect: "none",
|
69
58
|
cursor: sortable ? "pointer" : "default"
|
70
|
-
}, onClick:
|
71
|
-
onSort({ accessor
|
72
|
-
}
|
73
|
-
}), fixedRightHeaders.map(
|
74
|
-
|
75
|
-
|
59
|
+
}, onClick: () => {
|
60
|
+
onSort({ accessor });
|
61
|
+
}, children: cloneElement(Cell) }, accessor));
|
62
|
+
}), fixedRightHeaders.map((header, index) => {
|
63
|
+
const { accessor, Cell, align = "center", width, title, sortable = false, onSort } = header;
|
64
|
+
const right = fixedRightHeaders
|
76
65
|
.slice(0, fixedRightHeaders.length - 1 - index)
|
77
|
-
.reduce(
|
78
|
-
return (_jsx(TableCell,
|
66
|
+
.reduce((w, t) => w + (t.width || 0), 0);
|
67
|
+
return (_jsx(TableCell, { title: title, align: align, sx: {
|
79
68
|
position: "sticky",
|
80
69
|
backgroundColor: "#eaf0f6",
|
81
70
|
zIndex: 10,
|
82
|
-
width
|
83
|
-
right
|
71
|
+
width,
|
72
|
+
right,
|
84
73
|
userSelect: "none",
|
85
74
|
cursor: sortable ? "pointer" : "default",
|
86
75
|
"&::after": index === 0 && rightShadowVisible
|
@@ -96,9 +85,9 @@ function TableHeader(props) {
|
|
96
85
|
boxShadow: "inset -10px 0 10px -8px rgba(0, 0, 0, 0.1)"
|
97
86
|
}
|
98
87
|
: undefined
|
99
|
-
}, onClick:
|
100
|
-
onSort({ accessor
|
101
|
-
}
|
102
|
-
})] })
|
88
|
+
}, onClick: () => {
|
89
|
+
onSort({ accessor });
|
90
|
+
}, children: cloneElement(Cell) }, accessor));
|
91
|
+
})] }) }));
|
103
92
|
}
|
104
93
|
export default TableHeader;
|
package/DataTable/index.js
CHANGED
@@ -1,14 +1,3 @@
|
|
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
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
13
2
|
import { useState, useCallback, useRef, useEffect } from "react";
|
14
3
|
import Table from "@mui/material/Table";
|
@@ -19,34 +8,34 @@ import TableBody from "./TableBody";
|
|
19
8
|
import TableHeader from "./TableHeader";
|
20
9
|
import TableFooter from "./TableFooter";
|
21
10
|
function DataTable(props) {
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
11
|
+
const { columns = [], rows = [], headers = [], footers = [], noDataText = "No Data!", dense, stickyHeader, primaryColor, secondaryColor, onRowClick, onCustomizeRowBgColor } = props;
|
12
|
+
const theme = useCustomTheme({ primaryColor, secondaryColor });
|
13
|
+
const tableRef = useRef(null);
|
14
|
+
const [leftShadowVisible, setLeftShadowVisible] = useState(false);
|
15
|
+
const [rightShadowVisible, setRightShadowVisible] = useState(false);
|
16
|
+
const onProcessShadowVisible = useCallback(() => {
|
28
17
|
if (tableRef.current) {
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
18
|
+
const target = tableRef.current;
|
19
|
+
const scrollLeft = target.scrollLeft;
|
20
|
+
const scrollWidth = target.scrollWidth;
|
21
|
+
const clientWidth = target.clientWidth;
|
22
|
+
const hasScrollBar = scrollWidth > clientWidth;
|
34
23
|
setLeftShadowVisible(hasScrollBar && scrollLeft > 0);
|
35
24
|
setRightShadowVisible(hasScrollBar && scrollWidth - scrollLeft > clientWidth + 1);
|
36
25
|
}
|
37
26
|
}, []);
|
38
|
-
useEffect(
|
27
|
+
useEffect(() => {
|
39
28
|
if (columns) {
|
40
29
|
onProcessShadowVisible();
|
41
30
|
}
|
42
31
|
}, [columns, onProcessShadowVisible]);
|
43
|
-
useEffect(
|
32
|
+
useEffect(() => {
|
44
33
|
window.addEventListener("resize", onProcessShadowVisible);
|
45
34
|
}, [onProcessShadowVisible]);
|
46
|
-
useEffect(
|
35
|
+
useEffect(() => () => {
|
47
36
|
window.removeEventListener("scroll", onProcessShadowVisible);
|
48
|
-
}
|
49
|
-
return (_jsx(ThemeProvider,
|
37
|
+
}, [onProcessShadowVisible]);
|
38
|
+
return (_jsx(ThemeProvider, { theme: theme, children: _jsx(TableContainer, { ref: tableRef, onScroll: onProcessShadowVisible, sx: {
|
50
39
|
maxHeight: "inherit",
|
51
40
|
borderWidth: "thin",
|
52
41
|
borderColor: "#e5e5e5",
|
@@ -54,7 +43,7 @@ function DataTable(props) {
|
|
54
43
|
borderRadius: "4px",
|
55
44
|
borderCollapse: "unset !important",
|
56
45
|
transition: "all 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms"
|
57
|
-
}
|
46
|
+
}, children: _jsxs(Table, { sx: { minWidth: 600, tableLayout: "fixed" }, stickyHeader: stickyHeader, size: dense ? "small" : "medium", children: [_jsx(TableHeader, { headers: headers, noData: rows.length === 0, leftShadowVisible: leftShadowVisible, rightShadowVisible: rightShadowVisible }), _jsx(TableBody, { rows: rows, columns: columns, noDataText: noDataText, onRowClick: onRowClick, onCustomizeRowBgColor: onCustomizeRowBgColor, leftShadowVisible: leftShadowVisible, rightShadowVisible: rightShadowVisible }), footers.length > 0 ? (_jsx(TableFooter, { footers: footers, noData: rows.length === 0, leftShadowVisible: leftShadowVisible, rightShadowVisible: rightShadowVisible })) : (_jsx(_Fragment, {}))] }) }) }));
|
58
47
|
}
|
59
48
|
export default DataTable;
|
60
49
|
export * from "./types";
|
package/DataTable/useTable.js
CHANGED
@@ -1,63 +1,40 @@
|
|
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
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
24
2
|
import { cloneElement, useState, useMemo, useCallback } from "react";
|
25
3
|
function useTable(props) {
|
26
|
-
|
4
|
+
const { data, columns, initialState, disableSortBy, onSort, ...rest } = props;
|
27
5
|
if (!data) {
|
28
6
|
throw new Error('"data" is required but got null or undefined');
|
29
7
|
}
|
30
8
|
if (!columns) {
|
31
9
|
throw new Error('"columns" is required but got null or undefined');
|
32
10
|
}
|
33
|
-
|
34
|
-
|
35
|
-
|
11
|
+
const { sortBy } = initialState || {};
|
12
|
+
const { accessor, order } = sortBy || {};
|
13
|
+
const [sortingProps, setSortingProps] = useState({
|
36
14
|
accessor: accessor || "",
|
37
15
|
order: !!accessor ? order || "NONE" : "NONE"
|
38
|
-
})
|
39
|
-
|
40
|
-
var accessor = _a.accessor;
|
16
|
+
});
|
17
|
+
const handleSort = useCallback(({ accessor }) => {
|
41
18
|
if (!disableSortBy) {
|
42
|
-
|
19
|
+
let newSortingProps = { ...sortingProps };
|
43
20
|
if (accessor !== sortingProps.accessor ||
|
44
21
|
sortingProps.order === "NONE") {
|
45
|
-
newSortingProps = { accessor
|
22
|
+
newSortingProps = { accessor, order: "ASC" };
|
46
23
|
}
|
47
24
|
else if (sortingProps.order === "ASC") {
|
48
|
-
newSortingProps =
|
25
|
+
newSortingProps = { ...sortingProps, order: "DESC" };
|
49
26
|
}
|
50
27
|
else {
|
51
|
-
newSortingProps =
|
28
|
+
newSortingProps = { ...sortingProps, order: "NONE" };
|
52
29
|
}
|
53
30
|
if (onSort) {
|
54
|
-
onSort(
|
31
|
+
onSort({ ...newSortingProps });
|
55
32
|
}
|
56
|
-
setSortingProps(
|
33
|
+
setSortingProps({ ...newSortingProps });
|
57
34
|
}
|
58
35
|
}, [disableSortBy, onSort, sortingProps]);
|
59
|
-
|
60
|
-
|
36
|
+
const renderSortingSymbol = useCallback((accessor) => {
|
37
|
+
const { accessor: field, order } = sortingProps;
|
61
38
|
if (accessor !== field || order === "NONE") {
|
62
39
|
return "";
|
63
40
|
}
|
@@ -66,29 +43,44 @@ function useTable(props) {
|
|
66
43
|
}
|
67
44
|
return "↓";
|
68
45
|
}, [sortingProps]);
|
69
|
-
|
70
|
-
|
71
|
-
return columns.map(
|
72
|
-
|
73
|
-
return
|
46
|
+
const rows = useMemo(() => data.map(d => ({ ...d })), [data]);
|
47
|
+
const cols = useMemo(() => {
|
48
|
+
return columns.map(col => {
|
49
|
+
const { Body } = col;
|
50
|
+
return {
|
51
|
+
Cell: cloneElement(Body || _jsx(_Fragment, {}), { column: col }),
|
52
|
+
...col,
|
53
|
+
...rest
|
54
|
+
};
|
74
55
|
});
|
75
56
|
}, [columns, rest]);
|
76
|
-
|
77
|
-
return columns.map(
|
78
|
-
|
79
|
-
|
80
|
-
return
|
57
|
+
const headers = useMemo(() => {
|
58
|
+
return columns.map(col => {
|
59
|
+
const { Header, accessor, sortable, headerTip } = col;
|
60
|
+
const canSortBy = sortable && !disableSortBy;
|
61
|
+
return {
|
62
|
+
Cell: (_jsxs(_Fragment, { children: [cloneElement(Header || _jsx(_Fragment, {}), { column: col }), canSortBy && renderSortingSymbol(accessor)] })),
|
63
|
+
title: `${headerTip || ""}${canSortBy ? " (Click to sort)" : ""}`,
|
64
|
+
sortable: canSortBy,
|
65
|
+
onSort: canSortBy ? handleSort : () => { },
|
66
|
+
...col,
|
67
|
+
...rest
|
68
|
+
};
|
81
69
|
});
|
82
70
|
}, [columns, disableSortBy, handleSort, renderSortingSymbol, rest]);
|
83
|
-
|
84
|
-
return columns.map(
|
85
|
-
|
86
|
-
return
|
71
|
+
const footers = useMemo(() => {
|
72
|
+
return columns.map(col => {
|
73
|
+
const { Footer } = col;
|
74
|
+
return {
|
75
|
+
Cell: cloneElement(Footer || _jsx(_Fragment, {}), {
|
87
76
|
column: col,
|
88
|
-
rows
|
89
|
-
})
|
77
|
+
rows
|
78
|
+
}),
|
79
|
+
...col,
|
80
|
+
...rest
|
81
|
+
};
|
90
82
|
});
|
91
83
|
}, [columns, rest, rows]);
|
92
|
-
return { headers
|
84
|
+
return { headers, footers, columns: cols, rows };
|
93
85
|
}
|
94
86
|
export default useTable;
|