@coveord/plasma-mantine
Version:
A Plasma flavoured Mantine theme
67 lines (66 loc) • 2.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "TablePagination", {
enumerable: true,
get: function() {
return TablePagination;
}
});
var _object_spread = require("@swc/helpers/_/_object_spread");
var _object_spread_props = require("@swc/helpers/_/_object_spread_props");
var _jsxruntime = require("react/jsx-runtime");
var _core = require("@mantine/core");
var _hooks = require("@mantine/hooks");
var _TableContext = require("../TableContext.js");
var TablePagination = function TablePagination(param) {
var onPageChange = param.onPageChange;
var _useTableContext = (0, _TableContext.useTableContext)(), store = _useTableContext.store, table = _useTableContext.table, containerRef = _useTableContext.containerRef;
var updatePage = function updatePage(newPage) {
onPageChange === null || onPageChange === void 0 ? void 0 : onPageChange(newPage - 1);
store.setPagination(function(prev) {
return _object_spread_props._(_object_spread._({}, prev), {
pageIndex: newPage - 1
});
});
containerRef.current.scrollIntoView({
behavior: 'smooth'
});
};
var total = table.getPageCount();
(0, _hooks.useDidUpdate)(function() {
if (store.state.pagination.pageIndex + 1 > total && total > 0) {
updatePage(total);
}
}, [
store.state.pagination.pageIndex,
total
]);
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_core.Pagination, {
value: store.state.pagination.pageIndex + 1,
onChange: updatePage,
total: total,
boundaries: 1,
size: "md",
gap: "xs",
getControlProps: function getControlProps(control) {
switch(control){
case 'previous':
return {
component: 'button',
'aria-label': 'previous page'
};
case 'next':
return {
component: 'button',
'aria-label': 'next page'
};
default:
return {};
}
}
});
};
TablePagination.displayName = 'Table.Pagination';
//# sourceMappingURL=TablePagination.js.map