|
| 1 | +import React from 'react'; |
| 2 | +import { Link } from 'react-router'; |
| 3 | + |
| 4 | +type PaginationProps = { |
| 5 | + currentPage: number; |
| 6 | + totalPages: number; |
| 7 | + getPageHref: (page: number) => string; |
| 8 | +}; |
| 9 | + |
| 10 | +const buttonBaseStyle: React.CSSProperties = { |
| 11 | + minWidth: '38px', |
| 12 | + height: '38px', |
| 13 | + padding: '0 12px', |
| 14 | + borderRadius: '10px', |
| 15 | + border: '1px solid #cbd5e1', |
| 16 | + backgroundColor: '#ffffff', |
| 17 | + color: '#334155', |
| 18 | + fontSize: '14px', |
| 19 | + fontWeight: 600, |
| 20 | + cursor: 'pointer', |
| 21 | +}; |
| 22 | + |
| 23 | +const Pagination: React.FC<PaginationProps> = ({ |
| 24 | + currentPage, |
| 25 | + totalPages, |
| 26 | + getPageHref, |
| 27 | +}) => { |
| 28 | + if (totalPages <= 1) { |
| 29 | + return null; |
| 30 | + } |
| 31 | + |
| 32 | + const pages = Array.from({ length: totalPages }, (_, index) => index + 1); |
| 33 | + |
| 34 | + return ( |
| 35 | + <div |
| 36 | + style={{ |
| 37 | + display: 'flex', |
| 38 | + justifyContent: 'space-between', |
| 39 | + alignItems: 'center', |
| 40 | + gap: '16px', |
| 41 | + marginTop: '22px', |
| 42 | + flexWrap: 'wrap', |
| 43 | + }} |
| 44 | + > |
| 45 | + <p style={{ margin: 0, fontSize: '14px', color: '#64748b' }}> |
| 46 | + Pagina {currentPage} de {totalPages} |
| 47 | + </p> |
| 48 | + |
| 49 | + <div style={{ display: 'flex', gap: '8px', flexWrap: 'wrap' }}> |
| 50 | + <Link |
| 51 | + to={getPageHref(Math.max(currentPage - 1, 1))} |
| 52 | + aria-disabled={currentPage === 1} |
| 53 | + style={{ |
| 54 | + ...buttonBaseStyle, |
| 55 | + display: 'inline-flex', |
| 56 | + alignItems: 'center', |
| 57 | + justifyContent: 'center', |
| 58 | + textDecoration: 'none', |
| 59 | + opacity: currentPage === 1 ? 0.5 : 1, |
| 60 | + cursor: currentPage === 1 ? 'not-allowed' : 'pointer', |
| 61 | + pointerEvents: currentPage === 1 ? 'none' : 'auto', |
| 62 | + }} |
| 63 | + > |
| 64 | + Anterior |
| 65 | + </Link> |
| 66 | + |
| 67 | + {pages.map((page) => ( |
| 68 | + <Link |
| 69 | + key={page} |
| 70 | + to={getPageHref(page)} |
| 71 | + style={{ |
| 72 | + ...buttonBaseStyle, |
| 73 | + display: 'inline-flex', |
| 74 | + alignItems: 'center', |
| 75 | + justifyContent: 'center', |
| 76 | + textDecoration: 'none', |
| 77 | + backgroundColor: currentPage === page ? '#2563eb' : '#ffffff', |
| 78 | + borderColor: currentPage === page ? '#2563eb' : '#cbd5e1', |
| 79 | + color: currentPage === page ? '#ffffff' : '#334155', |
| 80 | + }} |
| 81 | + > |
| 82 | + {page} |
| 83 | + </Link> |
| 84 | + ))} |
| 85 | + |
| 86 | + <Link |
| 87 | + to={getPageHref(Math.min(currentPage + 1, totalPages))} |
| 88 | + aria-disabled={currentPage === totalPages} |
| 89 | + style={{ |
| 90 | + ...buttonBaseStyle, |
| 91 | + display: 'inline-flex', |
| 92 | + alignItems: 'center', |
| 93 | + justifyContent: 'center', |
| 94 | + textDecoration: 'none', |
| 95 | + opacity: currentPage === totalPages ? 0.5 : 1, |
| 96 | + cursor: currentPage === totalPages ? 'not-allowed' : 'pointer', |
| 97 | + pointerEvents: currentPage === totalPages ? 'none' : 'auto', |
| 98 | + }} |
| 99 | + > |
| 100 | + Siguiente |
| 101 | + </Link> |
| 102 | + </div> |
| 103 | + </div> |
| 104 | + ); |
| 105 | +}; |
| 106 | + |
| 107 | +export default Pagination; |
0 commit comments