UNPKG

@jackiemacklein/nettz-utils

Version:

Serviços de imagem, e-mail, códigos de barras, utilitários numéricos e componentes React para apps Node.js com TypeScript

40 lines (39 loc) 2.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); const fa_1 = require("react-icons/fa"); require("./Pagination.css"); const Pagination = ({ currentPage, totalPage, onChangePage, size = "md", className = "" }) => { const getVisiblePages = () => { const delta = 2; // Número de páginas para mostrar antes e depois da atual const range = []; const rangeWithDots = []; for (let i = Math.max(2, currentPage - delta); i <= Math.min(totalPage - 1, currentPage + delta); i++) { range.push(i); } if (currentPage - delta > 2) { rangeWithDots.push(1, "..."); } else { rangeWithDots.push(1); } rangeWithDots.push(...range); if (currentPage + delta < totalPage - 1) { rangeWithDots.push("...", totalPage); } else if (totalPage > 1) { rangeWithDots.push(totalPage); } return rangeWithDots; }; const handlePageChange = (page) => { if (page >= 1 && page <= totalPage && page !== currentPage) { onChangePage(page); } }; if (totalPage <= 1) return null; const visiblePages = getVisiblePages(); return ((0, jsx_runtime_1.jsx)("nav", { className: `nettz-pagination nettz-pagination-${size} ${className}`, children: (0, jsx_runtime_1.jsxs)("ul", { className: "nettz-pagination-list", children: [(0, jsx_runtime_1.jsx)("li", { className: "nettz-pagination-item", children: (0, jsx_runtime_1.jsx)("button", { className: `nettz-pagination-link ${currentPage === 1 ? "nettz-pagination-disabled" : ""}`, onClick: () => handlePageChange(currentPage - 1), disabled: currentPage === 1, "aria-label": "P\u00E1gina anterior", children: (0, jsx_runtime_1.jsx)(fa_1.FaChevronLeft, {}) }) }), visiblePages.map((page, index) => ((0, jsx_runtime_1.jsx)("li", { className: "nettz-pagination-item", children: page === "..." ? ((0, jsx_runtime_1.jsx)("span", { className: "nettz-pagination-ellipsis", children: "..." })) : ((0, jsx_runtime_1.jsx)("button", { className: `nettz-pagination-link ${page === currentPage ? "nettz-pagination-active" : ""}`, onClick: () => handlePageChange(page), "aria-label": `Página ${page}`, "aria-current": page === currentPage ? "page" : undefined, children: page })) }, index))), (0, jsx_runtime_1.jsx)("li", { className: "nettz-pagination-item", children: (0, jsx_runtime_1.jsx)("button", { className: `nettz-pagination-link ${currentPage === totalPage ? "nettz-pagination-disabled" : ""}`, onClick: () => handlePageChange(currentPage + 1), disabled: currentPage === totalPage, "aria-label": "Pr\u00F3xima p\u00E1gina", children: (0, jsx_runtime_1.jsx)(fa_1.FaChevronRight, {}) }) })] }) })); }; exports.default = Pagination;