@nearform/quantum 1.7.1 → 1.7.2

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
@@ -3694,6 +3694,44 @@ var StepButtonStyles = (0, import_class_variance_authority21.cva)([
3694
3694
  "disabled:text-foreground-subtle",
3695
3695
  "dark:disabled:text-foreground-subtle-dark"
3696
3696
  ]);
3697
+ var noOfSiblings = 1;
3698
+ var noOfPagesShown = noOfSiblings * 2 + 5;
3699
+ var range = (from, to) => Array.from({ length: Math.max(0, to - from + 1) }, (_, i) => from + i);
3700
+ var pageWindow = (currentPage, totalPages) => {
3701
+ if (totalPages <= noOfPagesShown) {
3702
+ return {
3703
+ pageNumbers: range(1, totalPages),
3704
+ showLeftDots: false,
3705
+ showRightDots: false
3706
+ };
3707
+ }
3708
+ if (currentPage <= noOfPagesShown - 3) {
3709
+ return {
3710
+ pageNumbers: [...range(1, noOfPagesShown - 2), totalPages],
3711
+ showLeftDots: false,
3712
+ showRightDots: true
3713
+ };
3714
+ }
3715
+ if (currentPage < totalPages - 3) {
3716
+ return {
3717
+ pageNumbers: [
3718
+ 1,
3719
+ ...range(
3720
+ Math.max(2, currentPage - noOfSiblings),
3721
+ Math.min(totalPages - 1, currentPage + noOfSiblings)
3722
+ ),
3723
+ totalPages
3724
+ ],
3725
+ showLeftDots: true,
3726
+ showRightDots: true
3727
+ };
3728
+ }
3729
+ return {
3730
+ pageNumbers: [1, ...range(totalPages - noOfPagesShown + 3, totalPages)],
3731
+ showLeftDots: true,
3732
+ showRightDots: false
3733
+ };
3734
+ };
3697
3735
  var Pagination = import_react7.default.forwardRef(
3698
3736
  (_a, ref) => {
3699
3737
  var _b = _a, {
@@ -3723,42 +3761,10 @@ var Pagination = import_react7.default.forwardRef(
3723
3761
  currentRowsLength > 0 ? currentRowsLength / numberOfItemsPerPage : 0
3724
3762
  );
3725
3763
  }, [currentRowsLength, numberOfItemsPerPage]);
3726
- const allPages = [...Array(totalPages + 1).keys()].slice(1);
3727
- const [pageNumbers, setPageNumbers] = (0, import_react7.useState)(allPages);
3728
- const [showLeftDots, setShowLeftDots] = (0, import_react7.useState)(false);
3729
- const [showRightDots, setShowRightDots] = (0, import_react7.useState)(false);
3730
- const noOfSiblings = 1;
3731
- const noOfPagesShown = noOfSiblings * 2 + 5;
3732
- (0, import_react7.useEffect)(() => {
3733
- if (totalPages <= noOfPagesShown) {
3734
- setPageNumbers(allPages);
3735
- setShowRightDots(false);
3736
- setShowLeftDots(false);
3737
- } else if (currentPage <= noOfPagesShown - 3) {
3738
- const pages = allPages.slice(0, noOfPagesShown - 2);
3739
- pages.push(totalPages);
3740
- setPageNumbers(pages);
3741
- setShowRightDots(true);
3742
- setShowLeftDots(false);
3743
- } else if (noOfPagesShown - 3 < currentPage && currentPage < totalPages - 3) {
3744
- const pages = [1];
3745
- const start = Math.max(2, currentPage - noOfSiblings);
3746
- const end = Math.min(totalPages - 1, currentPage + noOfSiblings);
3747
- for (let i = start; i <= end; i++) {
3748
- pages.push(i);
3749
- }
3750
- pages.push(totalPages);
3751
- setPageNumbers(pages);
3752
- setShowRightDots(true);
3753
- setShowLeftDots(true);
3754
- } else if (currentPage >= totalPages - 3) {
3755
- const pages = allPages.slice(-noOfPagesShown + 2);
3756
- pages.unshift(1);
3757
- setPageNumbers(pages);
3758
- setShowRightDots(false);
3759
- setShowLeftDots(true);
3760
- }
3761
- }, [currentPage, totalPages]);
3764
+ const { pageNumbers, showLeftDots, showRightDots } = import_react7.default.useMemo(
3765
+ () => pageWindow(currentPage, totalPages),
3766
+ [currentPage, totalPages]
3767
+ );
3762
3768
  const goToNextPage = () => {
3763
3769
  if (currentPage !== totalPages) setCurrentPage(currentPage + 1);
3764
3770
  };