import clsx from 'clsx'; import classes from './MRT_TablePagination.module.css'; import { ActionIcon, Box, Group, Pagination, type PaginationProps, Select, Text, } from '@mantine/core'; import { type MRT_RowData, type MRT_TableInstance } from '../../types'; import { parseFromValuesOrFunc } from '../../utils/utils'; const defaultRowsPerPage = [5, 10, 15, 20, 25, 30, 50, 100].map((x) => x.toString(), ); interface Props extends Partial { position?: 'bottom' | 'top'; table: MRT_TableInstance; } export const MRT_TablePagination = ({ position = 'bottom', table, ...props }: Props) => { 'use no memo'; const { getPrePaginationRowModel, getState, options: { enableToolbarInternalActions, icons: { IconChevronLeft, IconChevronLeftPipe, IconChevronRight, IconChevronRightPipe, }, localization, mantinePaginationProps, paginationDisplayMode, rowCount, }, setPageIndex, setPageSize, } = table; const { pagination: { pageIndex = 0, pageSize = 10 }, showGlobalFilter, } = getState(); const paginationProps = { ...parseFromValuesOrFunc(mantinePaginationProps, { table, }), ...props, }; const totalRowCount = rowCount ?? getPrePaginationRowModel().rows.length; const numberOfPages = Math.ceil(totalRowCount / pageSize); const showFirstLastPageButtons = numberOfPages > 2; const firstRowIndex = pageIndex * pageSize; const lastRowIndex = Math.min(pageIndex * pageSize + pageSize, totalRowCount); const { rowsPerPageOptions = defaultRowsPerPage, showRowsPerPage = true, withEdges = showFirstLastPageButtons, ...rest } = paginationProps ?? {}; const needsTopMargin = position === 'top' && enableToolbarInternalActions && !showGlobalFilter; return ( {paginationProps?.showRowsPerPage !== false && ( {localization.rowsPerPage}