@sustaina/shared-ui 1.6.1 → 1.6.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.mjs CHANGED
@@ -869,15 +869,33 @@ var DataTable = ({
869
869
  }, [centerVisibleLeafColumns, leftVisibleLeftColumns, rightVisibleLeafColumns]);
870
870
  const fetchMoreOnScrollReached = useCallback(
871
871
  (containerRefElement) => {
872
- if (!scrollFetch?.enabled) {
872
+ if (!scrollFetch?.enabled || !containerRefElement || scrollFetch?.isFetchingMore || !scrollFetch?.hasMore || !scrollFetch?.fetchMore) {
873
873
  return;
874
874
  }
875
- if (containerRefElement) {
876
- const { scrollHeight, scrollTop, clientHeight } = containerRefElement;
877
- const threshold = 1.5;
878
- if (scrollHeight - scrollTop - clientHeight < clientHeight * threshold && !scrollFetch?.isFetchingMore && scrollFetch?.hasMore && scrollFetch?.fetchMore) {
879
- scrollFetch.fetchMore();
880
- }
875
+ const { scrollHeight, scrollTop, clientHeight } = containerRefElement;
876
+ const scrollableHeight = scrollHeight - clientHeight;
877
+ const distanceToBottom = scrollHeight - clientHeight - scrollTop;
878
+ const ratioToBottom = scrollableHeight > 0 ? scrollTop / scrollableHeight : 1;
879
+ const info = {
880
+ scrollTop,
881
+ scrollHeight,
882
+ clientHeight,
883
+ scrollableHeight,
884
+ distanceToBottom,
885
+ ratioToBottom,
886
+ isTopReached: scrollTop === 0,
887
+ isBottomReached: distanceToBottom <= 0
888
+ };
889
+ let shouldTrigger = false;
890
+ if (typeof scrollFetch.scrollThreshold === "number") {
891
+ shouldTrigger = info.ratioToBottom >= scrollFetch.scrollThreshold;
892
+ } else if (typeof scrollFetch.scrollThreshold === "function") {
893
+ shouldTrigger = scrollFetch.scrollThreshold(info);
894
+ } else {
895
+ shouldTrigger = info.ratioToBottom >= 0.7;
896
+ }
897
+ if (shouldTrigger) {
898
+ scrollFetch.fetchMore();
881
899
  }
882
900
  },
883
901
  // eslint-disable-next-line react-hooks/exhaustive-deps