stackpress
Version:
Incept is a content management framework.
20 lines (19 loc) • 1.15 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export default function Pagination(props) {
const { total = 0, skip = 0, take = 50, radius = 2, paginate = () => { } } = props;
const current = Math.floor(skip / take) + 1;
const max = Math.ceil(total / take);
const previous = current > 1;
const next = current < max;
const refresh = (page) => paginate(Math.max(page - 1, 0) * take);
const pages = [];
for (let i = current - 1 - radius; i < max; i++) {
if (i >= 0 && i < current + radius) {
pages.push(i + 1);
}
}
if (total <= take)
return null;
return (_jsxs("div", { className: "pagination", children: [previous && (_jsx("button", { className: "prev", onClick: () => refresh(current - 1), children: _jsx("i", { className: "fas fa-chevron-left" }) })), pages.map((page, i) => (_jsx("button", { onClick: () => refresh(page), className: `page ${page === current ? 'active' : ''}`, children: page }, i))), next && (_jsx("button", { className: "next", onClick: () => refresh(current + 1), children: _jsx("i", { className: "fas fa-chevron-right" }) }))] }));
}
;