import clsx from 'clsx'; import type { ReactElement } from 'react'; import { ChevronLeftIcon, ChevronRightIcon } from '@heroicons/react/20/solid'; type Props = Readonly<{ current: number; end: number; label: string; onSelect: (page: number, event: React.MouseEvent) => void; pagePadding?: number; start: number; }>; function PaginationPage({ isCurrent = false, label, onClick, }: Readonly<{ isCurrent?: boolean; label: number; onClick: (event: React.MouseEvent) => void; }>) { return ( ); } function PaginationEllipsis() { return ( ... ); } export default function Pagination({ current, end, label, onSelect, pagePadding = 1, start = 1, }: Props) { const pageNumberSet = new Set(); const pageNumberList: Array = []; const elements: Array = []; let lastAddedPage = 0; function addPage(page: number) { if (page < start || page > end) { return; } if (!pageNumberSet.has(page)) { lastAddedPage = page; pageNumberList.push(page); pageNumberSet.add(page); elements.push( { onSelect(page, event); }} />, ); } } for (let i = start; i <= start + pagePadding; i++) { addPage(i); } if (lastAddedPage < current - pagePadding) { elements.push(); } for (let i = current - pagePadding; i <= current + pagePadding; i++) { addPage(i); } if (lastAddedPage < end - pagePadding) { elements.push(); } for (let i = end - pagePadding; i <= end; i++) { addPage(i); } const isPrevButtonDisabled = current === start; const isNextButtonDisabled = current === end; return ( ); }