index.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import type { FC } from 'react'
  2. import React from 'react'
  3. import { Pagination } from 'react-headless-pagination'
  4. import { ArrowLeftIcon, ArrowRightIcon } from '@heroicons/react/24/outline'
  5. import { useTranslation } from 'react-i18next'
  6. import s from './style.module.css'
  7. type Props = {
  8. current: number
  9. onChange: (cur: number) => void
  10. total: number
  11. limit?: number
  12. }
  13. const CustomizedPagination: FC<Props> = ({ current, onChange, total, limit = 10 }) => {
  14. const { t } = useTranslation()
  15. const totalPages = Math.ceil(total / limit)
  16. return (
  17. <Pagination
  18. className="flex items-center w-full h-10 text-sm select-none mt-8"
  19. currentPage={current}
  20. edgePageCount={2}
  21. middlePagesSiblingCount={1}
  22. setCurrentPage={onChange}
  23. totalPages={totalPages}
  24. truncableClassName="w-8 px-0.5 text-center"
  25. truncableText="..."
  26. >
  27. <Pagination.PrevButton
  28. disabled={current === 0}
  29. className={`flex items-center mr-2 text-gray-500 focus:outline-none ${current === 0 ? 'cursor-not-allowed opacity-50' : 'cursor-pointer hover:text-gray-600'}`} >
  30. <ArrowLeftIcon className="mr-3 h-3 w-3" />
  31. {t('appLog.table.pagination.previous')}
  32. </Pagination.PrevButton>
  33. <div className={`flex items-center justify-center flex-grow ${s.pagination}`}>
  34. <Pagination.PageButton
  35. activeClassName="bg-primary-50 text-primary-600"
  36. className="flex items-center justify-center h-8 w-8 rounded-lg cursor-pointer"
  37. inactiveClassName="text-gray-500"
  38. />
  39. </div>
  40. <Pagination.NextButton
  41. disabled={current === totalPages - 1}
  42. className={`flex items-center mr-2 text-gray-500 focus:outline-none ${current === totalPages - 1 ? 'cursor-not-allowed opacity-50' : 'cursor-pointer hover:text-gray-600'}`} >
  43. {t('appLog.table.pagination.next')}
  44. <ArrowRightIcon className="ml-3 h-3 w-3" />
  45. </Pagination.NextButton>
  46. </Pagination>
  47. )
  48. }
  49. export default CustomizedPagination