UNPKG

@chayns-components/core

Version:

A set of beautiful React components for developing your own applications with chayns.

52 lines 1.19 kB
export const getNearestPoint = _ref => { let { snapPoints, position, scrollLeft } = _ref; let nearestIndex = -1; let nearestPoint = -Infinity; for (let i = 0; i < snapPoints.length; i++) { const index = snapPoints[i]; if (index && index < position + scrollLeft && index > nearestPoint) { nearestPoint = index; nearestIndex = i; } } nearestIndex = nearestIndex === -1 ? 0 : nearestIndex; nearestPoint = nearestPoint === -Infinity ? 0 : nearestPoint; return { nearestIndex, nearestPoint }; }; export const getThumbPosition = _ref2 => { let { itemWidth, scope } = _ref2; if (!scope.current) { return undefined; } const { transform } = scope.current.style; let position; if (transform === 'none') { position = 0; } else { const match = transform.match(/translateX\(([-\d.]+)px\)/); if (match && match[1]) { position = parseFloat(match[1]); } } if (typeof position !== 'number' && !position) { return undefined; } return { left: position, right: position + itemWidth, middle: position + itemWidth / 2 }; }; //# sourceMappingURL=sliderButton.js.map