2021-12-31 02:06:20 +08:00
|
|
|
import React, { useCallback, useRef } 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";
|
|
|
|
|
2021-12-31 02:06:20 +08:00
|
|
|
import { useContentWidth } from "../../libs/width";
|
2021-12-30 16:05:05 +08:00
|
|
|
import styles from "./styles.module.css";
|
|
|
|
|
2021-12-30 12:50:30 +08:00
|
|
|
export default function Paginate({
|
|
|
|
totalPages,
|
|
|
|
setPage,
|
2021-12-30 22:46:15 +08:00
|
|
|
currentPage,
|
2021-12-30 12:50:30 +08:00
|
|
|
}: ReturnType<typeof usePagination>): JSX.Element {
|
2021-12-31 02:06:20 +08:00
|
|
|
const ref = useRef<HTMLElement>();
|
|
|
|
const maxWidth = useContentWidth(ref.current?.parentElement ?? undefined);
|
|
|
|
|
2021-12-30 12:50:30 +08:00
|
|
|
const onPageChange = useCallback(
|
|
|
|
(selectedItem: { selected: number }) => {
|
|
|
|
setPage(selectedItem.selected);
|
|
|
|
},
|
|
|
|
[setPage]
|
|
|
|
);
|
|
|
|
|
2021-12-31 02:06:20 +08:00
|
|
|
// FIXME: responsive width
|
2021-12-30 12:50:30 +08:00
|
|
|
return (
|
2021-12-31 02:06:20 +08:00
|
|
|
<nav role="navigation" aria-label="Pagination Navigation" ref={ref}>
|
2021-12-30 12:50:30 +08:00
|
|
|
<ReactPaginate
|
|
|
|
pageCount={totalPages}
|
2021-12-30 22:46:15 +08:00
|
|
|
forcePage={currentPage}
|
2021-12-30 12:50:30 +08:00
|
|
|
onPageChange={onPageChange}
|
2021-12-30 16:05:05 +08:00
|
|
|
containerClassName={styles.container}
|
|
|
|
pageClassName={styles.li}
|
|
|
|
pageLinkClassName={styles.a}
|
|
|
|
previousClassName={styles.li}
|
|
|
|
previousLinkClassName={styles.a}
|
|
|
|
nextClassName={styles.li}
|
|
|
|
nextLinkClassName={styles.a}
|
|
|
|
activeLinkClassName={styles.active}
|
|
|
|
disabledLinkClassName={styles.disabled}
|
2021-12-30 12:50:30 +08:00
|
|
|
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
|
|
|
}
|