@symply.io/basic-components 1.1.3-beta.2 → 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.
@@ -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 { useTheme } from "@mui/material/styles";
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, onCustomizeRowSxProps = props.onCustomizeRowSxProps;
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 customRowSx = useMemo(function () {
35
- if (onCustomizeRowSxProps) {
36
- return onCustomizeRowSxProps({ row: row, columns: columns });
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, onCustomizeRowSxProps]);
40
- return (_jsxs(TableRow, __assign({ sx: __assign(__assign({}, customRowSx), { "&:hover": {
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 ? "#F2F1F3" : "#FEFEFE"
43
- } }), onMouseEnter: function (event) {
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 ? "#F2F1F3" : "#FEFEFE",
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 ? "#F2F1F3" : "#FEFEFE"
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 ? "#F2F1F3" : "#FEFEFE",
101
+ backgroundColor: onRowClick && rowEl ? hover : normal,
94
102
  "&::after": index === 0 && rightShadowVisible
95
103
  ? {
96
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, onCustomizeRowSxProps = props.onCustomizeRowSxProps;
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, onCustomizeRowSxProps: onCustomizeRowSxProps, 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,5 +1,9 @@
1
1
  import { ReactElement, CSSProperties } from "react";
2
- import { SxProps } from "@mui/material/styles";
2
+ declare type RGBColor = `#${string}`;
3
+ export declare type CustomRowBgColor = {
4
+ normal?: RGBColor;
5
+ hover?: RGBColor;
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
- onCustomizeRowSxProps?: ({ row, columns }: {
65
+ onCustomizeRowBgColor?: ({ row, columns }: {
62
66
  row: RowProps;
63
67
  columns: Array<TableBodyCellProps<RowProps, ExtendedProps>>;
64
- }) => SxProps;
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symply.io/basic-components",
3
- "version": "1.1.3-beta.2",
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",