UNPKG

@researchgate/react-intersection-list

Version:

React List Component using the Intersection Observer API

36 lines (31 loc) 1.06 kB
import warning from 'warning'; export function computeRootMargin(_ref) { var threshold = _ref.threshold, axis = _ref.axis; var margins = [threshold]; var unit = threshold.match(/^-?\d*\.?\d+(px|%)$/) || ['']; var value = "0" + unit.pop(); if (axis === 'y') { margins.push(value); } else { margins.unshift(value); } return margins.join(' '); } export function getItemCount(_ref2, warnIfConflict) { var itemCount = _ref2.itemCount, items = _ref2.items; var hasItemCount = typeof itemCount !== 'undefined'; var hasItems = typeof items !== 'undefined'; var defaultValue = 0; if (warnIfConflict) { warning(!(hasItemCount && hasItems), 'ReactIntersectionList: cannot use itemCount and items props at the same time, choose one to determine the number of items to render.'); } if (hasItemCount) { return itemCount; } return hasItems ? items.length || items.size || defaultValue : defaultValue; } export function computeSize(pageSize, itemCount) { return Math.max(0, Math.min(pageSize, itemCount)); }