import { memo, useCallback, useMemo } from 'react'; import type { MouseEvent as ReactMouseEvent } from 'react'; import clsx from 'clsx'; import Grid from '@mui/material/Grid'; import TablePagination from '@mui/material/TablePagination'; import type { TablePaginationProps } from '@mui/material/TablePagination'; import type { TablePaginationActionsProps } from '@mui/material/TablePagination/TablePaginationActions'; import usePagination from '@mui/material/usePagination'; import ChevronLeftRoundedIcon from '@mui/icons-material/ChevronLeftRounded'; import ChevronRightRoundedIcon from '@mui/icons-material/ChevronRightRounded'; import createClasses from './styles'; const PaginationComponent = memo((props: TablePaginationActionsProps) => { const { backIconButtonProps, count, nextIconButtonProps, page, rowsPerPage, getItemAriaLabel, onPageChange, className } = props; const styles = createClasses(); const { items } = usePagination({ count: Math.ceil(count / rowsPerPage), // eslint-disable-next-line onChange: (e: any, pageNumber) => onPageChange(e, pageNumber - 1), // Mui types dont corelate page: page + 1 }); const itemsIds = useMemo(() => items.map(() => Math.random()), [items]); const handleEllipsisClick = useCallback( state => (e: ReactMouseEvent) => onPageChange(e, page + (state === 'next' ? 4 : -4)), [onPageChange, page] ); return ( ); }); export interface PaginationProps extends Omit< TablePaginationProps, | 'ActionsComponent' | 'onPageChange' | 'onRowsPerPageChange' | 'rowsPerPageOptions' | 'SelectProps' | 'showFirstButton' | 'showLastButton' > { /** * Current page, starts count from 0. */ page: number; /** * Callback on change page. */ onChangePage: TablePaginationProps['onPageChange']; /** * Total number of items. */ count: number; /** * Number of items to be displayed in a page. */ rowsPerPage: number; /** * Hide pagination action buttons? */ hideNavigation?: boolean; /** * Hide displayed rows text? */ hideRowCount?: boolean; classes?: TablePaginationProps['classes'] & Partial>; } const Pagination = (props: PaginationProps) => { const { page, onChangePage, count, rowsPerPage, hideNavigation, hideRowCount, classes, ...otherProps } = props; const styles = createClasses(); const labelDisplayedRows: TablePaginationProps['labelDisplayedRows'] = useCallback( ({ from, to, count: curCount }) => `${from}-${to} of ${curCount}`, [] ); return ( ); }; const m = memo(Pagination); export { m as Pagination };