@bluemarble/bm-components 0.0.45 → 0.0.47

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/dist/esm/index.js CHANGED
@@ -15002,70 +15002,7 @@ const GridPagination = ({ currentPage, totalNumberOfPages, onPageChange, rowsPer
15002
15002
  React__default.createElement(MdArrowForwardIos, { size: 8 * 2 })))));
15003
15003
  };
15004
15004
 
15005
- /* eslint no-undef: "off" */
15006
- function useEvent(event, handler, passive = false) {
15007
- useEffect(() => {
15008
- window.addEventListener(event, handler, passive);
15009
- return function cleanup() {
15010
- window.removeEventListener(event, handler);
15011
- };
15012
- });
15013
- }
15014
-
15015
- function BaseGrid({ columns: columnsData, children, fixedColumns, paperProps, tableBodyProps, tableHeadProps, tableProps, sortedDirection, sortedBy, onSortBy, dense = true, striped, bordered, currentPage, totalNumberOfPages, onPageChange, rowsPerPage, setRowsPerPage, rowsPerPageOptions, }) {
15016
- const [columns, setColumns] = useState([]);
15017
- const [startResize, setStartResize] = useState(0);
15018
- const columnsRef = useRef(null);
15019
- const [draggingColumn, setDraggingColumn] = useState(-1);
15020
- const defaultColumn = useRef(columnsData);
15021
- const startColumnWidth = useRef(undefined);
15022
- function handleResizeColumn(event) {
15023
- if (draggingColumn < 0 || event.clientX === 0)
15024
- return;
15025
- const initialWidth = startColumnWidth.current;
15026
- const offset = event.clientX - startResize;
15027
- const newWidth = (initialWidth || 100) + offset;
15028
- setColumns((prevColuns) => {
15029
- prevColuns[draggingColumn].width = newWidth;
15030
- return prevColuns.slice(0);
15031
- });
15032
- }
15033
- function getTableWidth() {
15034
- if (fixedColumns)
15035
- return {
15036
- width: columns.reduce((acc, col) => (acc += (col === null || col === void 0 ? void 0 : col.width) || 100), 0),
15037
- };
15038
- return {};
15039
- }
15040
- function getColWidth(width) {
15041
- if (fixedColumns)
15042
- return width;
15043
- return "auto";
15044
- }
15045
- useEffect(() => {
15046
- const newColumns = columnsData.map((column) => (Object.assign(Object.assign({}, column), { width: column.width || 100 })));
15047
- defaultColumn.current = newColumns;
15048
- setColumns(newColumns);
15049
- }, [columnsData]);
15050
- useEvent("mousemove", (event) => {
15051
- if (draggingColumn >= 0) {
15052
- handleResizeColumn(event);
15053
- }
15054
- });
15055
- useEvent("mousedown", (event) => {
15056
- if (event.target.id) {
15057
- if (String(event.target.id).startsWith("resize-col")) {
15058
- event.preventDefault();
15059
- const dragginCol = parseInt(event.target.id.split("-").pop());
15060
- setDraggingColumn(dragginCol);
15061
- setStartResize(event.clientX);
15062
- startColumnWidth.current = columns[dragginCol].width;
15063
- }
15064
- }
15065
- });
15066
- useEvent("mouseup", () => {
15067
- setDraggingColumn(-1);
15068
- });
15005
+ function BaseGrid({ columns, children, fixedColumns, paperProps, tableBodyProps, tableHeadProps, tableProps, sortedDirection, sortedBy, onSortBy, dense = true, striped, bordered, currentPage, totalNumberOfPages, onPageChange, rowsPerPage, setRowsPerPage, rowsPerPageOptions, }) {
15069
15006
  return (React__default.createElement(Paper, Object.assign({}, paperProps, { sx: Object.assign({ "tr td": {
15070
15007
  py: dense ? 0.23 : 0.7,
15071
15008
  border: bordered ? "1px solid" : "",
@@ -15074,26 +15011,10 @@ function BaseGrid({ columns: columnsData, children, fixedColumns, paperProps, ta
15074
15011
  transition: "background-color ease 200ms",
15075
15012
  bgcolor: striped ? "divider" : "initial",
15076
15013
  }, width: fixedColumns ? "fit-content" : "100" }, paperProps === null || paperProps === void 0 ? void 0 : paperProps.sx) }),
15077
- React__default.createElement(Table, Object.assign({ size: "small", stickyHeader: true }, tableProps, { sx: Object.assign(Object.assign({}, getTableWidth()), tableProps === null || tableProps === void 0 ? void 0 : tableProps.sx) }),
15014
+ React__default.createElement(Table, Object.assign({ size: "small", stickyHeader: true }, tableProps, { sx: Object.assign({}, tableProps === null || tableProps === void 0 ? void 0 : tableProps.sx) }),
15078
15015
  React__default.createElement(TableHead, Object.assign({}, tableHeadProps),
15079
- React__default.createElement(TableRow, { ref: columnsRef }, columns.map((column, index) => (React__default.createElement(TableCell, { key: column.name, padding: dense ? "none" : "normal", sx: Object.assign({ border: "1px solid", borderColor: "divider", width: column.width || 100, minWidth: getColWidth((column === null || column === void 0 ? void 0 : column.width) || 100), maxWidth: getColWidth((column === null || column === void 0 ? void 0 : column.width) || 100), pl: 2, zIndex: columns.length - index }, column === null || column === void 0 ? void 0 : column.sx) },
15080
- React__default.createElement(TableSortLabel, { active: sortedBy === column.name, direction: sortedDirection, onClick: () => onSortBy(column.name), disabled: column.canSort === false, sx: { position: "relative", right: "-9px" } }, column.label),
15081
- index < columns.length && (React__default.createElement(Box$2, { id: `resize-col-${index}`, sx: {
15082
- width: "4px",
15083
- height: "100%",
15084
- position: "absolute",
15085
- top: 0,
15086
- zIndex: index,
15087
- right: "-3px",
15088
- bgcolor: draggingColumn === index
15089
- ? "primary.main"
15090
- : "transparent",
15091
- transition: "all ease 200ms",
15092
- ":hover": {
15093
- cursor: "w-resize",
15094
- bgcolor: "primary.main",
15095
- },
15096
- } }))))))),
15016
+ React__default.createElement(TableRow, null, columns.map((column) => (React__default.createElement(TableCell, { key: column.name, padding: dense ? "none" : "normal", sx: Object.assign({ pl: 2 }, column === null || column === void 0 ? void 0 : column.sx) },
15017
+ React__default.createElement(TableSortLabel, { active: sortedBy === column.name, direction: sortedDirection, onClick: () => onSortBy(column.name), disabled: column.canSort === false, sx: { position: "relative", right: "-9px" } }, column.label)))))),
15097
15018
  React__default.createElement(TableBody, Object.assign({}, tableBodyProps), children)),
15098
15019
  React__default.createElement(GridPagination, { rowsPerPageOptions: rowsPerPageOptions, currentPage: currentPage, totalNumberOfPages: totalNumberOfPages, onPageChange: onPageChange, setRowsPerPage: setRowsPerPage, rowsPerPage: rowsPerPage, dense: dense })));
15099
15020
  }
@@ -15223,7 +15144,8 @@ function useGrid({ columns, filters = [], rowsPerPageOptions = [30, 60, 100], })
15223
15144
  setCurrentPage(pageNumber);
15224
15145
  };
15225
15146
  const onChangeRowsPerPage = (rows) => {
15226
- const totalNumberOfPages = Math.round(filteredData.length / rows) - 1;
15147
+ let totalNumberOfPages = Math.round(filteredData.length / rows) - 1;
15148
+ totalNumberOfPages = totalNumberOfPages <= 0 ? 0 : 1;
15227
15149
  if (currentPage > totalNumberOfPages)
15228
15150
  setCurrentPage(totalNumberOfPages);
15229
15151
  setRowsPerPage(rows);
@@ -15257,6 +15179,16 @@ function useGrid({ columns, filters = [], rowsPerPageOptions = [30, 60, 100], })
15257
15179
  };
15258
15180
  }
15259
15181
 
15182
+ /* eslint no-undef: "off" */
15183
+ function useEvent(event, handler, passive = false) {
15184
+ useEffect(() => {
15185
+ window.addEventListener(event, handler, passive);
15186
+ return function cleanup() {
15187
+ window.removeEventListener(event, handler);
15188
+ };
15189
+ });
15190
+ }
15191
+
15260
15192
  function useLoading() {
15261
15193
  const [state, setState] = useState([]);
15262
15194
  const isLoading = (prop) => state.includes(prop);