Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 33x 33x 33x 33x 33x 1x 7x 7x 33x 33x 33x 33x 1x 1x 1x 1x 1x 31x 31x 1x 1x 1x 1x 1x 1x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 1x 1x 1x 1x | import styled from "@emotion/styled";
import React from "react";
import RBPagination from "reactstrap/lib/Pagination";
import PaginationItem from "reactstrap/lib/PaginationItem";
import PaginationLink from "reactstrap/lib/PaginationLink";
import * as R from "ramda";
interface Props {
canNext: boolean;
canPrevious: boolean;
data: any[];
defaultPage: number;
defaultPageSize: number;
loading: boolean;
nextText: string;
ofText: string;
onPageChange: (pageIndex) => void;
page: number;
pageJumpText: string;
pageSize: number;
pageSizeOptions: number[];
pageText: string;
pages: number;
previousText: string;
rowsText: string;
showPageJump: boolean;
showPageSizeOptions: boolean;
}
const PagerWrapper: any = styled("div")`
-webkit-tap-highlight-color: ${({ theme }) => (theme as any).colors.black};
-webkit-touch-callout: none;
align-items: center;
background-color: ${({ theme }) => (theme as any).colors.white};
border-top: 1px solid ${({ theme }) => (theme as any).colors.borderColor};
color: ${({ theme }) => (theme as any).colors.fontColor};
cursor: default;
display: flex;
outline: 0;
overflow: hidden;
padding: 0.375rem;
justify-content: flex-end;
ul {
margin: 0;
}
nav {
flex-grow: 1;
}
`;
const MAX_PAGER_BUTTONS = 10;
const getMaxPagerCount = (numPages, threshold = MAX_PAGER_BUTTONS) => {
return Math.min(numPages, threshold);
};
const getPagerRange = R.curry((page, totalPages, maxPagerItems) => {
if (page < maxPagerItems) {
return [0, maxPagerItems];
}
// avoid an off-by-one error
if (page % maxPagerItems === 0) {
page = page + 1;
}
const maxRange = Math.ceil(page / maxPagerItems) * maxPagerItems;
const minRange = maxRange - maxPagerItems;
return [minRange, maxRange > totalPages ? totalPages : maxRange];
});
const getCountInfo = (page, pageSize, ofText, dataSize) => {
if (!dataSize) {
return "";
}
const firstNum = page > 0 ? page * pageSize + 1 : 1;
const secondNum = firstNum - 1 + pageSize;
return `${firstNum} - ${secondNum > dataSize ? dataSize : secondNum} ${ofText} ${dataSize}`;
};
function Pagination(props: Props) {
const {
data,
canNext,
canPrevious,
defaultPage,
defaultPageSize,
loading,
nextText,
ofText,
page,
pageSize,
pageJumpText,
pageSizeOptions,
pageText,
pages,
previousText,
rowsText,
showPageJump,
showPageSizeOptions,
onPageChange,
} = props;
const incPage = R.compose(onPageChange, R.inc);
const decPage = R.compose(onPageChange, R.dec);
const isPageActive = R.equals(page);
const pagerRange = R.compose(R.apply(R.range), getPagerRange(page, pages), getMaxPagerCount)(pages);
return (
<PagerWrapper>
{pages > 1 && (
<RBPagination>
<PaginationItem disabled={!canPrevious} data-testid="react-table__pager__first">
<PaginationLink first href="#" onClick={() => onPageChange(0)} />
</PaginationItem>
<PaginationItem disabled={!canPrevious} data-testid="react-table__pager__prev">
<PaginationLink previous href="#" onClick={() => decPage(page)} aria-label={previousText} />
</PaginationItem>
{R.head(pagerRange) > 0 && (
<PaginationItem disabled={!canPrevious} data-testid="react-table__pager__prev-range">
<PaginationLink
previous
href="#"
onClick={() => R.compose(decPage, R.head)(pagerRange)}
aria-label={previousText}
>
...
</PaginationLink>
</PaginationItem>
)}
{R.compose(
R.map((n) => (
<PaginationItem active={isPageActive(n)} key={n}>
<PaginationLink
href="#"
onClick={() => isPageActive(n) || onPageChange(n)}
aria-label={`${pageText} ${n + 1}`}
>
{R.inc(n)}
</PaginationLink>
</PaginationItem>
)),
)(pagerRange)}
{R.last(pagerRange) < pages - 1 && (
<PaginationItem disabled={!canNext} data-testid="react-table__pager__next-range">
<PaginationLink
next
href="#"
onClick={() => R.compose(incPage, R.last)(pagerRange)}
aria-label={nextText}
>
...
</PaginationLink>
</PaginationItem>
)}
<PaginationItem disabled={!canNext} data-testid="react-table__pager__next">
<PaginationLink next href="#" onClick={() => incPage(page)} aria-label={nextText} />
</PaginationItem>
<PaginationItem disabled={!canNext} data-testid="react-table__pager__last">
<PaginationLink last href="#" onClick={() => onPageChange(pages)} aria-label={nextText} />
</PaginationItem>
</RBPagination>
)}
<div className="count" data-testid="react-table__pager__total">
{getCountInfo(page, pageSize, ofText, data.length)}
</div>
</PagerWrapper>
);
}
export { getMaxPagerCount, getCountInfo, getPagerRange };
export default Pagination;
|