@coveord/plasma-mantine
Version:
A Plasma flavoured Mantine theme
52 lines (51 loc) • 1.62 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { Pagination } from '@mantine/core';
import { useDidUpdate } from '@mantine/hooks';
import { useTableContext } from '../TableContext';
export const TablePagination = ({ onPageChange })=>{
const { store, table, containerRef } = useTableContext();
const updatePage = (newPage)=>{
onPageChange?.(newPage - 1);
store.setPagination((prev)=>({
...prev,
pageIndex: newPage - 1
}));
containerRef.current.scrollIntoView({
behavior: 'smooth'
});
};
const total = table.getPageCount();
useDidUpdate(()=>{
if (store.state.pagination.pageIndex + 1 > total && total > 0) {
updatePage(total);
}
}, [
store.state.pagination.pageIndex,
total
]);
return /*#__PURE__*/ _jsx(Pagination, {
value: store.state.pagination.pageIndex + 1,
onChange: updatePage,
total: total,
boundaries: 1,
size: "md",
gap: "xs",
getControlProps: (control)=>{
switch(control){
case 'previous':
return {
component: 'button',
'aria-label': 'previous page'
};
case 'next':
return {
component: 'button',
'aria-label': 'next page'
};
default:
return {};
}
}
});
};
//# sourceMappingURL=TablePagination.js.map