@symply.io/basic-components 1.1.3-beta.2 → 1.1.3
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/TableBodyRow.js +21 -13
- package/DataTable/index.js +2 -2
- package/DataTable/types.d.ts +7 -3
- package/README.md +12 -10
- package/package.json +1 -1
@@ -14,9 +14,9 @@ import { cloneElement, useState, useMemo } from "react";
|
|
14
14
|
import TableRow from "@mui/material/TableRow";
|
15
15
|
import TableCell from "@mui/material/TableCell";
|
16
16
|
import useMediaQuery from "@mui/material/useMediaQuery";
|
17
|
-
import
|
17
|
+
import useTheme from "@mui/material/styles/useTheme";
|
18
18
|
function TableBodyRow(props) {
|
19
|
-
var row = props.row, rows = props.rows, columns = props.columns, leftShadowVisible = props.leftShadowVisible, rightShadowVisible = props.rightShadowVisible, onRowClick = props.onRowClick,
|
19
|
+
var row = props.row, rows = props.rows, columns = props.columns, leftShadowVisible = props.leftShadowVisible, rightShadowVisible = props.rightShadowVisible, onRowClick = props.onRowClick, 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"));
|
@@ -31,16 +31,24 @@ function TableBodyRow(props) {
|
|
31
31
|
return [[], columns, []];
|
32
32
|
}
|
33
33
|
}, [isUpMd, columns]), fixedLeftCols = _b[0], dynamicCols = _b[1], fixedRightCols = _b[2];
|
34
|
-
var
|
35
|
-
if (
|
36
|
-
|
34
|
+
var _c = useMemo(function () {
|
35
|
+
if (onCustomizeRowBgColor) {
|
36
|
+
var regex = /^#(\d|[a-f]|[A-F]){6}/i;
|
37
|
+
var _a = onCustomizeRowBgColor({ row: row, columns: columns }), normal_1 = _a.normal, hover_1 = _a.hover;
|
38
|
+
return {
|
39
|
+
normal: normal_1 && regex.test(normal_1) ? normal_1 : "#FEFEFE",
|
40
|
+
hover: hover_1 && regex.test(hover_1) ? hover_1 : "#F2F1F3"
|
41
|
+
};
|
37
42
|
}
|
38
|
-
return {};
|
39
|
-
}, [row, columns,
|
40
|
-
return (_jsxs(TableRow, __assign({ sx:
|
43
|
+
return { normal: "#FEFEFE", hover: "#F2F1F3" };
|
44
|
+
}, [row, columns, onCustomizeRowBgColor]), normal = _c.normal, hover = _c.hover;
|
45
|
+
return (_jsxs(TableRow, __assign({ sx: {
|
46
|
+
backgroundColor: normal,
|
47
|
+
"&:hover": {
|
41
48
|
cursor: onRowClick ? "pointer" : "default",
|
42
|
-
backgroundColor: onRowClick ?
|
43
|
-
}
|
49
|
+
backgroundColor: onRowClick ? hover : normal
|
50
|
+
}
|
51
|
+
}, onMouseEnter: function (event) {
|
44
52
|
setRowEl(event.currentTarget);
|
45
53
|
}, onMouseLeave: function () {
|
46
54
|
setRowEl(undefined);
|
@@ -58,7 +66,7 @@ function TableBodyRow(props) {
|
|
58
66
|
left: left,
|
59
67
|
position: "sticky",
|
60
68
|
zIndex: 10,
|
61
|
-
backgroundColor: onRowClick && rowEl ?
|
69
|
+
backgroundColor: onRowClick && rowEl ? hover : normal,
|
62
70
|
"&::after": index === fixedLeftCols.length - 1 && leftShadowVisible
|
63
71
|
? {
|
64
72
|
position: "absolute",
|
@@ -78,7 +86,7 @@ function TableBodyRow(props) {
|
|
78
86
|
return (_jsx(TableCell, __assign({ align: align, sx: {
|
79
87
|
width: width,
|
80
88
|
zIndex: 9,
|
81
|
-
backgroundColor: onRowClick && rowEl ?
|
89
|
+
backgroundColor: onRowClick && rowEl ? hover : normal
|
82
90
|
} }, { children: cloneElement(Cell, { column: col, rows: rows, row: row }) }), accessor));
|
83
91
|
}), fixedRightCols.map(function (col, index) {
|
84
92
|
var accessor = col.accessor, Cell = col.Cell, width = col.width, _a = col.align, align = _a === void 0 ? "center" : _a;
|
@@ -90,7 +98,7 @@ function TableBodyRow(props) {
|
|
90
98
|
right: right,
|
91
99
|
position: "sticky",
|
92
100
|
zIndex: 10,
|
93
|
-
backgroundColor: onRowClick && rowEl ?
|
101
|
+
backgroundColor: onRowClick && rowEl ? hover : normal,
|
94
102
|
"&::after": index === 0 && rightShadowVisible
|
95
103
|
? {
|
96
104
|
position: "absolute",
|
package/DataTable/index.js
CHANGED
@@ -19,7 +19,7 @@ import TableBody from "./TableBody";
|
|
19
19
|
import TableHeader from "./TableHeader";
|
20
20
|
import TableFooter from "./TableFooter";
|
21
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,
|
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, onCustomizeRowBgColor = props.onCustomizeRowBgColor;
|
23
23
|
var theme = useCustomTheme({ primaryColor: primaryColor, secondaryColor: secondaryColor });
|
24
24
|
var tableRef = useRef(null);
|
25
25
|
var _f = useState(false), leftShadowVisible = _f[0], setLeftShadowVisible = _f[1];
|
@@ -53,7 +53,7 @@ function DataTable(props) {
|
|
53
53
|
borderRadius: "4px",
|
54
54
|
borderCollapse: "unset !important",
|
55
55
|
transition: "all 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms"
|
56
|
-
} }, { children: _jsxs(Table, __assign({ 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,
|
56
|
+
} }, { children: _jsxs(Table, __assign({ 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, {}))] })) })) })));
|
57
57
|
}
|
58
58
|
export default DataTable;
|
59
59
|
export { default as useDataTable } from "./useTable";
|
package/DataTable/types.d.ts
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
import { ReactElement, CSSProperties } from "react";
|
2
|
-
|
2
|
+
declare type HexColor = `#${string}`;
|
3
|
+
export declare type CustomRowBgColor = {
|
4
|
+
normal?: HexColor;
|
5
|
+
hover?: HexColor;
|
6
|
+
};
|
3
7
|
export declare type OrderType = "ASC" | "DESC" | "NONE";
|
4
8
|
export declare type KvProps = Record<string, unknown>;
|
5
9
|
export declare type SortingProps = {
|
@@ -58,10 +62,10 @@ export declare type TableBodyProps<RowProps extends KvProps, ExtendedProps exten
|
|
58
62
|
rightShadowVisible?: boolean;
|
59
63
|
noDataText?: string;
|
60
64
|
onRowClick?: (row: RowProps) => unknown;
|
61
|
-
|
65
|
+
onCustomizeRowBgColor?: ({ row, columns }: {
|
62
66
|
row: RowProps;
|
63
67
|
columns: Array<TableBodyCellProps<RowProps, ExtendedProps>>;
|
64
|
-
}) =>
|
68
|
+
}) => CustomRowBgColor;
|
65
69
|
};
|
66
70
|
export declare type TableBodyRowProps<RowProps extends KvProps, ExtendedProps extends KvProps> = Omit<TableBodyProps<RowProps, ExtendedProps>, "noDataText"> & {
|
67
71
|
row: RowProps;
|
package/README.md
CHANGED
@@ -393,22 +393,24 @@ import DataTable, { useDataTable } from '@symply.io/basic-components/DataTable';
|
|
393
393
|
|
394
394
|
| Name | Type | Description |
|
395
395
|
| ------- | ----------------------------- | ------------------------- |
|
396
|
-
| headers | Array\<TableHeaderCellProps\> | The cells for the header. |
|
397
396
|
| columns | Array\<TableBodyCellProps\> | The cells for the body. |
|
398
397
|
| footers | Array\<TableFooterCellProps> | The cells for the footer. |
|
398
|
+
| headers | Array\<TableHeaderCellProps\> | The cells for the header. |
|
399
399
|
| rows | Array<RowProps\> | The rows for the table. |
|
400
400
|
|
401
401
|
<h5>Component Props</h5>
|
402
402
|
|
403
|
-
| Name
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
403
|
+
| Name | Type | Default | Required | Description |
|
404
|
+
| --------------------- | ----------------------------- | ---------- | -------- | ------------------------------------------------------------ |
|
405
|
+
| columns | Array\<TableBodyCellProps\> | | true | The cells for the body. (from the hook) |
|
406
|
+
| dense | bool | | false | If `true` the table size/density would be tight. |
|
407
|
+
| footers | Array\<TableFooterCellProps> | [] | false | The cells for the footer. (from the hook) |
|
408
|
+
| headers | Array\<TableHeaderCellProps\> | | true | The cells for the header. (from the hook) |
|
409
|
+
| noDataText | string | 'No Data!' | false | The text when no data rendered. |
|
410
|
+
| 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/>}` |
|
411
|
+
| onRowClick | func | | false | The function for row clicking.<br />**Signature:**<br/>`function(row: RowProps) => unknown` |
|
412
|
+
| rows | Array<RowProps\> | | true | The rows for the table. (from the hook) |
|
413
|
+
| stickyHeader | bool | | false | Set the header sticky.<br/>⚠️ It doesn't work with IE11. |
|
412
414
|
|
413
415
|
|
414
416
|
|