UNPKG

@lanaco/lnc-react-ui

Version:

React component library

166 lines (165 loc) 3.95 kB
import { jsx as i, jsxs as G, Fragment as O } from "react/jsx-runtime"; import { useState as R } from "react"; import b from "./Button.js"; import g from "./IconButton.js"; import E from "./ButtonGroup.js"; import { s as B } from "./emotion-styled.browser.esm-DfbrHHed.js"; import { u as U } from "./emotion-element-f0de968e.browser.esm-CkCiQliQ.js"; import { u as k } from "./useUpdateEffect-CuYWz7EA.js"; const q = B.div` display: inline-flex; flex-wrap: wrap; width: 100%; gap: 0.375rem; justify-content: ${(u) => u.horizontalAlignment}; `, D = B.div` & > .button-group-pagination-lnc { width: 100%; justify-content: ${(u) => u.horizontalAlignment}; } `, Y = (u) => { const { icons: f = {}, borderRadius: d = "regular", currentPage: p = 1, buttonType: T = "outline", currentPageButtonType: v = "tinted", withFirstLast: h = !0, withButtonGroup: w = !0, disabledNext: N = !1, disabledPrevious: j = !1, disabledFirst: z = !1, disabledLast: S = !1, disabled: r = !1, totalNumberOfPages: c = 1, pagesOffset: m = 0, horizontalAlignment: y = "left", //------------------ onPageChange: A = () => { }, //------------------ className: x = "", style: P = {}, color: F = "primary", size: L = "small" } = u, s = { theme: U(), size: L, color: F, btnType: T }, [e, a] = R(p); k(() => { a(p); }, [p]), k(() => { A(e); }, [e]); const l = (o, t) => { t == "next" && e < c ? a(e + 1) : t == "previous" && e > 1 ? a(e - 1) : t == "last" && e != c ? a(c) : t == "first" && e != 1 ? a(1) : isNaN(+t) || a(t); }, $ = () => { let o = []; for (let t = e - m > 0 ? e - m : 1; t < e && t > 0; t++) o.push( /* @__PURE__ */ i( b, { ...s, borderRadius: d, onClick: (n) => l(n, t), btnType: "basic", text: t.toString(), disabled: r }, t ) ); o.push( /* @__PURE__ */ i( b, { ...s, borderRadius: d, btnType: v, text: e.toString(), disabled: r }, e ) ); for (let t = e + 1; t <= e + m && t <= c; t++) o.push( /* @__PURE__ */ i( b, { ...s, borderRadius: d, onClick: (n) => l(n, t), btnType: "basic", text: t.toString(), disabled: r }, t ) ); return o; }, C = (o = null) => { var t = {}; return o && (t.borderRadius = o), /* @__PURE__ */ G(O, { children: [ h && /* @__PURE__ */ i( g, { ...s, icon: f.doubleLeft || "angle-double-left", disabled: z || r, onClick: (n) => l(n, "first"), ...t } ), /* @__PURE__ */ i( g, { ...s, icon: f.left || "angle-left", disabled: j || r, onClick: (n) => l(n, "previous"), ...t } ), $(), /* @__PURE__ */ i( g, { ...s, icon: f.right || "angle-right", disabled: N || r, onClick: (n) => l(n, "next"), ...t } ), h && /* @__PURE__ */ i( g, { ...s, icon: f.doubleRight || "angle-double-right", disabled: S || r, onClick: (n) => l(n, "last"), ...t } ) ] }); }; return w ? /* @__PURE__ */ i(D, { horizontalAlignment: y, children: /* @__PURE__ */ i( E, { className: "button-group-pagination-lnc " + x, style: P, borderRadius: d, children: C() } ) }) : /* @__PURE__ */ i( q, { horizontalAlignment: y, className: x, style: P, children: C(d) } ); }; export { Y as default };