@veracity/vui
Version:
Veracity UI is a React component library crafted for use within Veracity applications and pages. Based on Styled Components and @xstyled.
28 lines (27 loc) • 1.19 kB
JavaScript
//#region src/pagination/helpers.ts
const range = (start, end) => {
const length = end - start + 1;
return Array.from({ length }, (_, i) => start + i);
};
/** Returns an array describing pagination items, like page buttons, prev/next arrows or ellipsis. */
function getPaginationItems(page, pageCount) {
const boundaryCount = 1;
const siblingCount = 1;
const startPages = range(1, Math.min(boundaryCount, pageCount));
const endPages = range(Math.max(pageCount - boundaryCount + 1, 2), pageCount);
const siblingsStart = Math.max(Math.min(page - siblingCount, pageCount - boundaryCount - 2 - 1), 3);
const siblingsEnd = Math.min(Math.max(page + siblingCount, 5), endPages.length > 0 ? endPages[0] - 2 : pageCount - 1);
return [
"previous",
...startPages,
...siblingsStart > 3 ? ["ellipsisStart"] : 2 < pageCount - boundaryCount ? [2] : [],
...range(siblingsStart, siblingsEnd),
...siblingsEnd < pageCount - boundaryCount - 1 ? ["ellipsisEnd"] : pageCount - boundaryCount > boundaryCount ? [pageCount - boundaryCount] : [],
...endPages,
"next"
];
}
//#endregion
export { getPaginationItems };
globalThis.__vuiVersion__ = "5.3.1"
//# sourceMappingURL=helpers.js.map