@bonprix-ds/react-pagination 1.1.6 → 1.1.7
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/index.d.ts +3 -35
- package/dist/index.js +13 -13
- package/dist/index.js.map +1 -1
- package/dist/src/Pagination.d.ts +25 -0
- package/dist/src/PaginationArrow.d.ts +9 -0
- package/dist/src/PaginationItem.d.ts +10 -0
- package/dist/src/utils.d.ts +1 -0
- package/package.json +29 -28
package/dist/index.d.ts
CHANGED
|
@@ -1,35 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare interface BaseProps {
|
|
6
|
-
/** The current active page number. */
|
|
7
|
-
currentPage: number;
|
|
8
|
-
/** The total number of pages. */
|
|
9
|
-
totalPages: number;
|
|
10
|
-
/** Callback function that is called when the page changes. The first parameter is the new page number, and the second parameter is the origin of the event ( `page`, `prev` or `next`) */
|
|
11
|
-
onPageChange: (newPage: number, origin: PaginationEventOrigin) => void;
|
|
12
|
-
/** Creates the individual page's `href` attributes taking into account the page's number.
|
|
13
|
-
* @param {number} pageNumber - the page number
|
|
14
|
-
* @returns {string} The `href` for the given page.
|
|
15
|
-
*/
|
|
16
|
-
constructPageHref: (pageNumber: number) => string;
|
|
17
|
-
/** Accessible label for screen readers. */
|
|
18
|
-
srLabel?: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export declare const calculateItems: (currentPage: number, totalPages: number, pagesShown?: 5 | 7) => (number | "ellipsis")[];
|
|
22
|
-
|
|
23
|
-
declare const Pagination: <C extends ElementType>({ currentPage, totalPages, onPageChange, srLabel, constructPageHref, itemComponent, itemProps, }: PaginationProps<C>) => default_2.JSX.Element;
|
|
24
|
-
export default Pagination;
|
|
25
|
-
|
|
26
|
-
declare type PaginationEventOrigin = "page" | "prev" | "next";
|
|
27
|
-
|
|
28
|
-
export declare type PaginationProps<C extends ElementType = "a"> = BaseProps & {
|
|
29
|
-
/** The semantic component to render the Items. Preferrably `"a"`, `"button"` or something like `Link` from NextJS. Native props will be passed to this component. */
|
|
30
|
-
itemComponent?: C;
|
|
31
|
-
/** Props that get passed to all items. Useful for setting props for NextJS `Link`s for example. */
|
|
32
|
-
itemProps?: Omit<ComponentProps<C>, "href">;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export { }
|
|
1
|
+
export { default } from "./src/Pagination";
|
|
2
|
+
export type { Props as PaginationProps } from "./src/Pagination";
|
|
3
|
+
export * from "./src/utils";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useBreakpointUp as e } from "@bonprix-ds/utils";
|
|
3
2
|
import "react";
|
|
4
|
-
import { tv as
|
|
3
|
+
import { tv as e } from "tailwind-variants";
|
|
4
|
+
import { useBreakpointUp as t } from "@bonprix-ds/utils";
|
|
5
5
|
import n from "@bonprix-ds/react-icon-button";
|
|
6
6
|
import { jsx as r, jsxs as i } from "react/jsx-runtime";
|
|
7
7
|
//#region src/PaginationArrow.tsx
|
|
@@ -13,7 +13,7 @@ var a = ({ position: e = "left", href: t, onClick: i, disabled: a = !1 }) => a ?
|
|
|
13
13
|
},
|
|
14
14
|
label: e === "left" ? "vorherige Seite" : "nächste Seite",
|
|
15
15
|
icon: e === "left" ? "arrow-left" : "arrow-right"
|
|
16
|
-
}), o =
|
|
16
|
+
}), o = e({
|
|
17
17
|
base: "preflight group relative inline-block leading-8 w-8 typography-button text-clr-on-bg-high text-center align-middle",
|
|
18
18
|
slots: { indicator: "absolute start-0 bottom-0 w-full bg-clr-primary" },
|
|
19
19
|
variants: { active: {
|
|
@@ -64,19 +64,19 @@ var a = ({ position: e = "left", href: t, onClick: i, disabled: a = !1 }) => a ?
|
|
|
64
64
|
t
|
|
65
65
|
];
|
|
66
66
|
}
|
|
67
|
-
}, l =
|
|
67
|
+
}, l = e({
|
|
68
68
|
base: "preflight flex items-center justify-center gap-2",
|
|
69
69
|
slots: {
|
|
70
70
|
orderedList: "flex items-center gap-2",
|
|
71
71
|
listItem: "list-none"
|
|
72
72
|
}
|
|
73
|
-
}), u = ({ currentPage:
|
|
74
|
-
let h = p, g = c(
|
|
73
|
+
}), u = ({ currentPage: e = 1, totalPages: n, onPageChange: o, srLabel: u, constructPageHref: f, itemComponent: p = "a", itemProps: m }) => {
|
|
74
|
+
let h = p, g = c(e, n, t("m") ? 7 : 5), _ = e === 1, v = e === n, y = () => e < n && o(e + 1, "next"), b = () => e > 1 && o(e - 1, "prev"), x = f(e - 1), S = f(e + 1), { base: C, listItem: w, orderedList: T } = l();
|
|
75
75
|
return /* @__PURE__ */ i("nav", {
|
|
76
76
|
className: C(),
|
|
77
77
|
"data-bpds": "pagination",
|
|
78
78
|
"aria-label": u,
|
|
79
|
-
"data-bpds-current-page":
|
|
79
|
+
"data-bpds-current-page": e,
|
|
80
80
|
"data-bpds-total-pages": n,
|
|
81
81
|
children: [
|
|
82
82
|
/* @__PURE__ */ r(a, {
|
|
@@ -87,15 +87,15 @@ var a = ({ position: e = "left", href: t, onClick: i, disabled: a = !1 }) => a ?
|
|
|
87
87
|
}),
|
|
88
88
|
/* @__PURE__ */ r("ol", {
|
|
89
89
|
className: T(),
|
|
90
|
-
children: g.map((
|
|
90
|
+
children: g.map((t, n) => /* @__PURE__ */ r("li", {
|
|
91
91
|
className: w(),
|
|
92
|
-
children: typeof
|
|
92
|
+
children: typeof t == "number" ? /* @__PURE__ */ r(s, {
|
|
93
93
|
component: h,
|
|
94
94
|
...m,
|
|
95
|
-
href: f(
|
|
96
|
-
pageNumber:
|
|
97
|
-
onClick: () => o(
|
|
98
|
-
active:
|
|
95
|
+
href: f(t),
|
|
96
|
+
pageNumber: t,
|
|
97
|
+
onClick: () => o(t, "page"),
|
|
98
|
+
active: t === e
|
|
99
99
|
}) : /* @__PURE__ */ r(d, {})
|
|
100
100
|
}, n))
|
|
101
101
|
}),
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/PaginationArrow.tsx","../src/PaginationItem.tsx","../src/utils.ts","../src/Pagination.tsx"],"sourcesContent":["import IconButton from \"@bonprix-ds/react-icon-button\";\nimport React from \"react\";\n\nexport interface PaginationArrowProps {\n position: \"left\" | \"right\";\n onClick: () => void;\n href: string;\n disabled?: boolean;\n}\n\nconst PaginationArrow = ({ position = \"left\", href, onClick, disabled = false }: PaginationArrowProps) => {\n const handleClick = (event: React.MouseEvent<HTMLAnchorElement>) => {\n event.preventDefault();\n onClick();\n };\n\n if (disabled) {\n return <div className=\"w-8 h-8\"></div>;\n }\n\n const previousPageLabel = \"vorherige Seite\";\n const nextPageLabel = \"nächste Seite\";\n const label = position === \"left\" ? previousPageLabel : nextPageLabel;\n const iconVariant = position === \"left\" ? \"arrow-left\" : \"arrow-right\";\n\n return <IconButton component=\"a\" href={href} onClick={handleClick} label={label} icon={iconVariant} />;\n};\n\nexport default PaginationArrow;\n","import React, { ComponentProps, ElementType } from \"react\";\nimport { tv } from \"tailwind-variants\";\n\nconst generateClasses = tv({\n base: \"preflight group relative inline-block leading-8 w-8 typography-button text-clr-on-bg-high text-center align-middle\",\n slots: {\n indicator: \"absolute start-0 bottom-0 w-full bg-clr-primary\",\n },\n variants: {\n active: {\n true: {\n indicator: \"h-1\",\n base: \"outline-none\",\n },\n false: {\n base: \"focus-visible:outline outline-2 outline-clr-on-bg-high outline-offset-2 focus-visible:rounded-sm\",\n indicator: \"group-hover:h-[0.0625rem] group-focus:group-hover:h-0\",\n },\n },\n },\n});\n\ninterface BaseProps {\n pageNumber: number;\n active?: boolean;\n}\n\ntype Props<C extends ElementType> = BaseProps & {\n component?: C;\n} & Omit<ComponentProps<C>, keyof BaseProps | \"component\">;\n\nconst PaginationItem = <C extends ElementType>({ pageNumber, active = false, component = \"a\" as C, ...props }: Props<C>) => {\n const { onClick, ...otherProps } = props;\n const Component: ElementType = component;\n const { base, indicator } = generateClasses({ active });\n const handleClick = (event: React.MouseEvent) => {\n event.preventDefault();\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n onClick?.();\n };\n\n return (\n <Component {...otherProps} className={base()} onClick={handleClick} aria-current={active ? \"page\" : undefined}>\n {pageNumber}\n <span className={indicator()}></span>\n </Component>\n );\n};\n\nexport default PaginationItem;\n","export const calculateItems: (currentPage: number, totalPages: number, pagesShown?: 5 | 7) => (number | \"ellipsis\")[] = (\n currentPage,\n totalPages,\n pagesShown = 7,\n) => {\n const range: number[] = [];\n\n // show all pages if total pages are less than or equal to pages shown\n if (totalPages <= pagesShown) {\n for (let i = 1; i <= totalPages; i++) {\n range.push(i);\n }\n return range;\n } else if (pagesShown === 7) {\n const rangeStart = Math.max(Math.min(currentPage - 1, totalPages - 4), 3);\n const rangeEnd = Math.max(Math.min(totalPages - 2, currentPage + 1), pagesShown - 2);\n const second = rangeStart === 3 ? 2 : \"ellipsis\";\n const penultimate = rangeEnd === totalPages - 2 ? totalPages - 1 : \"ellipsis\";\n\n for (let i = rangeStart; i <= rangeEnd; i++) {\n range.push(i);\n }\n return [1, second, ...range, penultimate, totalPages];\n } else {\n const atTheBeginning = currentPage <= 3;\n const atTheEnd = currentPage >= totalPages - 2;\n const second = atTheBeginning ? 2 : \"ellipsis\";\n const penultimate = atTheEnd ? totalPages - 1 : \"ellipsis\";\n const middlePage = atTheBeginning ? 3 : atTheEnd ? totalPages - 2 : currentPage;\n return [1, second, middlePage, penultimate, totalPages];\n }\n};\n","\"use client\";\n\nimport { useBreakpointUp } from \"@bonprix-ds/utils\";\nimport React, { ComponentProps, ElementType } from \"react\";\nimport { tv } from \"tailwind-variants\";\n\nimport PaginationArrow from \"./PaginationArrow\";\nimport PaginationItem from \"./PaginationItem\";\nimport { calculateItems } from \"./utils\";\n\nconst generateClasses = tv({\n base: \"preflight flex items-center justify-center gap-2\",\n slots: {\n orderedList: \"flex items-center gap-2\",\n listItem: \"list-none\",\n },\n});\n\ntype PaginationEventOrigin = \"page\" | \"prev\" | \"next\";\n\ninterface BaseProps {\n /** The current active page number. */\n currentPage: number;\n /** The total number of pages. */\n totalPages: number;\n /** Callback function that is called when the page changes. The first parameter is the new page number, and the second parameter is the origin of the event ( `page`, `prev` or `next`) */\n onPageChange: (newPage: number, origin: PaginationEventOrigin) => void;\n /** Creates the individual page's `href` attributes taking into account the page's number.\n * @param {number} pageNumber - the page number\n * @returns {string} The `href` for the given page.\n */\n constructPageHref: (pageNumber: number) => string;\n /** Accessible label for screen readers. */\n srLabel?: string;\n}\n\nexport type Props<C extends ElementType = \"a\"> = BaseProps & {\n /** The semantic component to render the Items. Preferrably `\"a\"`, `\"button\"` or something like `Link` from NextJS. Native props will be passed to this component. */\n itemComponent?: C;\n /** Props that get passed to all items. Useful for setting props for NextJS `Link`s for example. */\n itemProps?: Omit<ComponentProps<C>, \"href\">;\n};\n\nconst Pagination = <C extends ElementType>({\n currentPage = 1,\n totalPages,\n onPageChange,\n srLabel,\n constructPageHref,\n itemComponent = \"a\" as C,\n itemProps,\n}: Props<C>) => {\n const ItemComponent: ElementType = itemComponent;\n\n const isMOrUp = useBreakpointUp(\"m\");\n const pagesShown = isMOrUp ? 7 : 5;\n const pageItems = calculateItems(currentPage, totalPages, pagesShown);\n\n const disableLeftArrow = currentPage === 1;\n const disableRightArrow = currentPage === totalPages;\n\n const onNext = () => currentPage < totalPages && onPageChange(currentPage + 1, \"next\");\n const onPrevious = () => currentPage > 1 && onPageChange(currentPage - 1, \"prev\");\n const prevPageHref = constructPageHref(currentPage - 1);\n const nextPageHref = constructPageHref(currentPage + 1);\n const { base, listItem, orderedList } = generateClasses();\n\n return (\n <nav\n className={base()}\n data-bpds=\"pagination\"\n aria-label={srLabel}\n data-bpds-current-page={currentPage}\n data-bpds-total-pages={totalPages}\n >\n <PaginationArrow position=\"left\" href={prevPageHref} onClick={onPrevious} disabled={disableLeftArrow} />\n <ol className={orderedList()}>\n {pageItems.map((pagePosition, index) => {\n return (\n <li className={listItem()} key={index}>\n {typeof pagePosition === \"number\" ? (\n <PaginationItem\n component={ItemComponent}\n {...itemProps}\n href={constructPageHref(pagePosition)}\n pageNumber={pagePosition}\n onClick={() => onPageChange(pagePosition, \"page\")}\n active={pagePosition === currentPage}\n />\n ) : (\n <Ellipsis />\n )}\n </li>\n );\n })}\n </ol>\n <PaginationArrow position=\"right\" href={nextPageHref} onClick={onNext} disabled={disableRightArrow} />\n </nav>\n );\n};\n\nexport default Pagination;\n\nconst Ellipsis = () => <span className=\"w-8 inline-block text-center typography-button text-clr-on-bg-high\">…</span>;\n"],"mappings":";;;;;;;AAUA,IAAM,KAAmB,EAAE,cAAW,QAAQ,SAAM,YAAS,cAAW,SAMlE,IACK,kBAAC,OAAD,EAAK,WAAU,UAAe,CAAA,IAQhC,kBAAC,GAAD;CAAY,WAAU;CAAU;CAAM,UAdxB,MAA+C;EAElE,AADA,EAAM,eAAe,GACrB,EAAQ;CACV;CAW0E,OAH5D,MAAa,SAAS,oBAAoB;CAGyB,MAF7D,MAAa,SAAS,eAAe;AAE4C,CAAA,GCtBjG,IAAkB,EAAG;CACzB,MAAM;CACN,OAAO,EACL,WAAW,kDACb;CACA,UAAU,EACR,QAAQ;EACN,MAAM;GACJ,WAAW;GACX,MAAM;EACR;EACA,OAAO;GACL,MAAM;GACN,WAAW;EACb;CACF,EACF;AACF,CAAC,GAWK,KAAyC,EAAE,eAAY,YAAS,IAAO,eAAY,KAAU,GAAG,QAAsB;CAC1H,IAAM,EAAE,YAAS,GAAG,MAAe,GAC7B,IAAyB,GACzB,EAAE,SAAM,iBAAc,EAAgB,EAAE,UAAO,CAAC,GAChD,KAAe,MAA4B;EAG/C,AAFA,EAAM,eAAe,GAErB,IAAU;CACZ;CAEA,OACE,kBAAC,GAAD;EAAW,GAAI;EAAY,WAAW,EAAK;EAAG,SAAS;EAAa,gBAAc,IAAS,SAAS,KAAA;EAApG,UAAA,CACG,GACD,kBAAC,QAAD,EAAM,WAAW,EAAU,EAAS,CAAA,CAC3B;;AAEf,GC/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;CAExD,OACE,kBAAC,OAAD;EACE,WAAW,EAAK;EAChB,aAAU;EACV,cAAY;EACZ,0BAAwB;EACxB,yBAAuB;EALzB,UAAA;GAOE,kBAAC,GAAD;IAAiB,UAAS;IAAO,MAAM;IAAc,SAAS;IAAY,UAAU;GAAmB,CAAA;GACvG,kBAAC,MAAD;IAAI,WAAW,EAAY;IACxB,UAAA,EAAU,KAAK,GAAc,MAE1B,kBAAC,MAAD;KAAI,WAAW,EAAS;KACrB,UAAA,OAAO,KAAiB,WACvB,kBAAC,GAAD;MACE,WAAW;MACX,GAAI;MACJ,MAAM,EAAkB,CAAY;MACpC,YAAY;MACZ,eAAe,EAAa,GAAc,MAAM;MAChD,QAAQ,MAAiB;KAC1B,CAAA,IAED,kBAAC,GAAD,CAAW,CAAA;IAEX,GAb4B,CAa5B,CAEP;GACC,CAAA;GACJ,kBAAC,GAAD;IAAiB,UAAS;IAAQ,MAAM;IAAc,SAAS;IAAQ,UAAU;GAAoB,CAAA;EAClG;;AAET,GAIM,UAAiB,kBAAC,QAAD;CAAM,WAAU;CAAqE,UAAA;AAAO,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/PaginationArrow.tsx","../src/PaginationItem.tsx","../src/utils.ts","../src/Pagination.tsx"],"sourcesContent":["import React from \"react\";\n\nimport IconButton from \"@bonprix-ds/react-icon-button\";\n\nexport interface PaginationArrowProps {\n position: \"left\" | \"right\";\n onClick: () => void;\n href: string;\n disabled?: boolean;\n}\n\nconst PaginationArrow = ({ position = \"left\", href, onClick, disabled = false }: PaginationArrowProps) => {\n const handleClick = (event: React.MouseEvent<HTMLAnchorElement>) => {\n event.preventDefault();\n onClick();\n };\n\n if (disabled) {\n return <div className=\"w-8 h-8\"></div>;\n }\n\n const previousPageLabel = \"vorherige Seite\";\n const nextPageLabel = \"nächste Seite\";\n const label = position === \"left\" ? previousPageLabel : nextPageLabel;\n const iconVariant = position === \"left\" ? \"arrow-left\" : \"arrow-right\";\n\n return <IconButton component=\"a\" href={href} onClick={handleClick} label={label} icon={iconVariant} />;\n};\n\nexport default PaginationArrow;\n","import React, { ComponentProps, ElementType } from \"react\";\nimport { tv } from \"tailwind-variants\";\n\nconst generateClasses = tv({\n base: \"preflight group relative inline-block leading-8 w-8 typography-button text-clr-on-bg-high text-center align-middle\",\n slots: {\n indicator: \"absolute start-0 bottom-0 w-full bg-clr-primary\",\n },\n variants: {\n active: {\n true: {\n indicator: \"h-1\",\n base: \"outline-none\",\n },\n false: {\n base: \"focus-visible:outline outline-2 outline-clr-on-bg-high outline-offset-2 focus-visible:rounded-sm\",\n indicator: \"group-hover:h-[0.0625rem] group-focus:group-hover:h-0\",\n },\n },\n },\n});\n\ninterface BaseProps {\n pageNumber: number;\n active?: boolean;\n}\n\ntype Props<C extends ElementType> = BaseProps & {\n component?: C;\n} & Omit<ComponentProps<C>, keyof BaseProps | \"component\">;\n\nconst PaginationItem = <C extends ElementType>({ pageNumber, active = false, component = \"a\" as C, ...props }: Props<C>) => {\n const { onClick, ...otherProps } = props;\n const Component: ElementType = component;\n const { base, indicator } = generateClasses({ active });\n const handleClick = (event: React.MouseEvent) => {\n event.preventDefault();\n // oxlint-disable-next-line @typescript-eslint/no-unsafe-call\n onClick?.();\n };\n\n return (\n <Component {...otherProps} className={base()} onClick={handleClick} aria-current={active ? \"page\" : undefined}>\n {pageNumber}\n <span className={indicator()}></span>\n </Component>\n );\n};\n\nexport default PaginationItem;\n","export const calculateItems: (currentPage: number, totalPages: number, pagesShown?: 5 | 7) => (number | \"ellipsis\")[] = (\n currentPage,\n totalPages,\n pagesShown = 7,\n) => {\n const range: number[] = [];\n\n // show all pages if total pages are less than or equal to pages shown\n if (totalPages <= pagesShown) {\n for (let i = 1; i <= totalPages; i++) {\n range.push(i);\n }\n return range;\n } else if (pagesShown === 7) {\n const rangeStart = Math.max(Math.min(currentPage - 1, totalPages - 4), 3);\n const rangeEnd = Math.max(Math.min(totalPages - 2, currentPage + 1), pagesShown - 2);\n const second = rangeStart === 3 ? 2 : \"ellipsis\";\n const penultimate = rangeEnd === totalPages - 2 ? totalPages - 1 : \"ellipsis\";\n\n for (let i = rangeStart; i <= rangeEnd; i++) {\n range.push(i);\n }\n return [1, second, ...range, penultimate, totalPages];\n } else {\n const atTheBeginning = currentPage <= 3;\n const atTheEnd = currentPage >= totalPages - 2;\n const second = atTheBeginning ? 2 : \"ellipsis\";\n const penultimate = atTheEnd ? totalPages - 1 : \"ellipsis\";\n const middlePage = atTheBeginning ? 3 : atTheEnd ? totalPages - 2 : currentPage;\n return [1, second, middlePage, penultimate, totalPages];\n }\n};\n","\"use client\";\n\nimport React, { ComponentProps, ElementType } from \"react\";\nimport { tv } from \"tailwind-variants\";\n\nimport { useBreakpointUp } from \"@bonprix-ds/utils\";\n\nimport PaginationArrow from \"./PaginationArrow\";\nimport PaginationItem from \"./PaginationItem\";\nimport { calculateItems } from \"./utils\";\n\nconst generateClasses = tv({\n base: \"preflight flex items-center justify-center gap-2\",\n slots: {\n orderedList: \"flex items-center gap-2\",\n listItem: \"list-none\",\n },\n});\n\ntype PaginationEventOrigin = \"page\" | \"prev\" | \"next\";\n\ninterface BaseProps {\n /** The current active page number. */\n currentPage: number;\n /** The total number of pages. */\n totalPages: number;\n /** Callback function that is called when the page changes. The first parameter is the new page number, and the second parameter is the origin of the event ( `page`, `prev` or `next`) */\n onPageChange: (newPage: number, origin: PaginationEventOrigin) => void;\n /** Creates the individual page's `href` attributes taking into account the page's number.\n * @param {number} pageNumber - the page number\n * @returns {string} The `href` for the given page.\n */\n constructPageHref: (pageNumber: number) => string;\n /** Accessible label for screen readers. */\n srLabel?: string;\n}\n\nexport type Props<C extends ElementType = \"a\"> = BaseProps & {\n /** The semantic component to render the Items. Preferrably `\"a\"`, `\"button\"` or something like `Link` from NextJS. Native props will be passed to this component. */\n itemComponent?: C;\n /** Props that get passed to all items. Useful for setting props for NextJS `Link`s for example. */\n itemProps?: Omit<ComponentProps<C>, \"href\">;\n};\n\nconst Pagination = <C extends ElementType>({\n currentPage = 1,\n totalPages,\n onPageChange,\n srLabel,\n constructPageHref,\n itemComponent = \"a\" as C,\n itemProps,\n}: Props<C>) => {\n const ItemComponent: ElementType = itemComponent;\n\n const isMOrUp = useBreakpointUp(\"m\");\n const pagesShown = isMOrUp ? 7 : 5;\n const pageItems = calculateItems(currentPage, totalPages, pagesShown);\n\n const disableLeftArrow = currentPage === 1;\n const disableRightArrow = currentPage === totalPages;\n\n const onNext = () => currentPage < totalPages && onPageChange(currentPage + 1, \"next\");\n const onPrevious = () => currentPage > 1 && onPageChange(currentPage - 1, \"prev\");\n const prevPageHref = constructPageHref(currentPage - 1);\n const nextPageHref = constructPageHref(currentPage + 1);\n const { base, listItem, orderedList } = generateClasses();\n\n return (\n <nav\n className={base()}\n data-bpds=\"pagination\"\n aria-label={srLabel}\n data-bpds-current-page={currentPage}\n data-bpds-total-pages={totalPages}\n >\n <PaginationArrow position=\"left\" href={prevPageHref} onClick={onPrevious} disabled={disableLeftArrow} />\n <ol className={orderedList()}>\n {pageItems.map((pagePosition, index) => {\n return (\n <li className={listItem()} key={index}>\n {typeof pagePosition === \"number\" ? (\n <PaginationItem\n component={ItemComponent}\n {...itemProps}\n href={constructPageHref(pagePosition)}\n pageNumber={pagePosition}\n onClick={() => onPageChange(pagePosition, \"page\")}\n active={pagePosition === currentPage}\n />\n ) : (\n <Ellipsis />\n )}\n </li>\n );\n })}\n </ol>\n <PaginationArrow position=\"right\" href={nextPageHref} onClick={onNext} disabled={disableRightArrow} />\n </nav>\n );\n};\n\nexport default Pagination;\n\nconst Ellipsis = () => <span className=\"w-8 inline-block text-center typography-button text-clr-on-bg-high\">…</span>;\n"],"mappings":";;;;;;;AAWA,IAAM,KAAmB,EAAE,cAAW,QAAQ,SAAM,YAAS,cAAW,SAMlE,IACK,kBAAC,OAAD,EAAK,WAAU,UAAe,CAAA,IAQhC,kBAAC,GAAD;CAAY,WAAU;CAAU;CAAM,UAdxB,MAA+C;EAElE,AADA,EAAM,e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,GAAD;IAAiB,UAAS;IAAQ,MAAM;IAAc,SAAS;IAAQ,UAAU;GAAoB,CAAA;EAClG;;AAET,GAIM,UAAiB,kBAAC,QAAD;CAAM,WAAU;CAAqE,UAAA;AAAO,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React, { ComponentProps, ElementType } from "react";
|
|
2
|
+
type PaginationEventOrigin = "page" | "prev" | "next";
|
|
3
|
+
interface BaseProps {
|
|
4
|
+
/** The current active page number. */
|
|
5
|
+
currentPage: number;
|
|
6
|
+
/** The total number of pages. */
|
|
7
|
+
totalPages: number;
|
|
8
|
+
/** Callback function that is called when the page changes. The first parameter is the new page number, and the second parameter is the origin of the event ( `page`, `prev` or `next`) */
|
|
9
|
+
onPageChange: (newPage: number, origin: PaginationEventOrigin) => void;
|
|
10
|
+
/** Creates the individual page's `href` attributes taking into account the page's number.
|
|
11
|
+
* @param {number} pageNumber - the page number
|
|
12
|
+
* @returns {string} The `href` for the given page.
|
|
13
|
+
*/
|
|
14
|
+
constructPageHref: (pageNumber: number) => string;
|
|
15
|
+
/** Accessible label for screen readers. */
|
|
16
|
+
srLabel?: string;
|
|
17
|
+
}
|
|
18
|
+
export type Props<C extends ElementType = "a"> = BaseProps & {
|
|
19
|
+
/** The semantic component to render the Items. Preferrably `"a"`, `"button"` or something like `Link` from NextJS. Native props will be passed to this component. */
|
|
20
|
+
itemComponent?: C;
|
|
21
|
+
/** Props that get passed to all items. Useful for setting props for NextJS `Link`s for example. */
|
|
22
|
+
itemProps?: Omit<ComponentProps<C>, "href">;
|
|
23
|
+
};
|
|
24
|
+
declare const Pagination: <C extends ElementType>({ currentPage, totalPages, onPageChange, srLabel, constructPageHref, itemComponent, itemProps, }: Props<C>) => React.JSX.Element;
|
|
25
|
+
export default Pagination;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface PaginationArrowProps {
|
|
3
|
+
position: "left" | "right";
|
|
4
|
+
onClick: () => void;
|
|
5
|
+
href: string;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
}
|
|
8
|
+
declare const PaginationArrow: ({ position, href, onClick, disabled }: PaginationArrowProps) => React.JSX.Element;
|
|
9
|
+
export default PaginationArrow;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React, { ComponentProps, ElementType } from "react";
|
|
2
|
+
interface BaseProps {
|
|
3
|
+
pageNumber: number;
|
|
4
|
+
active?: boolean;
|
|
5
|
+
}
|
|
6
|
+
type Props<C extends ElementType> = BaseProps & {
|
|
7
|
+
component?: C;
|
|
8
|
+
} & Omit<ComponentProps<C>, keyof BaseProps | "component">;
|
|
9
|
+
declare const PaginationItem: <C extends ElementType>({ pageNumber, active, component, ...props }: Props<C>) => React.JSX.Element;
|
|
10
|
+
export default PaginationItem;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const calculateItems: (currentPage: number, totalPages: number, pagesShown?: 5 | 7) => (number | "ellipsis")[];
|
package/package.json
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bonprix-ds/react-pagination",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "Pagination component, implemented in React, for the Bonprix Design System.",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
"keywords": [],
|
|
6
|
+
"license": "UNLICENSED",
|
|
7
|
+
"author": "",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/bonprix/design-system.git",
|
|
11
|
+
"directory": "packages/react/pagination"
|
|
9
12
|
},
|
|
10
|
-
"
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"!dist/tsconfig.tsbuildinfo",
|
|
16
|
+
"!dist/vite.config.d.ts",
|
|
17
|
+
"!dist/**/*.test.d.ts"
|
|
18
|
+
],
|
|
19
|
+
"type": "module",
|
|
11
20
|
"sideEffects": false,
|
|
21
|
+
"module": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
12
23
|
"exports": {
|
|
13
24
|
".": {
|
|
14
25
|
"import": "./dist/index.js",
|
|
@@ -16,35 +27,25 @@
|
|
|
16
27
|
"default": "./dist/index.js"
|
|
17
28
|
}
|
|
18
29
|
},
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
],
|
|
23
|
-
"keywords": [],
|
|
24
|
-
"author": "",
|
|
25
|
-
"license": "UNLICENSED",
|
|
26
|
-
"repository": {
|
|
27
|
-
"type": "git",
|
|
28
|
-
"url": "git+https://github.com/bonprix/design-system.git",
|
|
29
|
-
"directory": "packages/react/pagination"
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public",
|
|
32
|
+
"provenance": true
|
|
30
33
|
},
|
|
31
34
|
"dependencies": {
|
|
32
|
-
"@bonprix-ds/react-icon-button": "1.2.
|
|
35
|
+
"@bonprix-ds/react-icon-button": "1.2.1",
|
|
33
36
|
"@bonprix-ds/utils": "0.2.2"
|
|
34
37
|
},
|
|
35
|
-
"peerDependencies": {
|
|
36
|
-
"react": "^19.0.0",
|
|
37
|
-
"react-dom": "^19.0.0",
|
|
38
|
-
"tailwind-variants": "0.3.1"
|
|
39
|
-
},
|
|
40
38
|
"devDependencies": {
|
|
41
|
-
"
|
|
42
|
-
"vitest": "4.1.11",
|
|
43
|
-
"@types/react": "19.2.18",
|
|
39
|
+
"@types/react": "19.3.0",
|
|
44
40
|
"@vitejs/plugin-react": "6.1.1",
|
|
45
41
|
"rollup-preserve-directives": "1.1.3",
|
|
46
|
-
"
|
|
47
|
-
"
|
|
42
|
+
"vite": "8.3.0",
|
|
43
|
+
"vitest": "4.1.11"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"react": "^19.3.0",
|
|
47
|
+
"react-dom": "^19.3.0",
|
|
48
|
+
"tailwind-variants": "0.3.1"
|
|
48
49
|
},
|
|
49
50
|
"scripts": {
|
|
50
51
|
"build": "vite build"
|