UNPKG

@researchgate/react-intersection-list

Version:

React List Component using the Intersection Observer API

48 lines (37 loc) 1.35 kB
"use strict"; exports.__esModule = true; exports.computeRootMargin = computeRootMargin; exports.getItemCount = getItemCount; exports.computeSize = computeSize; var _warning = _interopRequireDefault(require("warning")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 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(' '); } 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) { (0, _warning["default"])(!(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; } function computeSize(pageSize, itemCount) { return Math.max(0, Math.min(pageSize, itemCount)); }