import { ReactNode } from 'react' import clsx from 'clsx' import { Spacer } from './layout/spacer' import { Row } from './layout/row' export function PaginationNextPrev(props: { className?: string prev?: ReactNode next?: ReactNode onClickPrev: () => void onClickNext: () => void scrollToTop?: boolean }) { const { className, prev, next, onClickPrev, onClickNext, scrollToTop } = props return ( {prev != null && ( {prev ?? 'Previous'} )} {next != null && ( {next ?? 'Next'} )} ) } 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 0 ? prevTitle ?? 'Previous' : null} next={page < maxPage ? nextTitle ?? 'Next' : null} onClickPrev={() => setPage(page - 1)} onClickNext={() => setPage(page + 1)} scrollToTop={scrollToTop} /> ) }
Showing {page * itemsPerPage + 1}{' '} to{' '} {Math.min(totalItems, (page + 1) * itemsPerPage)} {' '} of {totalItems} results