@defra/forms-model 3.0.600 → 3.0.601
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module/common/pagination/index.js +55 -0
- package/dist/module/common/pagination/index.js.map +1 -1
- package/dist/module/common/pagination/types.js.map +1 -1
- package/dist/types/common/pagination/index.d.ts +10 -1
- package/dist/types/common/pagination/index.d.ts.map +1 -1
- package/dist/types/common/pagination/types.d.ts +35 -0
- package/dist/types/common/pagination/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/common/pagination/index.ts +64 -1
- package/src/common/pagination/types.ts +41 -0
|
@@ -12,4 +12,59 @@ export const paginationOptionFields = {
|
|
|
12
12
|
* @see {@link PaginationOptions}
|
|
13
13
|
*/
|
|
14
14
|
export const paginationOptionsSchema = Joi.object(paginationOptionFields);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Builds the pages array for the GOV.UK Design System pagination component.
|
|
18
|
+
* Shows first page, last page, current page, and adjacent pages with ellipsis for gaps.
|
|
19
|
+
* @param currentPage - The current page number
|
|
20
|
+
* @param totalPages - The total number of pages
|
|
21
|
+
* @param createHref - Function to generate href for each page number
|
|
22
|
+
* @returns Array of pagination page items
|
|
23
|
+
*/
|
|
24
|
+
export function buildPaginationPages(currentPage, totalPages, createHref) {
|
|
25
|
+
const pages = [];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Creates a pagination page item
|
|
29
|
+
*/
|
|
30
|
+
function createPageItem(pageNumber, isCurrent = false) {
|
|
31
|
+
return {
|
|
32
|
+
number: String(pageNumber),
|
|
33
|
+
href: createHref(pageNumber),
|
|
34
|
+
current: isCurrent
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Always show the first page
|
|
39
|
+
pages.push(createPageItem(1, currentPage === 1));
|
|
40
|
+
|
|
41
|
+
// Calculate adjacent page range (one before and one after current)
|
|
42
|
+
const adjacentStartPage = Math.max(currentPage - 1, 2);
|
|
43
|
+
const adjacentEndPage = Math.min(currentPage + 1, totalPages - 1);
|
|
44
|
+
|
|
45
|
+
// Add ellipsis after first page if needed
|
|
46
|
+
if (adjacentStartPage > 2) {
|
|
47
|
+
pages.push({
|
|
48
|
+
ellipsis: true
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Add pages between adjacentStartPage and adjacentEndPage
|
|
53
|
+
for (let i = adjacentStartPage; i <= adjacentEndPage; i++) {
|
|
54
|
+
pages.push(createPageItem(i, i === currentPage));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Add ellipsis before last page if needed
|
|
58
|
+
if (adjacentEndPage < totalPages - 1) {
|
|
59
|
+
pages.push({
|
|
60
|
+
ellipsis: true
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Always show the last page if totalPages > 1
|
|
65
|
+
if (totalPages > 1) {
|
|
66
|
+
pages.push(createPageItem(totalPages, currentPage === totalPages));
|
|
67
|
+
}
|
|
68
|
+
return pages;
|
|
69
|
+
}
|
|
15
70
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Joi","paginationOptionFields","page","number","positive","integer","default","min","optional","description","perPage","max","paginationOptionsSchema","object"],"sources":["../../../../src/common/pagination/index.ts"],"sourcesContent":["import Joi from 'joi'\n\nimport { type PaginationOptions } from '~/src/common/pagination/types.js'\n\n/**\n * Field definitions for pagination options.\n */\nexport const paginationOptionFields = {\n page: Joi.number()\n .positive()\n .integer()\n .default(1)\n .min(1)\n .optional()\n .description('Current page number, starting from 1'),\n perPage: Joi.number()\n .positive()\n .integer()\n .default(24)\n .min(1)\n .max(200)\n .optional()\n .description('Number of items to display per page, between 1 and 200')\n}\n\n/**\n * Joi schema for `PaginationOptions` interface\n * @see {@link PaginationOptions}\n */\nexport const paginationOptionsSchema: Joi.ObjectSchema<PaginationOptions> =\n Joi.object(paginationOptionFields)\n"],"mappings":"AAAA,OAAOA,GAAG,MAAM,KAAK;
|
|
1
|
+
{"version":3,"file":"index.js","names":["Joi","paginationOptionFields","page","number","positive","integer","default","min","optional","description","perPage","max","paginationOptionsSchema","object","buildPaginationPages","currentPage","totalPages","createHref","pages","createPageItem","pageNumber","isCurrent","String","href","current","push","adjacentStartPage","Math","adjacentEndPage","ellipsis","i"],"sources":["../../../../src/common/pagination/index.ts"],"sourcesContent":["import Joi from 'joi'\n\nimport {\n type CreatePageHrefFn,\n type PaginationOptions,\n type PaginationPage\n} from '~/src/common/pagination/types.js'\n\n/**\n * Field definitions for pagination options.\n */\nexport const paginationOptionFields = {\n page: Joi.number()\n .positive()\n .integer()\n .default(1)\n .min(1)\n .optional()\n .description('Current page number, starting from 1'),\n perPage: Joi.number()\n .positive()\n .integer()\n .default(24)\n .min(1)\n .max(200)\n .optional()\n .description('Number of items to display per page, between 1 and 200')\n}\n\n/**\n * Joi schema for `PaginationOptions` interface\n * @see {@link PaginationOptions}\n */\nexport const paginationOptionsSchema: Joi.ObjectSchema<PaginationOptions> =\n Joi.object(paginationOptionFields)\n\n/**\n * Builds the pages array for the GOV.UK Design System pagination component.\n * Shows first page, last page, current page, and adjacent pages with ellipsis for gaps.\n * @param currentPage - The current page number\n * @param totalPages - The total number of pages\n * @param createHref - Function to generate href for each page number\n * @returns Array of pagination page items\n */\nexport function buildPaginationPages(\n currentPage: number,\n totalPages: number,\n createHref: CreatePageHrefFn\n): PaginationPage[] {\n const pages: PaginationPage[] = []\n\n /**\n * Creates a pagination page item\n */\n function createPageItem(\n pageNumber: number,\n isCurrent = false\n ): PaginationPage {\n return {\n number: String(pageNumber),\n href: createHref(pageNumber),\n current: isCurrent\n }\n }\n\n // Always show the first page\n pages.push(createPageItem(1, currentPage === 1))\n\n // Calculate adjacent page range (one before and one after current)\n const adjacentStartPage = Math.max(currentPage - 1, 2)\n const adjacentEndPage = Math.min(currentPage + 1, totalPages - 1)\n\n // Add ellipsis after first page if needed\n if (adjacentStartPage > 2) {\n pages.push({ ellipsis: true })\n }\n\n // Add pages between adjacentStartPage and adjacentEndPage\n for (let i = adjacentStartPage; i <= adjacentEndPage; i++) {\n pages.push(createPageItem(i, i === currentPage))\n }\n\n // Add ellipsis before last page if needed\n if (adjacentEndPage < totalPages - 1) {\n pages.push({ ellipsis: true })\n }\n\n // Always show the last page if totalPages > 1\n if (totalPages > 1) {\n pages.push(createPageItem(totalPages, currentPage === totalPages))\n }\n\n return pages\n}\n"],"mappings":"AAAA,OAAOA,GAAG,MAAM,KAAK;AAQrB;AACA;AACA;AACA,OAAO,MAAMC,sBAAsB,GAAG;EACpCC,IAAI,EAAEF,GAAG,CAACG,MAAM,CAAC,CAAC,CACfC,QAAQ,CAAC,CAAC,CACVC,OAAO,CAAC,CAAC,CACTC,OAAO,CAAC,CAAC,CAAC,CACVC,GAAG,CAAC,CAAC,CAAC,CACNC,QAAQ,CAAC,CAAC,CACVC,WAAW,CAAC,sCAAsC,CAAC;EACtDC,OAAO,EAAEV,GAAG,CAACG,MAAM,CAAC,CAAC,CAClBC,QAAQ,CAAC,CAAC,CACVC,OAAO,CAAC,CAAC,CACTC,OAAO,CAAC,EAAE,CAAC,CACXC,GAAG,CAAC,CAAC,CAAC,CACNI,GAAG,CAAC,GAAG,CAAC,CACRH,QAAQ,CAAC,CAAC,CACVC,WAAW,CAAC,wDAAwD;AACzE,CAAC;;AAED;AACA;AACA;AACA;AACA,OAAO,MAAMG,uBAA4D,GACvEZ,GAAG,CAACa,MAAM,CAACZ,sBAAsB,CAAC;;AAEpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASa,oBAAoBA,CAClCC,WAAmB,EACnBC,UAAkB,EAClBC,UAA4B,EACV;EAClB,MAAMC,KAAuB,GAAG,EAAE;;EAElC;AACF;AACA;EACE,SAASC,cAAcA,CACrBC,UAAkB,EAClBC,SAAS,GAAG,KAAK,EACD;IAChB,OAAO;MACLlB,MAAM,EAAEmB,MAAM,CAACF,UAAU,CAAC;MAC1BG,IAAI,EAAEN,UAAU,CAACG,UAAU,CAAC;MAC5BI,OAAO,EAAEH;IACX,CAAC;EACH;;EAEA;EACAH,KAAK,CAACO,IAAI,CAACN,cAAc,CAAC,CAAC,EAAEJ,WAAW,KAAK,CAAC,CAAC,CAAC;;EAEhD;EACA,MAAMW,iBAAiB,GAAGC,IAAI,CAAChB,GAAG,CAACI,WAAW,GAAG,CAAC,EAAE,CAAC,CAAC;EACtD,MAAMa,eAAe,GAAGD,IAAI,CAACpB,GAAG,CAACQ,WAAW,GAAG,CAAC,EAAEC,UAAU,GAAG,CAAC,CAAC;;EAEjE;EACA,IAAIU,iBAAiB,GAAG,CAAC,EAAE;IACzBR,KAAK,CAACO,IAAI,CAAC;MAAEI,QAAQ,EAAE;IAAK,CAAC,CAAC;EAChC;;EAEA;EACA,KAAK,IAAIC,CAAC,GAAGJ,iBAAiB,EAAEI,CAAC,IAAIF,eAAe,EAAEE,CAAC,EAAE,EAAE;IACzDZ,KAAK,CAACO,IAAI,CAACN,cAAc,CAACW,CAAC,EAAEA,CAAC,KAAKf,WAAW,CAAC,CAAC;EAClD;;EAEA;EACA,IAAIa,eAAe,GAAGZ,UAAU,GAAG,CAAC,EAAE;IACpCE,KAAK,CAACO,IAAI,CAAC;MAAEI,QAAQ,EAAE;IAAK,CAAC,CAAC;EAChC;;EAEA;EACA,IAAIb,UAAU,GAAG,CAAC,EAAE;IAClBE,KAAK,CAACO,IAAI,CAACN,cAAc,CAACH,UAAU,EAAED,WAAW,KAAKC,UAAU,CAAC,CAAC;EACpE;EAEA,OAAOE,KAAK;AACd","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../../src/common/pagination/types.ts"],"sourcesContent":["/**\n * Result of pagination containing page information\n */\nexport interface PaginationResult {\n /**\n * The current page number.\n */\n page: number\n\n /**\n * The number of items per page.\n */\n perPage: number\n\n /**\n * The total number of items available.\n */\n totalItems: number\n\n /**\n * The total number of pages available.\n */\n totalPages: number\n}\n\n/**\n * Options for paginating results\n * Allows partial specification of page and perPage from PaginationResult\n */\nexport type PaginationOptions = Required<\n Pick<PaginationResult, 'page' | 'perPage'>\n>\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../../src/common/pagination/types.ts"],"sourcesContent":["/**\n * Result of pagination containing page information\n */\nexport interface PaginationResult {\n /**\n * The current page number.\n */\n page: number\n\n /**\n * The number of items per page.\n */\n perPage: number\n\n /**\n * The total number of items available.\n */\n totalItems: number\n\n /**\n * The total number of pages available.\n */\n totalPages: number\n}\n\n/**\n * Options for paginating results\n * Allows partial specification of page and perPage from PaginationResult\n */\nexport type PaginationOptions = Required<\n Pick<PaginationResult, 'page' | 'perPage'>\n>\n\n/**\n * A single page item for the pagination component\n */\nexport interface PaginationPage {\n /**\n * The page number (if it's a page, not an ellipsis)\n */\n number?: string\n\n /**\n * The URL for the page\n */\n href?: string\n\n /**\n * Whether this page is the current page\n */\n current?: boolean\n\n /**\n * Whether this entry is an ellipsis (gap indicator)\n */\n ellipsis?: boolean\n}\n\n/**\n * Callback function to generate href for a given page number\n */\nexport type CreatePageHrefFn = (pageNumber: number) => string\n\n/**\n * Pagination result with page items for the pagination component\n * Extends PaginationResult with the pages array needed for rendering\n */\nexport interface PaginationResultWithPages extends PaginationResult {\n /**\n * Page items for the pagination component\n */\n pages: PaginationPage[]\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Joi from 'joi';
|
|
2
|
-
import { type PaginationOptions } from '../../common/pagination/types.js';
|
|
2
|
+
import { type CreatePageHrefFn, type PaginationOptions, type PaginationPage } from '../../common/pagination/types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Field definitions for pagination options.
|
|
5
5
|
*/
|
|
@@ -12,4 +12,13 @@ export declare const paginationOptionFields: {
|
|
|
12
12
|
* @see {@link PaginationOptions}
|
|
13
13
|
*/
|
|
14
14
|
export declare const paginationOptionsSchema: Joi.ObjectSchema<PaginationOptions>;
|
|
15
|
+
/**
|
|
16
|
+
* Builds the pages array for the GOV.UK Design System pagination component.
|
|
17
|
+
* Shows first page, last page, current page, and adjacent pages with ellipsis for gaps.
|
|
18
|
+
* @param currentPage - The current page number
|
|
19
|
+
* @param totalPages - The total number of pages
|
|
20
|
+
* @param createHref - Function to generate href for each page number
|
|
21
|
+
* @returns Array of pagination page items
|
|
22
|
+
*/
|
|
23
|
+
export declare function buildPaginationPages(currentPage: number, totalPages: number, createHref: CreatePageHrefFn): PaginationPage[];
|
|
15
24
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/common/pagination/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAA;AAErB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/common/pagination/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAA;AAErB,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACpB,MAAM,kCAAkC,CAAA;AAEzC;;GAEG;AACH,eAAO,MAAM,sBAAsB;;;CAgBlC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,uBAAuB,EAAE,GAAG,CAAC,YAAY,CAAC,iBAAiB,CACpC,CAAA;AAEpC;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,gBAAgB,GAC3B,cAAc,EAAE,CA6ClB"}
|
|
@@ -24,4 +24,39 @@ export interface PaginationResult {
|
|
|
24
24
|
* Allows partial specification of page and perPage from PaginationResult
|
|
25
25
|
*/
|
|
26
26
|
export type PaginationOptions = Required<Pick<PaginationResult, 'page' | 'perPage'>>;
|
|
27
|
+
/**
|
|
28
|
+
* A single page item for the pagination component
|
|
29
|
+
*/
|
|
30
|
+
export interface PaginationPage {
|
|
31
|
+
/**
|
|
32
|
+
* The page number (if it's a page, not an ellipsis)
|
|
33
|
+
*/
|
|
34
|
+
number?: string;
|
|
35
|
+
/**
|
|
36
|
+
* The URL for the page
|
|
37
|
+
*/
|
|
38
|
+
href?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Whether this page is the current page
|
|
41
|
+
*/
|
|
42
|
+
current?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Whether this entry is an ellipsis (gap indicator)
|
|
45
|
+
*/
|
|
46
|
+
ellipsis?: boolean;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Callback function to generate href for a given page number
|
|
50
|
+
*/
|
|
51
|
+
export type CreatePageHrefFn = (pageNumber: number) => string;
|
|
52
|
+
/**
|
|
53
|
+
* Pagination result with page items for the pagination component
|
|
54
|
+
* Extends PaginationResult with the pages array needed for rendering
|
|
55
|
+
*/
|
|
56
|
+
export interface PaginationResultWithPages extends PaginationResult {
|
|
57
|
+
/**
|
|
58
|
+
* Page items for the pagination component
|
|
59
|
+
*/
|
|
60
|
+
pages: PaginationPage[];
|
|
61
|
+
}
|
|
27
62
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/common/pagination/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;IAElB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;CACnB;AAED;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,QAAQ,CACtC,IAAI,CAAC,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC,CAC3C,CAAA"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/common/pagination/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;IAElB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;CACnB;AAED;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,QAAQ,CACtC,IAAI,CAAC,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC,CAC3C,CAAA;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,UAAU,EAAE,MAAM,KAAK,MAAM,CAAA;AAE7D;;;GAGG;AACH,MAAM,WAAW,yBAA0B,SAAQ,gBAAgB;IACjE;;OAEG;IACH,KAAK,EAAE,cAAc,EAAE,CAAA;CACxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import Joi from 'joi'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
type CreatePageHrefFn,
|
|
5
|
+
type PaginationOptions,
|
|
6
|
+
type PaginationPage
|
|
7
|
+
} from '~/src/common/pagination/types.js'
|
|
4
8
|
|
|
5
9
|
/**
|
|
6
10
|
* Field definitions for pagination options.
|
|
@@ -29,3 +33,62 @@ export const paginationOptionFields = {
|
|
|
29
33
|
*/
|
|
30
34
|
export const paginationOptionsSchema: Joi.ObjectSchema<PaginationOptions> =
|
|
31
35
|
Joi.object(paginationOptionFields)
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Builds the pages array for the GOV.UK Design System pagination component.
|
|
39
|
+
* Shows first page, last page, current page, and adjacent pages with ellipsis for gaps.
|
|
40
|
+
* @param currentPage - The current page number
|
|
41
|
+
* @param totalPages - The total number of pages
|
|
42
|
+
* @param createHref - Function to generate href for each page number
|
|
43
|
+
* @returns Array of pagination page items
|
|
44
|
+
*/
|
|
45
|
+
export function buildPaginationPages(
|
|
46
|
+
currentPage: number,
|
|
47
|
+
totalPages: number,
|
|
48
|
+
createHref: CreatePageHrefFn
|
|
49
|
+
): PaginationPage[] {
|
|
50
|
+
const pages: PaginationPage[] = []
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Creates a pagination page item
|
|
54
|
+
*/
|
|
55
|
+
function createPageItem(
|
|
56
|
+
pageNumber: number,
|
|
57
|
+
isCurrent = false
|
|
58
|
+
): PaginationPage {
|
|
59
|
+
return {
|
|
60
|
+
number: String(pageNumber),
|
|
61
|
+
href: createHref(pageNumber),
|
|
62
|
+
current: isCurrent
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Always show the first page
|
|
67
|
+
pages.push(createPageItem(1, currentPage === 1))
|
|
68
|
+
|
|
69
|
+
// Calculate adjacent page range (one before and one after current)
|
|
70
|
+
const adjacentStartPage = Math.max(currentPage - 1, 2)
|
|
71
|
+
const adjacentEndPage = Math.min(currentPage + 1, totalPages - 1)
|
|
72
|
+
|
|
73
|
+
// Add ellipsis after first page if needed
|
|
74
|
+
if (adjacentStartPage > 2) {
|
|
75
|
+
pages.push({ ellipsis: true })
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Add pages between adjacentStartPage and adjacentEndPage
|
|
79
|
+
for (let i = adjacentStartPage; i <= adjacentEndPage; i++) {
|
|
80
|
+
pages.push(createPageItem(i, i === currentPage))
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Add ellipsis before last page if needed
|
|
84
|
+
if (adjacentEndPage < totalPages - 1) {
|
|
85
|
+
pages.push({ ellipsis: true })
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Always show the last page if totalPages > 1
|
|
89
|
+
if (totalPages > 1) {
|
|
90
|
+
pages.push(createPageItem(totalPages, currentPage === totalPages))
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return pages
|
|
94
|
+
}
|
|
@@ -30,3 +30,44 @@ export interface PaginationResult {
|
|
|
30
30
|
export type PaginationOptions = Required<
|
|
31
31
|
Pick<PaginationResult, 'page' | 'perPage'>
|
|
32
32
|
>
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A single page item for the pagination component
|
|
36
|
+
*/
|
|
37
|
+
export interface PaginationPage {
|
|
38
|
+
/**
|
|
39
|
+
* The page number (if it's a page, not an ellipsis)
|
|
40
|
+
*/
|
|
41
|
+
number?: string
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The URL for the page
|
|
45
|
+
*/
|
|
46
|
+
href?: string
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Whether this page is the current page
|
|
50
|
+
*/
|
|
51
|
+
current?: boolean
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Whether this entry is an ellipsis (gap indicator)
|
|
55
|
+
*/
|
|
56
|
+
ellipsis?: boolean
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Callback function to generate href for a given page number
|
|
61
|
+
*/
|
|
62
|
+
export type CreatePageHrefFn = (pageNumber: number) => string
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Pagination result with page items for the pagination component
|
|
66
|
+
* Extends PaginationResult with the pages array needed for rendering
|
|
67
|
+
*/
|
|
68
|
+
export interface PaginationResultWithPages extends PaginationResult {
|
|
69
|
+
/**
|
|
70
|
+
* Page items for the pagination component
|
|
71
|
+
*/
|
|
72
|
+
pages: PaginationPage[]
|
|
73
|
+
}
|