@popmenu/table 0.19.5 → 0.22.0
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/build/components/Table/TableProps.d.ts +14 -3
- package/build/hooks/index.d.ts +1 -0
- package/build/hooks/useManualPagination/index.d.ts +1 -0
- package/build/hooks/useManualPagination/useManualPagination.d.ts +5 -0
- package/build/hooks/useManualPagination/useManualPaginationTypes.d.ts +52 -0
- package/build/index.d.ts +1 -0
- package/build/index.es.js +104 -14
- package/build/index.es.js.map +1 -1
- package/build/index.js +103 -12
- package/build/index.js.map +1 -1
- package/build/util/index.d.ts +1 -0
- package/build/util/tableConstants.d.ts +5 -0
- package/package.json +2 -2
package/build/index.js
CHANGED
|
@@ -720,6 +720,34 @@ var Tooltip = React.forwardRef(function (props, ref) {
|
|
|
720
720
|
});
|
|
721
721
|
Tooltip.displayName = 'Tooltip';
|
|
722
722
|
|
|
723
|
+
core.makeStyles(function () { return ({
|
|
724
|
+
root: {
|
|
725
|
+
height: 56,
|
|
726
|
+
},
|
|
727
|
+
}); });
|
|
728
|
+
core.makeStyles(function (theme) { return ({
|
|
729
|
+
root: {
|
|
730
|
+
height: '100%',
|
|
731
|
+
width: 'min-content',
|
|
732
|
+
borderRadius: theme.spacing(1),
|
|
733
|
+
},
|
|
734
|
+
input: {
|
|
735
|
+
'&::-webkit-clear-button, &::-webkit-outer-spin-button, &::-webkit-inner-spin-button': {
|
|
736
|
+
display: 'none',
|
|
737
|
+
},
|
|
738
|
+
'-moz-appearance': 'textfield',
|
|
739
|
+
minWidth: 40,
|
|
740
|
+
padding: 0,
|
|
741
|
+
textAlign: 'center',
|
|
742
|
+
},
|
|
743
|
+
adornedStart: {
|
|
744
|
+
padding: 0,
|
|
745
|
+
},
|
|
746
|
+
adornedEnd: {
|
|
747
|
+
padding: 0,
|
|
748
|
+
},
|
|
749
|
+
}); });
|
|
750
|
+
|
|
723
751
|
var TableFooter = function (props) {
|
|
724
752
|
return (React__default['default'].createElement(core.Box, { display: "flex", justifyContent: "center", alignItems: "end", paddingTop: 3, paddingBottom: 4, flexGrow: 1 }, props.children));
|
|
725
753
|
};
|
|
@@ -852,9 +880,15 @@ var TableBody = function (props) {
|
|
|
852
880
|
return React__default['default'].createElement("tbody", __assign$1({}, restProps), children);
|
|
853
881
|
};
|
|
854
882
|
|
|
883
|
+
var tableConstants = {
|
|
884
|
+
tableTypography: 'body1',
|
|
885
|
+
cellPaddingFactor: 2,
|
|
886
|
+
headerBorder: 2,
|
|
887
|
+
};
|
|
888
|
+
|
|
855
889
|
var useTableCellStyles = core.makeStyles(function (theme) { return ({
|
|
856
890
|
root: function () { return ({
|
|
857
|
-
padding: theme.spacing(
|
|
891
|
+
padding: theme.spacing(tableConstants.cellPaddingFactor),
|
|
858
892
|
}); },
|
|
859
893
|
}); });
|
|
860
894
|
|
|
@@ -876,7 +910,7 @@ var useTableStyles = core.makeStyles(function (_a) {
|
|
|
876
910
|
},
|
|
877
911
|
table: function (_a) {
|
|
878
912
|
var fullWidth = _a.fullWidth;
|
|
879
|
-
return (__assign$1(__assign$1({ borderCollapse: 'collapse' }, (fullWidth && { width: '100%' })), typography.
|
|
913
|
+
return (__assign$1(__assign$1({ borderCollapse: 'collapse' }, (fullWidth && { width: '100%' })), typography[tableConstants.tableTypography]));
|
|
880
914
|
},
|
|
881
915
|
tableWrap: function () { return ({
|
|
882
916
|
maxWidth: '100%',
|
|
@@ -942,36 +976,93 @@ var makeColumns = function (config) {
|
|
|
942
976
|
/* eslint-disable react/jsx-key */
|
|
943
977
|
var Table = function (props) {
|
|
944
978
|
var actionColumnId = 'table-actions-column';
|
|
945
|
-
var rawColumns = props.columns, data = props.data, actions = props.actions, sortable = props.sortable, emptyMessage = props.emptyMessage, EmptyImage = props.EmptyImage, isLoading = props.loading,
|
|
979
|
+
var rawColumns = props.columns, data = props.data, actions = props.actions, sortable = props.sortable, emptyMessage = props.emptyMessage, EmptyImage = props.EmptyImage, isLoading = props.loading, fullHeight = props.fullHeight, _a = props.paginationOptions, paginationOptions = _a === void 0 ? {} : _a, _b = props.tableOptions, tableOptions = _b === void 0 ? {} : _b, onPaginate = props.onPaginate;
|
|
980
|
+
var theme = core.useTheme();
|
|
946
981
|
var classes = useTableStyles(props);
|
|
947
982
|
var columns = React.useMemo(function () { return makeColumns({ columns: rawColumns, actions: actions, actionColumnId: actionColumnId }); }, [rawColumns, actions]);
|
|
948
|
-
var
|
|
949
|
-
var
|
|
983
|
+
var initialPaginationState = paginationOptions.initialState, restPaginationOptions = __rest$1(paginationOptions, ["initialState"]);
|
|
984
|
+
var initialState = __assign$1({}, initialPaginationState);
|
|
985
|
+
var instance = useTable_js.useTable(__assign$1(__assign$1({ columns: columns, data: data, disableSortBy: !sortable, initialState: initialState }, restPaginationOptions), tableOptions), useSortBy_js.useSortBy, usePagination_js.usePagination);
|
|
986
|
+
var getTableProps = instance.getTableProps, getTableBodyProps = instance.getTableBodyProps, headerGroups = instance.headerGroups, page = instance.page, prepareRow = instance.prepareRow, pageCount = instance.pageCount, gotoPage = instance.gotoPage, rows = instance.rows;
|
|
950
987
|
var isPaginated = pageCount > 1;
|
|
951
988
|
var isEmpty = rows.length === 0;
|
|
989
|
+
var lineHeightRem = parseFloat(theme.typography[tableConstants.tableTypography].lineHeight);
|
|
990
|
+
var documentFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
991
|
+
var typographyHeight = lineHeightRem * documentFontSize;
|
|
992
|
+
var cellHeight = typographyHeight + theme.spacing(tableConstants.cellPaddingFactor * 2);
|
|
993
|
+
var headerHeight = cellHeight + tableConstants.headerBorder;
|
|
994
|
+
var bodyHeight = instance.state.pageSize * cellHeight;
|
|
995
|
+
var footerHeight = 88;
|
|
996
|
+
var minHeight = headerHeight + bodyHeight + footerHeight;
|
|
952
997
|
var handlePagination = function (_e, pageNumber) {
|
|
953
|
-
|
|
998
|
+
var pageIndex = pageNumber - 1;
|
|
999
|
+
if (onPaginate) {
|
|
1000
|
+
onPaginate(pageIndex, instance);
|
|
1001
|
+
}
|
|
1002
|
+
else {
|
|
1003
|
+
gotoPage(pageIndex);
|
|
1004
|
+
}
|
|
954
1005
|
};
|
|
955
|
-
return (React__default['default'].createElement(core.Box, { className: classes.root, minHeight:
|
|
956
|
-
React__default['default'].createElement(core.Box, { className: classes.tableWrap
|
|
1006
|
+
return (React__default['default'].createElement(core.Box, { className: classes.root, minHeight: fullHeight ? minHeight : 'unset' },
|
|
1007
|
+
React__default['default'].createElement(core.Box, { className: classes.tableWrap },
|
|
957
1008
|
React__default['default'].createElement("table", __assign$1({ className: classes.table }, getTableProps()),
|
|
958
1009
|
React__default['default'].createElement(TableHeader, null, headerGroups.map(function (headerGroup) { return (React__default['default'].createElement(TableHeaderRow, __assign$1({}, headerGroup.getHeaderGroupProps()), headerGroup.headers.map(function (column) { return (React__default['default'].createElement(TableHeaderCell, __assign$1({}, column.getHeaderProps(column.getSortByToggleProps()), { column: __assign$1(__assign$1({}, column), { isActionColumn: column.id === actionColumnId }), tableProps: props }), column.render('Header'))); }))); })),
|
|
959
1010
|
!isEmpty && !isLoading && (React__default['default'].createElement(TableBody, __assign$1({}, getTableBodyProps()), page.map(function (row) {
|
|
960
1011
|
prepareRow(row);
|
|
961
1012
|
return (React__default['default'].createElement(TableRow, __assign$1({}, row.getRowProps()), row.cells.map(function (cell) { return (React__default['default'].createElement(TableCell, __assign$1({}, cell.getCellProps()), cell.render('Cell'))); })));
|
|
962
1013
|
}))))),
|
|
963
|
-
isEmpty && (React__default['default'].createElement(core.Box, { display: "flex", flexDirection: "column", justifyContent: "center", alignItems: "center", p: 2, flexGrow: 1 },
|
|
1014
|
+
isEmpty && !isLoading && (React__default['default'].createElement(core.Box, { display: "flex", flexDirection: "column", justifyContent: "center", alignItems: "center", p: 2, flexGrow: 1 },
|
|
964
1015
|
EmptyImage && EmptyImage(),
|
|
965
1016
|
React__default['default'].createElement(Typography, null, emptyMessage))),
|
|
966
1017
|
isLoading && (React__default['default'].createElement(core.Box, { display: "flex", flexDirection: "column", justifyContent: "center", alignItems: "center", p: 2, flexGrow: 1 },
|
|
967
1018
|
React__default['default'].createElement(CircularProgress__default['default'], { size: 80, color: "inherit" }))),
|
|
968
|
-
isPaginated &&
|
|
969
|
-
React__default['default'].createElement(lab.Pagination, { count: pageCount, page: state.pageIndex + 1, onChange: handlePagination })))));
|
|
1019
|
+
isPaginated && (React__default['default'].createElement(TableFooter, null,
|
|
1020
|
+
React__default['default'].createElement(lab.Pagination, { count: pageCount, page: instance.state.pageIndex + 1, onChange: handlePagination })))));
|
|
970
1021
|
};
|
|
971
1022
|
Table.defaultProps = {
|
|
972
1023
|
emptyMessage: 'No results.',
|
|
973
|
-
|
|
1024
|
+
};
|
|
1025
|
+
|
|
1026
|
+
/**
|
|
1027
|
+
* Makes props for the Table component that will enable manual pagination and also provides page state.
|
|
1028
|
+
*/
|
|
1029
|
+
var useManualPagination = function (config) {
|
|
1030
|
+
var _a = config.initialPageIndex, initialPageIndex = _a === void 0 ? 0 : _a, _b = config.initialPageSize, initialPageSize = _b === void 0 ? 10 : _b, total = config.total, onPaginate = config.onPaginate;
|
|
1031
|
+
var _c = React.useState(0), pageIndex = _c[0], setPageIndex = _c[1];
|
|
1032
|
+
var _d = React.useState(initialPageSize), pageSize = _d[0], setPageSize = _d[1];
|
|
1033
|
+
var handlePagination = function (index, instance) {
|
|
1034
|
+
if (onPaginate) {
|
|
1035
|
+
onPaginate({ index: index, instance: instance }, setPageIndex);
|
|
1036
|
+
}
|
|
1037
|
+
else {
|
|
1038
|
+
setPageIndex(index);
|
|
1039
|
+
}
|
|
1040
|
+
};
|
|
1041
|
+
var manualPaginationProps = {
|
|
1042
|
+
onPaginate: handlePagination,
|
|
1043
|
+
tableOptions: {
|
|
1044
|
+
useControlledState: function (state) {
|
|
1045
|
+
return React.useMemo(function () { return (__assign$1(__assign$1({}, state), { pageIndex: pageIndex, pageSize: pageSize })); }, [pageIndex, pageSize]);
|
|
1046
|
+
},
|
|
1047
|
+
},
|
|
1048
|
+
paginationOptions: {
|
|
1049
|
+
initialState: { pageIndex: initialPageIndex, pageSize: pageSize },
|
|
1050
|
+
manualPagination: true,
|
|
1051
|
+
pageCount: Math.ceil(total / pageSize),
|
|
1052
|
+
},
|
|
1053
|
+
};
|
|
1054
|
+
var pageState = {
|
|
1055
|
+
pageIndex: pageIndex,
|
|
1056
|
+
pageSize: pageSize,
|
|
1057
|
+
setPageIndex: setPageIndex,
|
|
1058
|
+
setPageSize: setPageSize,
|
|
1059
|
+
};
|
|
1060
|
+
return {
|
|
1061
|
+
manualPaginationProps: manualPaginationProps,
|
|
1062
|
+
pageState: pageState,
|
|
1063
|
+
};
|
|
974
1064
|
};
|
|
975
1065
|
|
|
976
1066
|
exports.Table = Table;
|
|
1067
|
+
exports.useManualPagination = useManualPagination;
|
|
977
1068
|
//# sourceMappingURL=index.js.map
|