Spaces:
Running
Running
Upload components/Pagination.js with huggingface_hub
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374export default function Pagination({ currentPage, totalPages, onPageChange }) { if (totalPages <= 1) return null
const pages = [] const maxVisible = 5 let start = Math.max(1, currentPage - Math.floor(maxVisible / 2)) let end = Math.min(totalPages, start + maxVisible - 1)
if (end - start < maxVisible - 1) { start = Math.max(1, end - maxVisible + 1) }
for (let i = start; i <= end; i++) { pages.push(i) }
return ( <div className="flex items-center space-x-2"> <button onClick={() => onPageChange(currentPage - 1)} disabled={currentPage === 1} className="btn-secondary px-3 py-1 text-sm disabled:opacity-50 disabled:cursor-not-allowed" > Previous </button>
{start > 1 && ( <> <button onClick={() => onPageChange(1)} className="btn-secondary px-3 py-1 text-sm" > 1 </button> {start > 2 && <span className="text-dark-500">...</span>} </> )}
{pages.map((page) => ( <button key={page} onClick={() => onPageChange(page)} className={`px-3 py-1 text-sm rounded-lg transition-all ${ page === currentPage ? 'bg-primary-600 text-white' : 'btn-secondary' }`} > {page} </button> ))}
{end < totalPages && ( <> {end < totalPages - 1 && <span className="text-dark-500">...</span>} <button onClick={() => onPageChange(totalPages)} className="btn-secondary px-3 py-1 text-sm" > {totalPages} </button> </> )}
<button onClick={() => onPageChange(currentPage + 1)} disabled={currentPage === totalPages} className="btn-secondary px-3 py-1 text-sm disabled:opacity-50 disabled:cursor-not-allowed" > Next </button> </div> )}components/Pagination.jsAdded+74