@sikt/sds-pagination 2.2.0 → 3.0.0
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/CHANGELOG.md +10 -0
- package/dist/index.d.mts +36 -5
- package/dist/index.d.ts +36 -5
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [3.0.0](https://gitlab.sikt.no/designsystem/sds-komponentbibliotek/compare/@sikt/sds-pagination@2.2.0...@sikt/sds-pagination@3.0.0) (2026-01-14)
|
|
6
|
+
|
|
7
|
+
### ⚠ BREAKING CHANGES
|
|
8
|
+
|
|
9
|
+
- **pagination:** rename handleClick prop to onClick to align with other components
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
- **pagination:** rename handleClick prop to onClick to align with other components ([2a6ccf5](https://gitlab.sikt.no/designsystem/sds-komponentbibliotek/commit/2a6ccf5fc9ce3c4356270b65992cd423b5e14a8a))
|
|
14
|
+
|
|
5
15
|
## [2.2.0](https://gitlab.sikt.no/designsystem/sds-komponentbibliotek/compare/@sikt/sds-pagination@2.1.1...@sikt/sds-pagination@2.2.0) (2025-07-08)
|
|
6
16
|
|
|
7
17
|
### Features
|
package/dist/index.d.mts
CHANGED
|
@@ -1,18 +1,49 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { HTMLAttributes } from 'react';
|
|
2
|
+
import { HTMLAttributes, MouseEvent } from 'react';
|
|
3
3
|
|
|
4
|
-
interface PaginationProps extends HTMLAttributes<HTMLElement> {
|
|
4
|
+
interface PaginationProps extends Omit<HTMLAttributes<HTMLElement>, "onClick"> {
|
|
5
|
+
/**
|
|
6
|
+
* Label for pagination navigation element.
|
|
7
|
+
*/
|
|
5
8
|
"aria-label": NonNullable<string>;
|
|
9
|
+
/**
|
|
10
|
+
* Label for previuos item button.
|
|
11
|
+
*
|
|
12
|
+
* @default "Vis forrige side"
|
|
13
|
+
*/
|
|
6
14
|
ariaLabelPrevious?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Label for next item button.
|
|
17
|
+
*
|
|
18
|
+
* @default "Vis neste side"
|
|
19
|
+
*/
|
|
7
20
|
ariaLabelNext?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Label item button.
|
|
23
|
+
*
|
|
24
|
+
* @default "Vis side"
|
|
25
|
+
*/
|
|
8
26
|
ariaLabelItem?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Totalt number of pages.
|
|
29
|
+
*/
|
|
9
30
|
count: number;
|
|
10
31
|
currentIndex: number;
|
|
11
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Total limit of elements, this includes previous/next/first/last. Minimum is 7 (previous/next/first/last/current/)
|
|
34
|
+
*/
|
|
12
35
|
limit?: number;
|
|
13
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Function for when the user clicks a pagination button.
|
|
38
|
+
*
|
|
39
|
+
* @default undefined
|
|
40
|
+
*/
|
|
41
|
+
onClick: (event: MouseEvent<HTMLButtonElement>, index: number) => void;
|
|
14
42
|
className?: string;
|
|
15
43
|
}
|
|
16
|
-
declare const Pagination:
|
|
44
|
+
declare const Pagination: {
|
|
45
|
+
({ "aria-label": ariaLabel, ariaLabelNext, ariaLabelPrevious, ariaLabelItem, count, currentIndex, limit, onClick, className, ...rest }: PaginationProps): react_jsx_runtime.JSX.Element;
|
|
46
|
+
displayName: string;
|
|
47
|
+
};
|
|
17
48
|
|
|
18
49
|
export { Pagination, type PaginationProps };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,49 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { HTMLAttributes } from 'react';
|
|
2
|
+
import { HTMLAttributes, MouseEvent } from 'react';
|
|
3
3
|
|
|
4
|
-
interface PaginationProps extends HTMLAttributes<HTMLElement> {
|
|
4
|
+
interface PaginationProps extends Omit<HTMLAttributes<HTMLElement>, "onClick"> {
|
|
5
|
+
/**
|
|
6
|
+
* Label for pagination navigation element.
|
|
7
|
+
*/
|
|
5
8
|
"aria-label": NonNullable<string>;
|
|
9
|
+
/**
|
|
10
|
+
* Label for previuos item button.
|
|
11
|
+
*
|
|
12
|
+
* @default "Vis forrige side"
|
|
13
|
+
*/
|
|
6
14
|
ariaLabelPrevious?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Label for next item button.
|
|
17
|
+
*
|
|
18
|
+
* @default "Vis neste side"
|
|
19
|
+
*/
|
|
7
20
|
ariaLabelNext?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Label item button.
|
|
23
|
+
*
|
|
24
|
+
* @default "Vis side"
|
|
25
|
+
*/
|
|
8
26
|
ariaLabelItem?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Totalt number of pages.
|
|
29
|
+
*/
|
|
9
30
|
count: number;
|
|
10
31
|
currentIndex: number;
|
|
11
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Total limit of elements, this includes previous/next/first/last. Minimum is 7 (previous/next/first/last/current/)
|
|
34
|
+
*/
|
|
12
35
|
limit?: number;
|
|
13
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Function for when the user clicks a pagination button.
|
|
38
|
+
*
|
|
39
|
+
* @default undefined
|
|
40
|
+
*/
|
|
41
|
+
onClick: (event: MouseEvent<HTMLButtonElement>, index: number) => void;
|
|
14
42
|
className?: string;
|
|
15
43
|
}
|
|
16
|
-
declare const Pagination:
|
|
44
|
+
declare const Pagination: {
|
|
45
|
+
({ "aria-label": ariaLabel, ariaLabelNext, ariaLabelPrevious, ariaLabelItem, count, currentIndex, limit, onClick, className, ...rest }: PaginationProps): react_jsx_runtime.JSX.Element;
|
|
46
|
+
displayName: string;
|
|
47
|
+
};
|
|
17
48
|
|
|
18
49
|
export { Pagination, type PaginationProps };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var a=require("@sikt/sds-icons"),e=require("clsx/lite"),i=require("react/jsx-runtime"),s=Object.defineProperty,t=Object.defineProperties,r=Object.getOwnPropertyDescriptors,l=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,
|
|
1
|
+
"use strict";var a=require("@sikt/sds-icons"),e=require("clsx/lite"),i=require("react/jsx-runtime"),s=Object.defineProperty,t=Object.defineProperties,r=Object.getOwnPropertyDescriptors,l=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,o=Object.prototype.propertyIsEnumerable,c=(a,e,i)=>e in a?s(a,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):a[e]=i,d=s=>{var d=s,{"aria-label":b,ariaLabelNext:u="Vis neste side",ariaLabelPrevious:m="Vis forrige side",ariaLabelItem:p="Vis side",count:x,currentIndex:j,limit:v=7,onClick:_,className:g}=d,N=((a,e)=>{var i={};for(var s in a)n.call(a,s)&&e.indexOf(s)<0&&(i[s]=a[s]);if(null!=a&&l)for(var s of l(a))e.indexOf(s)<0&&o.call(a,s)&&(i[s]=a[s]);return i})(d,["aria-label","ariaLabelNext","ariaLabelPrevious","ariaLabelItem","count","currentIndex","limit","onClick","className"]);const f=Math.ceil(v/2)-2-1,h=j+f,y=j-f,O=x-1-h-1,P=y-1;let k=x-1>h?h-1:h;k=P<0?k-P:k;let I=1<y?y+1:y;return I=O<0?I+O:I,i.jsx("nav",(L=((a,e)=>{for(var i in e||(e={}))n.call(e,i)&&c(a,i,e[i]);if(l)for(var i of l(e))o.call(e,i)&&c(a,i,e[i]);return a})({className:e.clsx("sds-pagination",g),"aria-label":b},N),C={children:i.jsxs("ol",{className:"sds-pagination__list",children:[i.jsx("li",{className:"sds-pagination__list-item",children:i.jsx("button",{className:"sds-pagination__button","aria-label":"".concat(m," ").concat(j),disabled:0===j,onClick:a=>{_(a,j-1)},children:i.jsx(a.MoveToPreviousIcon,{})})}),[...Array(x).keys()].map(a=>0===a||a===x-1||a>=I&&a<=k?i.jsx("li",{className:"sds-pagination__list-item",children:i.jsx("button",{className:"sds-pagination__button","aria-current":a===j||void 0,"aria-label":"".concat(p," ").concat(a+1),disabled:a===j,onClick:e=>{_(e,a)},children:a+1})},a):a==k+1||a==I-1?i.jsx("li",{className:"sds-pagination__list-item",children:i.jsx("div",{className:"sds-pagination__button--spacer",children:"…"})},a):void 0),i.jsx("li",{className:"sds-pagination__list-item",children:i.jsx("button",{className:"sds-pagination__button","aria-label":"".concat(u," ").concat(j+2),disabled:j===x-1,onClick:a=>{_(a,j+1)},children:i.jsx(a.MoveToNextIcon,{})})})]})},t(L,r(C))));var L,C};d.displayName="Pagination",exports.Pagination=d;//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/Pagination.tsx"],"names":["jsx","clsx","jsxs","MoveToPreviousIcon","MoveToNextIcon"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../src/Pagination.tsx"],"names":["jsx","clsx","jsxs","MoveToPreviousIcon","MoveToNextIcon"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDa,IAAA,UAAA,GAAa,CAAC,EAWJ,KAAA;AAXI,EACzB,IAAA,EAAA,GAAA,EAAA,EAAA;AAAA,IAAc,YAAA,EAAA,SAAA;AAAA,IACd,aAAgB,GAAA,gBAAA;AAAA,IAChB,iBAAoB,GAAA,kBAAA;AAAA,IACpB,aAAgB,GAAA,UAAA;AAAA,IAChB,KAAA;AAAA,IACA,YAAA;AAAA,IACA,KAAQ,GAAA,CAAA;AAAA,IACR,OAAA;AAAA,IACA;AAAA,GA1DF,GAiD2B,EAUtB,EAAA,IA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KAAA,GAAA;AAAA;AAAA,iBAVkC,KAY/C,CAAA;AAAA,qBAEO,KAAS,IAAA,QAAA,GAAW,CAAK,IAAA,KAAA,IAAS,WAAW,CAAG,EAAA;AACzD,YACE,uBAAAA,cAAA,CAAC,IAAG,EAAA,EAAA,SAAA,EAAU,2BACZ,EAAA,QAAA,kBAAAA,cAAA,CAAC,SAAI,SAAU,EAAA,gCAAA,EAAiC,QAAQ,EAAA,QAAA,EAAA,CAAA,EAAA,EADX,KAE/C,CAAA;AAAA;AAEJ,SACD,CAAA;AAAA,wBACDA,cAAA,CAAC,IAAG,EAAA,EAAA,SAAA,EAAU,2BACZ,EAAA,QAAA,kBAAAA,cAAA;AAAA,UAAC,QAAA;AAAA,UAAA;AAAA,YACC,SAAU,EAAA,wBAAA;AAAA,YACV,YAAY,EAAA,EAAA,CAAG,MAAa,CAAA,aAAA,EAAA,GAAA,CAAA,CAAI,MAAe,CAAA,YAAA,GAAA,CAAA,CAAA;AAAA,YAC/C,QAAA,EAAU,iBAAiB,KAAQ,GAAA,CAAA;AAAA,YACnC,OAAA,EAAS,CAAC,KAAU,KAAA;AAClB,cAAQ,OAAA,CAAA,KAAA,EAAO,eAAe,CAAC,CAAA;AAAA,aACjC;AAAA,YAEA,yCAACI,uBAAe,EAAA,EAAA;AAAA;AAAA,SAEpB,EAAA;AAAA,OACF,EAAA;AAAA,KAAA;AAAA,GACF;AAEJ;AACA,UAAA,CAAW,WAAc,GAAA,YAAA","file":"index.js","sourcesContent":["import { MoveToPreviousIcon, MoveToNextIcon } from \"@sikt/sds-icons\";\nimport { clsx } from \"clsx/lite\";\nimport { HTMLAttributes, MouseEvent } from \"react\";\nimport \"./pagination.pcss\";\n\nexport interface PaginationProps extends Omit<\n HTMLAttributes<HTMLElement>,\n \"onClick\"\n> {\n /**\n * Label for pagination navigation element.\n */\n \"aria-label\": NonNullable<string>;\n /**\n * Label for previuos item button.\n *\n * @default \"Vis forrige side\"\n */\n ariaLabelPrevious?: string;\n /**\n * Label for next item button.\n *\n * @default \"Vis neste side\"\n */\n ariaLabelNext?: string;\n /**\n * Label item button.\n *\n * @default \"Vis side\"\n */\n ariaLabelItem?: string;\n /**\n * Totalt number of pages.\n */\n count: number;\n currentIndex: number;\n /**\n * Total limit of elements, this includes previous/next/first/last. Minimum is 7 (previous/next/first/last/current/)\n */\n limit?: number;\n /**\n * Function for when the user clicks a pagination button.\n *\n * @default undefined\n */\n onClick: (event: MouseEvent<HTMLButtonElement>, index: number) => void;\n className?: string;\n}\n\nexport const Pagination = ({\n \"aria-label\": ariaLabel,\n ariaLabelNext = \"Vis neste side\",\n ariaLabelPrevious = \"Vis forrige side\",\n ariaLabelItem = \"Vis side\",\n count,\n currentIndex,\n limit = 7,\n onClick,\n className,\n ...rest\n}: PaginationProps) => {\n const constantCount = 2;\n const delimiter = Math.ceil(limit / 2) - constantCount - 1;\n const max = currentIndex + delimiter;\n const min = currentIndex - delimiter;\n const hasMaxSpacer = count - 1 > max;\n const hasMinSpacer = 1 < min;\n const maxModifier = count - 1 - max - 1;\n const minModifier = min - 1;\n const hasLessBeforeIndex = minModifier < 0;\n const hasLessAfterIndex = maxModifier < 0;\n let maxLimit = hasMaxSpacer ? max - 1 : max;\n maxLimit = hasLessBeforeIndex ? maxLimit - minModifier : maxLimit;\n let minLimit = hasMinSpacer ? min + 1 : min;\n minLimit = hasLessAfterIndex ? minLimit + maxModifier : minLimit;\n\n return (\n <nav\n className={clsx(\"sds-pagination\", className)}\n aria-label={ariaLabel}\n {...rest}\n >\n <ol className=\"sds-pagination__list\">\n <li className=\"sds-pagination__list-item\">\n <button\n className=\"sds-pagination__button\"\n aria-label={`${ariaLabelPrevious} ${currentIndex}`}\n disabled={currentIndex === 0}\n onClick={(event) => {\n onClick(event, currentIndex - 1);\n }}\n >\n <MoveToPreviousIcon />\n </button>\n </li>\n {[...Array(count).keys()].map((value) => {\n if (\n value === 0 ||\n value === count - 1 ||\n (value >= minLimit && value <= maxLimit)\n ) {\n return (\n <li className=\"sds-pagination__list-item\" key={value}>\n <button\n className=\"sds-pagination__button\"\n aria-current={value === currentIndex ? true : undefined}\n aria-label={`${ariaLabelItem} ${value + 1}`}\n disabled={value === currentIndex}\n onClick={(event) => {\n onClick(event, value);\n }}\n >\n {value + 1}\n </button>\n </li>\n );\n } else if (value == maxLimit + 1 || value == minLimit - 1) {\n return (\n <li className=\"sds-pagination__list-item\" key={value}>\n <div className=\"sds-pagination__button--spacer\">…</div>\n </li>\n );\n }\n })}\n <li className=\"sds-pagination__list-item\">\n <button\n className=\"sds-pagination__button\"\n aria-label={`${ariaLabelNext} ${currentIndex + 2}`}\n disabled={currentIndex === count - 1}\n onClick={(event) => {\n onClick(event, currentIndex + 1);\n }}\n >\n <MoveToNextIcon />\n </button>\n </li>\n </ol>\n </nav>\n );\n};\nPagination.displayName = \"Pagination\";\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{MoveToPreviousIcon as a,MoveToNextIcon as
|
|
1
|
+
import{MoveToPreviousIcon as a,MoveToNextIcon as i}from"@sikt/sds-icons";import{clsx as e}from"clsx/lite";import{jsx as t,jsxs as r}from"react/jsx-runtime";var l=Object.defineProperty,n=Object.defineProperties,s=Object.getOwnPropertyDescriptors,o=Object.getOwnPropertySymbols,c=Object.prototype.hasOwnProperty,d=Object.prototype.propertyIsEnumerable,b=(a,i,e)=>i in a?l(a,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[i]=e,m=l=>{var m=l,{"aria-label":p,ariaLabelNext:u="Vis neste side",ariaLabelPrevious:_="Vis forrige side",ariaLabelItem:f="Vis side",count:g,currentIndex:v,limit:N=7,onClick:h,className:y}=m,O=((a,i)=>{var e={};for(var t in a)c.call(a,t)&&i.indexOf(t)<0&&(e[t]=a[t]);if(null!=a&&o)for(var t of o(a))i.indexOf(t)<0&&d.call(a,t)&&(e[t]=a[t]);return e})(m,["aria-label","ariaLabelNext","ariaLabelPrevious","ariaLabelItem","count","currentIndex","limit","onClick","className"]);const x=Math.ceil(N/2)-2-1,P=v+x,j=v-x,k=g-1-P-1,L=j-1;let C=g-1>P?P-1:P;C=L<0?C-L:C;let I=1<j?j+1:j;return I=k<0?I+k:I,t("nav",(w=((a,i)=>{for(var e in i||(i={}))c.call(i,e)&&b(a,e,i[e]);if(o)for(var e of o(i))d.call(i,e)&&b(a,e,i[e]);return a})({className:e("sds-pagination",y),"aria-label":p},O),V={children:r("ol",{className:"sds-pagination__list",children:[t("li",{className:"sds-pagination__list-item",children:t("button",{className:"sds-pagination__button","aria-label":"".concat(_," ").concat(v),disabled:0===v,onClick:a=>{h(a,v-1)},children:t(a,{})})}),[...Array(g).keys()].map(a=>0===a||a===g-1||a>=I&&a<=C?t("li",{className:"sds-pagination__list-item",children:t("button",{className:"sds-pagination__button","aria-current":a===v||void 0,"aria-label":"".concat(f," ").concat(a+1),disabled:a===v,onClick:i=>{h(i,a)},children:a+1})},a):a==C+1||a==I-1?t("li",{className:"sds-pagination__list-item",children:t("div",{className:"sds-pagination__button--spacer",children:"…"})},a):void 0),t("li",{className:"sds-pagination__list-item",children:t("button",{className:"sds-pagination__button","aria-label":"".concat(u," ").concat(v+2),disabled:v===g-1,onClick:a=>{h(a,v+1)},children:t(i,{})})})]})},n(w,s(V))));var w,V};m.displayName="Pagination";export{m as Pagination};//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/Pagination.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../src/Pagination.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDa,IAAA,UAAA,GAAa,CAAC,EAWJ,KAAA;AAXI,EACzB,IAAA,EAAA,GAAA,EAAA,EAAA;AAAA,IAAc,YAAA,EAAA,SAAA;AAAA,IACd,aAAgB,GAAA,gBAAA;AAAA,IAChB,iBAAoB,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A;AAAA,gBACxC,UAAU,KAAU,KAAA,YAAA;AAAA,gBACpB,OAAA,EAAS,CAAC,KAAU,KAAA;AAClB,kBAAA,OAAA,CAAQ,OAAO,KAAK,CAAA;AAAA,iBACtB;AAAA,gBAEC,QAAQ,EAAA,KAAA,GAAA;AAAA;AAAA,iBAVkC,KAY/C,CAAA;AAAA,qBAEO,KAAS,IAAA,QAAA,GAAW,CAAK,IAAA,KAAA,IAAS,WAAW,CAAG,EAAA;AACzD,YACE,uBAAA,GAAA,CAAC,IAAG,EAAA,EAAA,SAAA,EAAU,2BACZ,EAAA,QAAA,kBAAA,GAAA,CAAC,SAAI,SAAU,EAAA,gCAAA,EAAiC,QAAQ,EAAA,QAAA,EAAA,CAAA,EAAA,EADX,KAE/C,CAAA;AAAA;AAEJ,SACD,CAAA;AAAA,wBACD,GAAA,CAAC,IAAG,EAAA,EAAA,SAAA,EAAU,2BACZ,EAAA,QAAA,kBAAA,GAAA;AAAA,UAAC,QAAA;AAAA,UAAA;AAAA,YACC,SAAU,EAAA,wBAAA;AAAA,YACV,YAAY,EAAA,EAAA,CAAG,MAAa,CAAA,aAAA,EAAA,GAAA,CAAA,CAAI,MAAe,CAAA,YAAA,GAAA,CAAA,CAAA;AAAA,YAC/C,QAAA,EAAU,iBAAiB,KAAQ,GAAA,CAAA;AAAA,YACnC,OAAA,EAAS,CAAC,KAAU,KAAA;AAClB,cAAQ,OAAA,CAAA,KAAA,EAAO,eAAe,CAAC,CAAA;AAAA,aACjC;AAAA,YAEA,8BAAC,cAAe,EAAA,EAAA;AAAA;AAAA,SAEpB,EAAA;AAAA,OACF,EAAA;AAAA,KAAA;AAAA,GACF;AAEJ;AACA,UAAA,CAAW,WAAc,GAAA,YAAA","file":"index.mjs","sourcesContent":["import { MoveToPreviousIcon, MoveToNextIcon } from \"@sikt/sds-icons\";\nimport { clsx } from \"clsx/lite\";\nimport { HTMLAttributes, MouseEvent } from \"react\";\nimport \"./pagination.pcss\";\n\nexport interface PaginationProps extends Omit<\n HTMLAttributes<HTMLElement>,\n \"onClick\"\n> {\n /**\n * Label for pagination navigation element.\n */\n \"aria-label\": NonNullable<string>;\n /**\n * Label for previuos item button.\n *\n * @default \"Vis forrige side\"\n */\n ariaLabelPrevious?: string;\n /**\n * Label for next item button.\n *\n * @default \"Vis neste side\"\n */\n ariaLabelNext?: string;\n /**\n * Label item button.\n *\n * @default \"Vis side\"\n */\n ariaLabelItem?: string;\n /**\n * Totalt number of pages.\n */\n count: number;\n currentIndex: number;\n /**\n * Total limit of elements, this includes previous/next/first/last. Minimum is 7 (previous/next/first/last/current/)\n */\n limit?: number;\n /**\n * Function for when the user clicks a pagination button.\n *\n * @default undefined\n */\n onClick: (event: MouseEvent<HTMLButtonElement>, index: number) => void;\n className?: string;\n}\n\nexport const Pagination = ({\n \"aria-label\": ariaLabel,\n ariaLabelNext = \"Vis neste side\",\n ariaLabelPrevious = \"Vis forrige side\",\n ariaLabelItem = \"Vis side\",\n count,\n currentIndex,\n limit = 7,\n onClick,\n className,\n ...rest\n}: PaginationProps) => {\n const constantCount = 2;\n const delimiter = Math.ceil(limit / 2) - constantCount - 1;\n const max = currentIndex + delimiter;\n const min = currentIndex - delimiter;\n const hasMaxSpacer = count - 1 > max;\n const hasMinSpacer = 1 < min;\n const maxModifier = count - 1 - max - 1;\n const minModifier = min - 1;\n const hasLessBeforeIndex = minModifier < 0;\n const hasLessAfterIndex = maxModifier < 0;\n let maxLimit = hasMaxSpacer ? max - 1 : max;\n maxLimit = hasLessBeforeIndex ? maxLimit - minModifier : maxLimit;\n let minLimit = hasMinSpacer ? min + 1 : min;\n minLimit = hasLessAfterIndex ? minLimit + maxModifier : minLimit;\n\n return (\n <nav\n className={clsx(\"sds-pagination\", className)}\n aria-label={ariaLabel}\n {...rest}\n >\n <ol className=\"sds-pagination__list\">\n <li className=\"sds-pagination__list-item\">\n <button\n className=\"sds-pagination__button\"\n aria-label={`${ariaLabelPrevious} ${currentIndex}`}\n disabled={currentIndex === 0}\n onClick={(event) => {\n onClick(event, currentIndex - 1);\n }}\n >\n <MoveToPreviousIcon />\n </button>\n </li>\n {[...Array(count).keys()].map((value) => {\n if (\n value === 0 ||\n value === count - 1 ||\n (value >= minLimit && value <= maxLimit)\n ) {\n return (\n <li className=\"sds-pagination__list-item\" key={value}>\n <button\n className=\"sds-pagination__button\"\n aria-current={value === currentIndex ? true : undefined}\n aria-label={`${ariaLabelItem} ${value + 1}`}\n disabled={value === currentIndex}\n onClick={(event) => {\n onClick(event, value);\n }}\n >\n {value + 1}\n </button>\n </li>\n );\n } else if (value == maxLimit + 1 || value == minLimit - 1) {\n return (\n <li className=\"sds-pagination__list-item\" key={value}>\n <div className=\"sds-pagination__button--spacer\">…</div>\n </li>\n );\n }\n })}\n <li className=\"sds-pagination__list-item\">\n <button\n className=\"sds-pagination__button\"\n aria-label={`${ariaLabelNext} ${currentIndex + 2}`}\n disabled={currentIndex === count - 1}\n onClick={(event) => {\n onClick(event, currentIndex + 1);\n }}\n >\n <MoveToNextIcon />\n </button>\n </li>\n </ol>\n </nav>\n );\n};\nPagination.displayName = \"Pagination\";\n"]}
|