@symply.io/basic-components 1.1.3-beta.1 → 1.1.3-beta.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.
@@ -16,7 +16,7 @@ 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 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,10 +31,22 @@ function TableBodyRow(props) {
31
31
  return [[], columns, []];
32
32
  }
33
33
  }, [isUpMd, columns]), fixedLeftCols = _b[0], dynamicCols = _b[1], fixedRightCols = _b[2];
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
+ };
42
+ }
43
+ return { normal: "#FEFEFE", hover: "#F2F1F3" };
44
+ }, [row, columns, onCustomizeRowBgColor]), normal = _c.normal, hover = _c.hover;
34
45
  return (_jsxs(TableRow, __assign({ sx: {
46
+ backgroundColor: normal,
35
47
  "&:hover": {
36
48
  cursor: onRowClick ? "pointer" : "default",
37
- backgroundColor: onRowClick ? "#F2F1F3" : "#FEFEFE"
49
+ backgroundColor: onRowClick ? hover : normal
38
50
  }
39
51
  }, onMouseEnter: function (event) {
40
52
  setRowEl(event.currentTarget);
@@ -54,7 +66,7 @@ function TableBodyRow(props) {
54
66
  left: left,
55
67
  position: "sticky",
56
68
  zIndex: 10,
57
- backgroundColor: onRowClick && rowEl ? "#F2F1F3" : "#FEFEFE",
69
+ backgroundColor: onRowClick && rowEl ? hover : normal,
58
70
  "&::after": index === fixedLeftCols.length - 1 && leftShadowVisible
59
71
  ? {
60
72
  position: "absolute",
@@ -74,7 +86,7 @@ function TableBodyRow(props) {
74
86
  return (_jsx(TableCell, __assign({ align: align, sx: {
75
87
  width: width,
76
88
  zIndex: 9,
77
- backgroundColor: onRowClick && rowEl ? "#F2F1F3" : "#FEFEFE"
89
+ backgroundColor: onRowClick && rowEl ? hover : normal
78
90
  } }, { children: cloneElement(Cell, { column: col, rows: rows, row: row }) }), accessor));
79
91
  }), fixedRightCols.map(function (col, index) {
80
92
  var accessor = col.accessor, Cell = col.Cell, width = col.width, _a = col.align, align = _a === void 0 ? "center" : _a;
@@ -86,7 +98,7 @@ function TableBodyRow(props) {
86
98
  right: right,
87
99
  position: "sticky",
88
100
  zIndex: 10,
89
- backgroundColor: onRowClick && rowEl ? "#F2F1F3" : "#FEFEFE",
101
+ backgroundColor: onRowClick && rowEl ? hover : normal,
90
102
  "&::after": index === 0 && rightShadowVisible
91
103
  ? {
92
104
  position: "absolute",
@@ -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, leftShadowVisible: leftShadowVisible, rightShadowVisible: rightShadowVisible }), footers.length > 0 ? (_jsx(TableFooter, { footers: footers, noData: rows.length === 0, leftShadowVisible: leftShadowVisible, rightShadowVisible: rightShadowVisible })) : (_jsx(_Fragment, {}))] })) })) })));
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";
@@ -1,4 +1,9 @@
1
1
  import { ReactElement, CSSProperties } from "react";
2
+ declare type RGBColor = `#${string}`;
3
+ export declare type CustomRowBgColor = {
4
+ normal?: RGBColor;
5
+ hover?: RGBColor;
6
+ };
2
7
  export declare type OrderType = "ASC" | "DESC" | "NONE";
3
8
  export declare type KvProps = Record<string, unknown>;
4
9
  export declare type SortingProps = {
@@ -57,6 +62,10 @@ export declare type TableBodyProps<RowProps extends KvProps, ExtendedProps exten
57
62
  rightShadowVisible?: boolean;
58
63
  noDataText?: string;
59
64
  onRowClick?: (row: RowProps) => unknown;
65
+ onCustomizeRowBgColor?: ({ row, columns }: {
66
+ row: RowProps;
67
+ columns: Array<TableBodyCellProps<RowProps, ExtendedProps>>;
68
+ }) => CustomRowBgColor;
60
69
  };
61
70
  export declare type TableBodyRowProps<RowProps extends KvProps, ExtendedProps extends KvProps> = Omit<TableBodyProps<RowProps, ExtendedProps>, "noDataText"> & {
62
71
  row: RowProps;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symply.io/basic-components",
3
- "version": "1.1.3-beta.1",
3
+ "version": "1.1.3-beta.3",
4
4
  "description": "Basic and reusable components for all frontend of Symply apps",
5
5
  "keywords": [
6
6
  "react",