Last active
August 19, 2019 17:02
-
-
Save olanipekunife/df226a54c79164cd46564a30ffffdf69 to your computer and use it in GitHub Desktop.
react component that can be used with Express-REST-API-Generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
const Paginations = React.memo(({ pages, lastpage, page, prev, next, pageClick }) => { | |
let paginations = [], showNext = page + 3, showLast = pages - 3, lastpaginations = [] | |
for (let i = 1; i <= pages; i++) { | |
//show last 3 | |
if (i >= page - 3) { | |
if (i < showNext) { | |
paginations.push(<li key={i} className={`page-item ${page === i && 'active'}`}><button onClick={() => page !== i && pageClick(i)} className="link-button page-link">{i}</button></li>) | |
} else if (i > showLast) { | |
lastpaginations.push(<li key={i} className={`page-item ${page === i && 'active'}`}><button onClick={() => page !== i && pageClick(i)} className="link-button page-link">{i}</button></li>) | |
} | |
} | |
} | |
return (<ul className="pagination mrgb0"> | |
<li className={`page-item page-prev ${page === 1 && 'disabled'}`}> | |
<button onClick={prev} className="page-link link-button" tabIndex={-1}> | |
Prev | |
</button> | |
</li> | |
{paginations} | |
{lastpaginations.length > 0 && <li className='page-item'><button className="link-button page-link">.....</button></li>} | |
{lastpaginations} | |
<li className={`page-item page-next ${(page === pages || lastpage) && 'disabled'}`}> | |
<button onClick={next} className="link-button page-link"> | |
Next | |
</button> | |
</li> | |
</ul> | |
); | |
}); | |
export default Paginations; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment