@bluemarble/bm-components 0.0.44 → 0.0.46
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
|
@@ -3866,7 +3866,7 @@ const AutoCreatedRows = ({ tableData, columns, primaryKey, }) => {
|
|
|
3866
3866
|
}))))));
|
|
3867
3867
|
};
|
|
3868
3868
|
|
|
3869
|
-
const Grid
|
|
3869
|
+
const Grid = (props) => {
|
|
3870
3870
|
const { columnTitles, isLoading, footer, noFilterButtons = false, selectedFilters, customButtons, setSelectedFilters, defaultData, setTableData, updateFilters, tableData, rowOptions = [60, 100, 150], noPagination, primaryKey, noFilters, } = props;
|
|
3871
3871
|
const [order, setOrder] = useState(undefined);
|
|
3872
3872
|
const [orderBy, setOrderBy] = useState("");
|
|
@@ -15002,98 +15002,19 @@ const GridPagination = ({ currentPage, totalNumberOfPages, onPageChange, rowsPer
|
|
|
15002
15002
|
React__default.createElement(MdArrowForwardIos, { size: 8 * 2 })))));
|
|
15003
15003
|
};
|
|
15004
15004
|
|
|
15005
|
-
|
|
15006
|
-
|
|
15007
|
-
useEffect(() => {
|
|
15008
|
-
window.addEventListener(event, handler, passive);
|
|
15009
|
-
return function cleanup() {
|
|
15010
|
-
window.removeEventListener(event, handler);
|
|
15011
|
-
};
|
|
15012
|
-
});
|
|
15013
|
-
}
|
|
15014
|
-
|
|
15015
|
-
function Grid({ 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
|
-
});
|
|
15069
|
-
return (React__default.createElement(Paper, Object.assign({}, paperProps, { sx: Object.assign({ "tbody tr td": {
|
|
15005
|
+
function BaseGrid({ columns, children, fixedColumns, paperProps, tableBodyProps, tableHeadProps, tableProps, sortedDirection, sortedBy, onSortBy, dense = true, striped, bordered, currentPage, totalNumberOfPages, onPageChange, rowsPerPage, setRowsPerPage, rowsPerPageOptions, }) {
|
|
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" : "",
|
|
15072
15009
|
borderColor: "divider",
|
|
15073
|
-
}, "
|
|
15010
|
+
}, "tr:nth-of-type(even)": {
|
|
15074
15011
|
transition: "background-color ease 200ms",
|
|
15075
15012
|
bgcolor: striped ? "divider" : "initial",
|
|
15076
|
-
}, width: fixedColumns ? "fit-content" : "100
|
|
15077
|
-
React__default.createElement(Table, Object.assign({ size: "small", stickyHeader: true }, tableProps, { sx: Object.assign(
|
|
15013
|
+
}, width: fixedColumns ? "fit-content" : "100" }, paperProps === null || paperProps === void 0 ? void 0 : paperProps.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,
|
|
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
|
}
|
|
@@ -15173,11 +15094,12 @@ function createFilter(filters) {
|
|
|
15173
15094
|
}
|
|
15174
15095
|
|
|
15175
15096
|
function useGrid({ columns, filters = [], rowsPerPageOptions = [30, 60, 100], }) {
|
|
15176
|
-
const [
|
|
15097
|
+
const [data, setData] = useState([]);
|
|
15177
15098
|
const [sortedBy, setSortedBy] = useState("");
|
|
15178
15099
|
const [sortedDirection, setSortedDirection] = useState("desc");
|
|
15179
15100
|
const [currentPage, setCurrentPage] = useState(0);
|
|
15180
15101
|
const [rowsPerPage, setRowsPerPage] = useState(rowsPerPageOptions[0]);
|
|
15102
|
+
const defaultData = useRef([]);
|
|
15181
15103
|
const toggleSortedDirection = () => {
|
|
15182
15104
|
if (sortedDirection === "desc")
|
|
15183
15105
|
setSortedDirection("asc");
|
|
@@ -15201,7 +15123,8 @@ function useGrid({ columns, filters = [], rowsPerPageOptions = [30, 60, 100], })
|
|
|
15201
15123
|
}
|
|
15202
15124
|
};
|
|
15203
15125
|
const set = (data) => {
|
|
15204
|
-
|
|
15126
|
+
setData(data);
|
|
15127
|
+
defaultData.current = data;
|
|
15205
15128
|
};
|
|
15206
15129
|
const sortData = (data) => {
|
|
15207
15130
|
if (sortedBy) {
|
|
@@ -15223,16 +15146,17 @@ function useGrid({ columns, filters = [], rowsPerPageOptions = [30, 60, 100], })
|
|
|
15223
15146
|
setCurrentPage(pageNumber);
|
|
15224
15147
|
};
|
|
15225
15148
|
const onChangeRowsPerPage = (rows) => {
|
|
15226
|
-
|
|
15149
|
+
let totalNumberOfPages = Math.round(filteredData.length / rows) - 1;
|
|
15150
|
+
totalNumberOfPages = totalNumberOfPages <= 0 ? 0 : 1;
|
|
15227
15151
|
if (currentPage > totalNumberOfPages)
|
|
15228
15152
|
setCurrentPage(totalNumberOfPages);
|
|
15229
15153
|
setRowsPerPage(rows);
|
|
15230
15154
|
};
|
|
15231
15155
|
const filteredData = useMemo(() => {
|
|
15232
|
-
const newData = defaultData.slice(0);
|
|
15156
|
+
const newData = defaultData.current.slice(0);
|
|
15233
15157
|
const newFilter = createFilter(filters);
|
|
15234
15158
|
return newData.filter(newFilter.apply);
|
|
15235
|
-
}, [
|
|
15159
|
+
}, [data, filters]);
|
|
15236
15160
|
const displayData = useMemo(() => {
|
|
15237
15161
|
const sortedData = sortData(filteredData);
|
|
15238
15162
|
const startPage = currentPage * rowsPerPage;
|
|
@@ -15242,10 +15166,10 @@ function useGrid({ columns, filters = [], rowsPerPageOptions = [30, 60, 100], })
|
|
|
15242
15166
|
const totalNumberOfPages = Math.round(filteredData.length / rowsPerPage) - 1;
|
|
15243
15167
|
return {
|
|
15244
15168
|
data: displayData,
|
|
15169
|
+
defaultData: defaultData.current,
|
|
15245
15170
|
set,
|
|
15246
15171
|
onSortBy,
|
|
15247
15172
|
sortedBy,
|
|
15248
|
-
defaultData,
|
|
15249
15173
|
sortedDirection,
|
|
15250
15174
|
columns,
|
|
15251
15175
|
currentPage,
|
|
@@ -15257,6 +15181,16 @@ function useGrid({ columns, filters = [], rowsPerPageOptions = [30, 60, 100], })
|
|
|
15257
15181
|
};
|
|
15258
15182
|
}
|
|
15259
15183
|
|
|
15184
|
+
/* eslint no-undef: "off" */
|
|
15185
|
+
function useEvent(event, handler, passive = false) {
|
|
15186
|
+
useEffect(() => {
|
|
15187
|
+
window.addEventListener(event, handler, passive);
|
|
15188
|
+
return function cleanup() {
|
|
15189
|
+
window.removeEventListener(event, handler);
|
|
15190
|
+
};
|
|
15191
|
+
});
|
|
15192
|
+
}
|
|
15193
|
+
|
|
15260
15194
|
function useLoading() {
|
|
15261
15195
|
const [state, setState] = useState([]);
|
|
15262
15196
|
const isLoading = (prop) => state.includes(prop);
|
|
@@ -15284,5 +15218,5 @@ const Modal = (_a) => {
|
|
|
15284
15218
|
React__default.createElement(React__default.Fragment, null, rest.children))));
|
|
15285
15219
|
};
|
|
15286
15220
|
|
|
15287
|
-
export { Autocomplete,
|
|
15221
|
+
export { Autocomplete, BaseGrid, Checkbox, EditableTableCell, Grid, Input, InputMask, LargeButton, Modal, Radio, Select, Switch, TabPanel, Td, Tr, createFilter, filterData, getTabProps, useEvent, useFilter, useGrid, useLoading };
|
|
15288
15222
|
//# sourceMappingURL=index.js.map
|