import clsx from 'clsx' import { Spacer } from './layout/spacer' export function Pagination(props: { page: number itemsPerPage: number totalItems: number setPage: (page: number) => void scrollToTop?: boolean className?: string nextTitle?: string prevTitle?: string }) { const { page, itemsPerPage, totalItems, setPage, scrollToTop, nextTitle, prevTitle, className, } = props const maxPage = Math.ceil(totalItems / itemsPerPage) - 1 if (maxPage === 0) return return ( Showing {page * itemsPerPage + 1}{' '} to{' '} {Math.min(totalItems, (page + 1) * itemsPerPage)} {' '} of {totalItems} results {page > 0 && ( page > 0 && setPage(page - 1)} > {prevTitle ?? 'Previous'} )} page < maxPage && setPage(page + 1)} > {nextTitle ?? 'Next'} ) }
Showing {page * itemsPerPage + 1}{' '} to{' '} {Math.min(totalItems, (page + 1) * itemsPerPage)} {' '} of {totalItems} results