Sha256: f80046056657063ef73d579d94135acd16328425cc9f4390ff7a2d20db48eea2
Contents?: true
Size: 985 Bytes
Versions: 26
Compression:
Stored size: 985 Bytes
Contents
/** * Creates the next position for the active item considering a finite list of * items to be rendered on a page. */ export function finite({ active, pageSize, total, }) { const middle = Math.floor(pageSize / 2); if (total <= pageSize || active < middle) return active; if (active >= total - middle) return active + pageSize - total; return middle; } /** * Creates the next position for the active item considering an infinitely * looping list of items to be rendered on the page. */ export function infinite({ active, lastActive, total, pageSize, pointer, }) { if (total <= pageSize) return active; // Move the position only when the user moves down, and when the // navigation fits within a single page if (lastActive < active && active - lastActive < pageSize) { // Limit it to the middle of the list return Math.min(Math.floor(pageSize / 2), pointer + active - lastActive); } return pointer; }
Version data entries
26 entries across 26 versions & 1 rubygems