nonebot2/website/src/components/Paginate.tsx

31 lines
961 B
TypeScript
Raw Normal View History

2021-12-30 12:50:30 +08:00
import React, { useCallback } from "react";
2021-12-29 21:09:31 +08:00
import ReactPaginate from "react-paginate";
2021-12-30 12:50:30 +08:00
import { usePagination } from "react-use-pagination";
2021-12-29 21:09:31 +08:00
2021-12-30 12:50:30 +08:00
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
export default function Paginate({
totalPages,
setPage,
}: ReturnType<typeof usePagination>): JSX.Element {
const onPageChange = useCallback(
(selectedItem: { selected: number }) => {
setPage(selectedItem.selected);
},
[setPage]
);
return (
<nav role="navigation" aria-label="Pagination Navigation">
<ReactPaginate
pageCount={totalPages}
onPageChange={onPageChange}
containerClassName="w-full m-w-full inline-flex justify-center align-center m-0 pl-0 list-none"
breakLabel={<FontAwesomeIcon icon="ellipsis-h" />}
previousLabel={<FontAwesomeIcon icon="chevron-left" />}
nextLabel={<FontAwesomeIcon icon="chevron-right" />}
></ReactPaginate>
</nav>
);
2021-12-29 21:09:31 +08:00
}