UNPKG

@mankindui/core

Version:

- a react component library - you can see how @mankindui/core can be used via examples: [usage examples](https://github.com/clarklindev/mankindui-test)

29 lines (28 loc) 1.53 kB
import { j as i } from "../../_virtual/jsx-runtime.js"; const x = ({ totalItems: c, itemsPerPage: r, currentPage: d, onPageChange: l }) => { const t = Math.ceil(c / r), b = () => { const s = [], o = Math.max(d - 2, 1), a = Math.min(d + 2, t); for (let e = o; e <= a; e++) s.push(e); return o > 1 && (s.unshift(1), o > 2 && s.unshift(-1)), a < t && (s.push(-1), s.push(t)), s; }; return /* @__PURE__ */ i.jsxs("div", { className: "flex gap-2 justify-center mt-4", children: [ /* @__PURE__ */ i.jsx("button", { className: "px-3 py-1 border rounded disabled:opacity-50", onClick: () => l(1), disabled: d === 1, children: "First" }), /* @__PURE__ */ i.jsx("button", { className: "px-3 py-1 border rounded disabled:opacity-50", onClick: () => l(d - 1), disabled: d === 1, children: "Prev" }), b().map((s, n) => /* @__PURE__ */ i.jsx( "button", { onClick: () => s !== -1 ? l(s) : null, className: `px-3 py-1 border rounded ${s === d ? "bg-blue-500 text-white" : s === -1 ? "cursor-default" : "hover:bg-gray-200"}`, children: s === -1 ? "..." : s }, n )), /* @__PURE__ */ i.jsx("button", { className: "px-3 py-1 border rounded disabled:opacity-50", onClick: () => l(d + 1), disabled: d === t, children: "Next" }), /* @__PURE__ */ i.jsx("button", { className: "px-3 py-1 border rounded disabled:opacity-50", onClick: () => l(t), disabled: d === t, children: "Last" }) ] }); }; export { x as Pagination }; //# sourceMappingURL=index.js.map