|
| 1 | + |
| 2 | +const items = [ |
| 3 | + { id: 1, title: 'Back End Developer', department: 'Engineering', type: 'Full-time', location: 'Remote' }, |
| 4 | + { id: 2, title: 'Front End Developer', department: 'Engineering', type: 'Full-time', location: 'Remote' }, |
| 5 | + { id: 3, title: 'User Interface Designer', department: 'Design', type: 'Full-time', location: 'Remote' }, |
| 6 | +] |
| 7 | + |
| 8 | +export default function Pagination({ pageNo, setPageNo, totalPages }) { |
| 9 | + return ( |
| 10 | + <div className="flex items-center justify-between border-t border-gray-200 bg-transparent px-4 py-3 sm:px-6"> |
| 11 | + |
| 12 | + {/* For mobile devices */} |
| 13 | + <div className="flex flex-1 justify-between sm:hidden"> |
| 14 | + <button |
| 15 | + href="#" |
| 16 | + className="relative inline-flex items-center rounded-md border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50" |
| 17 | + > |
| 18 | + Previous |
| 19 | + </button> |
| 20 | + <button |
| 21 | + href="#" |
| 22 | + className="relative ml-3 inline-flex items-center rounded-md border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50" |
| 23 | + > |
| 24 | + Next |
| 25 | + </button> |
| 26 | + </div> |
| 27 | + |
| 28 | + {/* For larger devices */} |
| 29 | + <div className="hidden sm:flex sm:flex-1 sm:items-center sm:justify-center"> |
| 30 | + <div> |
| 31 | + <nav className="isolate inline-flex -space-x-px rounded-md shadow-sm" aria-label="Pagination"> |
| 32 | + <button onClick={() => { |
| 33 | + if (pageNo < 2) return; |
| 34 | + setPageNo((no) => no - 1) |
| 35 | + }} className="relative inline-flex items-center rounded-l-md px-2 py-2 text-gray-400 ring-1 ring-inset ring-gray-300 hover:bg-gray-800 focus:z-20 focus:outline-offset-0"> |
| 36 | + <span className="sr-only">Previous</span> |
| 37 | + ◀️ |
| 38 | + </button> |
| 39 | + |
| 40 | + { |
| 41 | + Array.from({ length: totalPages }, (_, index) => index + 1).map((item) => { |
| 42 | + console.log(item) |
| 43 | + return ( |
| 44 | + <button |
| 45 | + key={item} |
| 46 | + onClick={() => setPageNo(item)} |
| 47 | + aria-current={pageNo === item ? 'page' : undefined} |
| 48 | + className={`ring-1 ring-inset ring-gray-300 relative z-10 inline-flex items-center px-4 py-2 text-sm font-semibold hover:bg-gray-800 text-white focus:z-20 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600 ${pageNo === item ? 'bg-gray-500 hover:bg-gray-500 ' : 'bg-transparent'}`} |
| 49 | + > |
| 50 | + {item} |
| 51 | + </button> |
| 52 | + ) |
| 53 | + }) |
| 54 | + } |
| 55 | + |
| 56 | + <button onClick={() => { |
| 57 | + if (pageNo > totalPages - 1) return; |
| 58 | + setPageNo((no) => no + 1) |
| 59 | + }} className="ring-1 ring-inset ring-gray-300 relative inline-flex items-center rounded-r-md px-2 py-2 text-gray-400 hover:bg-gray-800 focus:z-20 focus:outline-offset-0"> |
| 60 | + <span className="sr-only">Next</span> |
| 61 | + {/* <ChevronRightIcon className="h-5 w-5" aria-hidden="true" /> */} |
| 62 | + ▶️ |
| 63 | + </button> |
| 64 | + </nav> |
| 65 | + </div> |
| 66 | + </div> |
| 67 | + </div> |
| 68 | + ) |
| 69 | +} |
0 commit comments