@andreagiugni/tailwind-dashboard-ui 1.0.29 → 1.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -538,36 +538,48 @@ var justifyByAlign = {
538
538
  center: "justify-center",
539
539
  right: "justify-end"
540
540
  };
541
+ var getPaginationItems = (currentPage, totalPages) => {
542
+ const total = Math.max(1, totalPages);
543
+ const current = Math.min(Math.max(currentPage, 1), total);
544
+ if (total <= 3) {
545
+ return Array.from({ length: total }, (_, i) => i + 1);
546
+ }
547
+ if (current === 1) {
548
+ return [1, 2, "ellipsis", total];
549
+ }
550
+ if (current === total) {
551
+ return [1, "ellipsis", total - 1, total];
552
+ }
553
+ return [current - 1, current, current + 1];
554
+ };
541
555
  var Pagination = ({
542
556
  currentPage,
543
557
  totalPages,
544
558
  onPageChange,
545
559
  align
546
560
  }) => {
547
- const pagesAroundCurrent = Array.from(
548
- { length: Math.min(3, totalPages) },
549
- (_, i) => i + Math.max(currentPage - 1, 1)
550
- );
561
+ const total = Math.max(1, totalPages);
562
+ const current = Math.min(Math.max(currentPage, 1), total);
563
+ const paginationItems = getPaginationItems(current, total);
551
564
  const prev = /* @__PURE__ */ jsx(
552
565
  "button",
553
566
  {
554
- onClick: () => onPageChange(currentPage - 1),
555
- disabled: currentPage === 1,
567
+ onClick: () => onPageChange(current - 1),
568
+ disabled: current === 1,
556
569
  "aria-label": "Previous",
557
570
  className: navButton,
558
571
  children: "Previous"
559
572
  }
560
573
  );
561
- const indices = /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
562
- currentPage > 3 && /* @__PURE__ */ jsx("span", { className: "px-2", children: "..." }),
563
- pagesAroundCurrent.map((page) => /* @__PURE__ */ jsx(
574
+ const indices = /* @__PURE__ */ jsx("div", { className: "flex items-center gap-2", children: paginationItems.map(
575
+ (item, index) => item === "ellipsis" ? /* @__PURE__ */ jsx("span", { className: "px-2 text-gray-500 dark:text-gray-400", children: "..." }, `ellipsis-${index}`) : /* @__PURE__ */ jsx(
564
576
  "button",
565
577
  {
566
- onClick: () => onPageChange(page),
567
- "aria-current": currentPage === page ? "page" : void 0,
578
+ onClick: () => onPageChange(item),
579
+ "aria-current": current === item ? "page" : void 0,
568
580
  className: cn(
569
- "flex w-10 items-center justify-center h-10 rounded-lg text-sm font-medium",
570
- currentPage === page ? (
581
+ "flex h-10 w-10 items-center justify-center rounded-lg text-sm font-medium",
582
+ current === item ? (
571
583
  // active page keeps its color on hover (no hover restyle)
572
584
  "bg-brand-500 text-white"
573
585
  ) : (
@@ -575,17 +587,16 @@ var Pagination = ({
575
587
  "text-gray-700 hover:bg-blue-500/[0.08] hover:text-brand-500 dark:text-gray-400 dark:hover:text-brand-500"
576
588
  )
577
589
  ),
578
- children: page
590
+ children: item
579
591
  },
580
- page
581
- )),
582
- currentPage < totalPages - 2 && /* @__PURE__ */ jsx("span", { className: "px-2", children: "..." })
583
- ] });
592
+ item
593
+ )
594
+ ) });
584
595
  const next = /* @__PURE__ */ jsx(
585
596
  "button",
586
597
  {
587
- onClick: () => onPageChange(currentPage + 1),
588
- disabled: currentPage === totalPages,
598
+ onClick: () => onPageChange(current + 1),
599
+ disabled: current === total,
589
600
  "aria-label": "Next",
590
601
  className: navButton,
591
602
  children: "Next"