UNPKG

@workday/canvas-kit-react

Version:

The parent module that contains all Workday Canvas Kit React components

91 lines (90 loc) 3.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getVisibleResultsMax = exports.getVisibleResultsMin = exports.getRangeMax = exports.getRangeMin = exports.getLastPage = void 0; /** * This function takes the number of results per page and the total count of results and returns the * last page number. Here's an example: * * Given there are 10 results per page, and there are 128 total results, the function will return 13. * * ```ts * const lastPage = getLastPage(10, 128); //=> 13 * ``` * * @param resultCount number of results per page * @param totalCount total number of results */ function getLastPage(resultCount, totalCount) { return Math.ceil(totalCount / resultCount); } exports.getLastPage = getLastPage; /** * This function takes the pagination range and returns its minimum value. Here's an example: * * Given the pagination range is 1-5, the function will return 1. * * ```ts * const range = [1, 2, 3, 4, 5]; * const rangeMin = getRangeMin(range); //=> 1 * ``` * @param range the range of numbers for the pagination component */ function getRangeMin(range) { return range[0]; } exports.getRangeMin = getRangeMin; /** * This function takes the pagination range and returns its maximum value. Here's an example: * * Given the pagination range is 1-5, the function will return 5. * * ```ts * const range = [1, 2, 3, 4, 5]; * const rangeMin = getRangeMax(range); //=> 5 * ``` * @param range the range of numbers for the pagination component */ function getRangeMax(range) { return range[range.length - 1]; } exports.getRangeMax = getRangeMax; /** * This function takes the current page, and number of results per page, and returns the minimum value * for that page. Here's an example: * * Given there are 10 results per page, and the current page is 5, the function will return 41. * * ```ts * const pageMin = getVisibleResultsMin(5, 10); //=> 41 * ``` * @param currentPage current page for the range * @param resultCount number of results per page */ function getVisibleResultsMin(currentPage, resultCount) { return currentPage * resultCount - resultCount + 1; } exports.getVisibleResultsMin = getVisibleResultsMin; /** * This function takes the current page, number of results per page, and the total number of results, * and returns the maximum value for that page. Here's an example: * * Given there are 10 results per page, the current page is 5, and there are 42 results total, the * function will return 42. * * ```ts * const currentPage = 5; * const resultCount = 10; * const totalCount = 42; * const pageMax = getVisibleResultsMax(currentPage, resultCount, totalCount); //=> 42 * ``` * @param currentPage current page for the range * @param resultCount number of results per page * @param totalCount total number of results */ function getVisibleResultsMax(currentPage, resultCount, totalCount) { if (totalCount < currentPage * resultCount) { return totalCount; } return currentPage * resultCount; } exports.getVisibleResultsMax = getVisibleResultsMax;