uikit/dist/pagination.js
Mohamadzadeh 1d78c19b1b
All checks were successful
Build and Deploy Next.js + Nginx Docker Image / build-and-deploy (push) Successful in 50s
Build and Deploy Next.js + Nginx Docker Image / deploy (push) Successful in 6s
change pagination icons
2026-07-09 16:18:10 +03:30

269 lines
7.3 KiB
JavaScript

import { jsxs as A, jsx as s } from "react/jsx-runtime";
import { useState as B, useRef as g, useEffect as v, useCallback as E } from "react";
import { HStack as y, IconButton as I, Button as N, Input as j, Text as M } from "@chakra-ui/react";
import { toFaDigits as f, toEnDigits as D } from "./utils.js";
import { C as z, a as S } from "./chunks/Pagination-DjllHYU8.js";
import { P as J } from "./chunks/Pagination-DjllHYU8.js";
const K = ({
currentPage: e,
totalPages: t,
totalCount: k,
onPageChange: a
}) => {
const [r, n] = B(f(e)), [d, c] = B(!1), [b, o] = B(null), x = g(null), h = [.../* @__PURE__ */ new Set([1, e, t])].filter(
(i) => i >= 1 && i <= t
);
v(() => {
if (b !== null) {
e === b && (o(null), c(!1), n(f(e)));
return;
}
d || n(f(e));
}, [e, d, b]), v(() => {
if (!d || !r || b !== null) return;
const i = parseInt(D(r), 10);
if (isNaN(i)) return;
const m = setTimeout(() => {
var C;
const u = Math.min(Math.max(i, 1), t);
u !== e ? (o(u), n(f(u)), a(u)) : (c(!1), n(f(e))), (C = x.current) == null || C.blur();
}, 1e3);
return () => clearTimeout(m);
}, [
r,
d,
b,
t,
e,
a
]);
const w = () => {
var u, C;
const i = parseInt(D(r), 10);
if (isNaN(i)) {
n(f(e)), c(!1), o(null), (u = x.current) == null || u.blur();
return;
}
const m = Math.min(Math.max(i, 1), t);
m !== e ? (o(m), n(f(m)), a(m)) : (n(f(e)), c(!1), o(null)), (C = x.current) == null || C.blur();
};
return t === 0 || !k ? null : /* @__PURE__ */ A(
y,
{
justifyContent: "space-around",
backgroundColor: "white",
py: "10px",
px: "16px",
rounded: "lg",
border: "1px",
borderColor: "blue.200",
w: "100%",
children: [
/* @__PURE__ */ A(y, { spacing: 2, alignItems: "center", justifyContent: "center", children: [
/* @__PURE__ */ s(
I,
{
size: "md",
bg: "#e6e6f1",
color: "#4B49AC",
_hover: { bg: "#cbcbe8" },
onClick: () => a(e - 1),
isDisabled: e === 1,
icon: /* @__PURE__ */ s(z, {}),
"aria-label": "صفحه قبلی"
}
),
h.map((i) => /* @__PURE__ */ s(
N,
{
size: "md",
px: 2,
bg: e === i ? "#4B49AC" : "#e6e6f1",
color: e === i ? "#e6e6f1" : "#4B49AC",
_hover: { bg: e === i ? "#4B49AC" : "#cbcbe8" },
onClick: () => a(i),
variant: "soft",
children: f(i)
},
i
)),
/* @__PURE__ */ s(
I,
{
size: "md",
bg: "#e6e6f1",
color: "#4B49AC",
_hover: { bg: "#cbcbe8" },
onClick: () => a(e + 1),
isDisabled: e === t,
icon: /* @__PURE__ */ s(S, {}),
"aria-label": "صفحه بعدی"
}
),
/* @__PURE__ */ s(
j,
{
ref: x,
type: "text",
inputMode: "numeric",
placeholder: "صفحه",
w: "56px",
value: r,
onFocus: () => {
c(!0), o(null), n("");
},
onChange: (i) => {
const m = i.target.value, u = D(m).replace(/\D/g, "");
n(f(u));
},
onBlur: () => {
r || (n(f(e)), c(!1), o(null));
},
onKeyDown: (i) => {
i.key === "Enter" && w();
},
textAlign: "center",
color: "#1D2939",
px: 1,
minW: 0,
dir: "ltr"
}
)
] }),
/* @__PURE__ */ A(y, { spacing: 2, children: [
/* @__PURE__ */ s(M, { w: "auto", fontWeight: "bold", whiteSpace: "nowrap", children: "تعداد کل:" }),
/* @__PURE__ */ s(M, { children: f(k) })
] })
]
}
);
}, H = ({
currentPage: e,
totalPages: t,
totalCount: k,
onPageChange: a
}) => {
const [r, n] = B(""), [d, c] = B(!1), [b, o] = B(null), x = g(null), h = b ?? e, w = E(
(l) => {
const p = Math.min(Math.max(l, 1), t);
c(!1), n(""), o(null), p !== e && a(p);
},
[e, t, a]
), i = E(() => {
if (!r) {
c(!1), n(""), o(null);
return;
}
const l = parseInt(D(r), 10);
if (isNaN(l)) {
c(!1), n(""), o(null);
return;
}
const p = Math.min(Math.max(l, 1), t);
c(!1), n(""), p !== e ? (o(p), a(p)) : o(null);
}, [r, e, t, a]);
v(() => {
var l;
d && ((l = x.current) == null || l.focus());
}, [d]), v(() => {
b !== null && e === b && o(null);
}, [e, b]), v(() => {
if (!d || !r) return;
const l = setTimeout(() => {
i();
}, 1e3);
return () => clearTimeout(l);
}, [r, d, i]);
const m = () => {
o(null), n(""), c(!0);
}, u = (l, p = !1) => /* @__PURE__ */ s(
N,
{
size: "md",
bg: p ? "#4B49AC" : "#e6e6f1",
color: p ? "#e6e6f1" : "#4B49AC",
_hover: { bg: p ? "#4B49AC" : "#cbcbe8" },
onClick: p ? m : () => w(l),
variant: "soft",
children: f(l)
},
l
);
if (t === 0 || !k) return null;
const C = t > 1 && h !== 1, T = t > 1 && h !== t;
return /* @__PURE__ */ s(
y,
{
justifyContent: "center",
backgroundColor: "white",
py: "10px",
px: "16px",
rounded: "lg",
border: "1px",
borderColor: "blue.200",
w: "100%",
children: /* @__PURE__ */ A(y, { spacing: 2, alignItems: "center", justifyContent: "center", children: [
/* @__PURE__ */ s(
I,
{
size: "md",
bg: "#e6e6f1",
color: "#4B49AC",
_hover: { bg: "#cbcbe8" },
onClick: () => w(h - 1),
isDisabled: h === 1,
icon: /* @__PURE__ */ s(z, {}),
"aria-label": "صفحه قبلی"
}
),
C && u(1),
d ? /* @__PURE__ */ s(
j,
{
ref: x,
type: "text",
inputMode: "numeric",
placeholder: "صفحه",
w: "48px",
value: r,
onChange: (l) => {
const p = l.target.value, V = D(p).replace(/\D/g, "");
n(f(V));
},
onBlur: () => {
r ? i() : (n(""), c(!1), o(null));
},
onKeyDown: (l) => {
l.key === "Enter" && i(), l.key === "Escape" && (n(""), c(!1), o(null));
},
textAlign: "center",
color: "#1D2939",
px: 1,
minW: 0,
dir: "ltr"
}
) : u(h, !0),
T && u(t),
/* @__PURE__ */ s(
I,
{
size: "md",
bg: "#e6e6f1",
color: "#4B49AC",
_hover: { bg: "#cbcbe8" },
onClick: () => w(h + 1),
isDisabled: h === t,
icon: /* @__PURE__ */ s(S, {}),
"aria-label": "صفحه بعدی"
}
)
] })
}
);
};
export {
K as LightPagination,
J as Pagination,
H as SimplePagination
};