Advertisement
Hen_B_S

Pagination React Tailwind

Oct 4th, 2024 (edited)
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TypeScript 2.46 KB | Source Code | 0 0
  1.  
  2.  
  3. type Page = {
  4.     content: [];
  5.     page: {
  6.         size: number;
  7.         number: number;
  8.         totalElements: number;
  9.         totalPages: number;
  10.     }
  11. }
  12.  
  13. type PageProps = {
  14.     pagination: Page;
  15.     onPageChange: Function;
  16. }
  17.  
  18. export const Pagination = ({ pagination, onPageChange }: PageProps) => {
  19.  
  20.     const next = (pageNumber: number) => {
  21.         if (pageNumber != pagination.page.totalPages) {
  22.             onPageChange(pagination.page.number + 1)
  23.         }
  24.     }
  25.  
  26.     return (
  27.         <nav>
  28.             <ul className="flex items-center -space-x-px h-10 text-base">
  29.                 <li>
  30.                     <button onClick={() => onPageChange(pagination.page.number - 1)} className="cursor-pointer flex items-center justify-center px-3 h-10 ms-0 leading-tight text-gray-500 bg-white border border-e-0 border-gray-600 rounded-s-lg hover:bg-gray-100 hover:text-gray-700">
  31.                         <span className="sr-only">Previous</span>
  32.                         <svg className="w-2.5 h-2.5 rtl:rotate-180" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 6 10">
  33.                             <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 1 1 5l4 4" />
  34.                         </svg>
  35.                     </button>
  36.                 </li>
  37.  
  38.                 <li>
  39.                     <p className="cursor-pointer flex items-center justify-center px-6 h-10 leading-tight text-gray-500 bg-white border border-gray-600 hover:bg-gray-100 hover:text-gray-700 ">{pagination.page.number + 1} de {pagination.page.totalPages} </p>
  40.                 </li>
  41.  
  42.                 <li className={pagination.page.number != pagination.page.totalPages - 1 ? `disable` : ''}>
  43.                     <button onClick={() => next(pagination.page.number + 1)} className="cursor-pointer flex items-center justify-center px-3 h-10 leading-tight text-gray-500 bg-white border border-gray-600 rounded-e-lg hover:bg-gray-100 hover:text-gray-700">
  44.                         <span className="sr-only">Next</span>
  45.                         <svg className="w-2.5 h-2.5 rtl:rotate-180" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 6 10">
  46.                             <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 9 4-4-4-4" />
  47.                         </svg>
  48.                     </button>
  49.                 </li>
  50.             </ul>
  51.         </nav>
  52.     );
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement