@rubenpazch/pagination 3.3.0 → 3.4.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/README.md +33 -32
- package/dist/Pagination.d.ts +9 -0
- package/dist/Pagination.d.ts.map +1 -1
- package/dist/PaginationItem.d.ts +3 -0
- package/dist/PaginationItem.d.ts.map +1 -1
- package/dist/index.cjs.js +18 -18
- package/dist/index.d.ts +11 -0
- package/dist/index.esm.js +19 -19
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -17,41 +17,42 @@ npm install @rubenpazch/pagination
|
|
|
17
17
|
|
|
18
18
|
## Pagination
|
|
19
19
|
|
|
20
|
-
| Prop | Tipo | Req. | Por defecto
|
|
21
|
-
| -------------------- | -------------------------------------------------------------- | ---- |
|
|
22
|
-
| `aria-label` | `string` | |
|
|
23
|
-
| `boundaryCount` | `number` | | `1`
|
|
24
|
-
| `compactOnMobile` | `boolean` | | `false`
|
|
25
|
-
| `count` | `number` | | `1`
|
|
26
|
-
| `defaultPage` | `number` | | `1`
|
|
27
|
-
| `disabled` | `boolean` | | `false`
|
|
28
|
-
| `hideNextButton` | `boolean` | | `false`
|
|
29
|
-
| `hidePrevButton` | `boolean` | | `false`
|
|
30
|
-
| `hideWhenSinglePage` | `boolean` | | `false`
|
|
31
|
-
| `labels` | `Partial<PaginationLabels>` | |
|
|
32
|
-
| `onChange` | `(event: ChangeEvent<unknown, Element>, page: number) => void` | |
|
|
33
|
-
| `onPageChange` | `(page: number) => void` | |
|
|
34
|
-
| `page` | `number` | |
|
|
35
|
-
| `pageSize` | `number` | |
|
|
36
|
-
| `renderItem` | `(item: PaginationItemType) => ReactNode` | |
|
|
37
|
-
| `shape` | `"rounded" \| "circular"` | | `rounded`
|
|
38
|
-
| `showFirstButton` | `boolean` | | `false`
|
|
39
|
-
| `showLastButton` | `boolean` | | `false`
|
|
40
|
-
| `siblingCount` | `number` | | `1`
|
|
41
|
-
| `size` | `"small" \| "medium" \| "large" \| "sm" \| "md" \| "lg"` | | `medium`
|
|
42
|
-
| `totalCount` | `number` | |
|
|
43
|
-
| `variant` | `"text" \| "outlined"` | | `text`
|
|
20
|
+
| Prop | Tipo | Req. | Por defecto | Descripción |
|
|
21
|
+
| -------------------- | -------------------------------------------------------------- | ---- | ----------- | -------------------------------------------------------------------------------------------------------------------------------- |
|
|
22
|
+
| `aria-label` | `string` | | | Nombre accesible de la navegación (por defecto "Paginación"). |
|
|
23
|
+
| `boundaryCount` | `number` | | `1` | Number of always visible pages at the beginning and end |
|
|
24
|
+
| `compactOnMobile` | `boolean` | | `false` | En pantallas angostas (< 640 px) oculta los números y muestra solo anterior/siguiente con el indicador "3 / 10". |
|
|
25
|
+
| `count` | `number` | | `1` | Total number of pages |
|
|
26
|
+
| `defaultPage` | `number` | | `1` | Default page if uncontrolled |
|
|
27
|
+
| `disabled` | `boolean` | | `false` | If true, the component is disabled |
|
|
28
|
+
| `hideNextButton` | `boolean` | | `false` | If true, hide the next-page button |
|
|
29
|
+
| `hidePrevButton` | `boolean` | | `false` | If true, hide the previous-page button |
|
|
30
|
+
| `hideWhenSinglePage` | `boolean` | | `false` | No muestra nada cuando hay una sola página (o ninguna). |
|
|
31
|
+
| `labels` | `Partial<PaginationLabels>` | | | Textos de la interfaz; por defecto en español. |
|
|
32
|
+
| `onChange` | `(event: ChangeEvent<unknown, Element>, page: number) => void` | | | Al cambiar de página, estilo MUI: (evento, página). Se mantiene por compatibilidad. |
|
|
33
|
+
| `onPageChange` | `(page: number) => void` | | | Al cambiar de página (recibe solo el número). Preferido sobre onChange. |
|
|
34
|
+
| `page` | `number` | | | The current page (1-based) |
|
|
35
|
+
| `pageSize` | `number` | | | Registros por página, para calcular el rango del resumen. |
|
|
36
|
+
| `renderItem` | `(item: PaginationItemType) => ReactNode` | | | Custom render function for items |
|
|
37
|
+
| `shape` | `"rounded" \| "circular"` | | `rounded` | The shape of the pagination items |
|
|
38
|
+
| `showFirstButton` | `boolean` | | `false` | If true, show the first-page button |
|
|
39
|
+
| `showLastButton` | `boolean` | | `false` | If true, show the last-page button |
|
|
40
|
+
| `siblingCount` | `number` | | `1` | Number of always visible pages before and after the current page |
|
|
41
|
+
| `size` | `"small" \| "medium" \| "large" \| "sm" \| "md" \| "lg"` | | `medium` | The size of the pagination component |
|
|
42
|
+
| `totalCount` | `number` | | | Total de registros. Muestra un resumen junto a la paginación: "Mostrando 1–50 de 230" si se indica `pageSize`, o "230 en total". |
|
|
43
|
+
| `variant` | `"text" \| "outlined"` | | `text` | The variant to use |
|
|
44
44
|
|
|
45
45
|
## PaginationItem
|
|
46
46
|
|
|
47
|
-
| Prop | Tipo
|
|
48
|
-
| ---------- |
|
|
49
|
-
| `page` | `number`
|
|
50
|
-
| `type` | `"page" \| "next" \| "previous" \| "first" \| "last" \| "start-ellipsis" \| "end-ellipsis"`
|
|
51
|
-
| `
|
|
52
|
-
| `
|
|
53
|
-
| `
|
|
54
|
-
| `
|
|
47
|
+
| Prop | Tipo | Req. | Por defecto | Descripción |
|
|
48
|
+
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---- | ----------- | ----------------------------------------------------------------------------------------- |
|
|
49
|
+
| `page` | `number` | sí | | The page number |
|
|
50
|
+
| `type` | `"page" \| "next" \| "previous" \| "first" \| "last" \| "start-ellipsis" \| "end-ellipsis"` | sí | | The type of pagination item |
|
|
51
|
+
| `labels` | `Partial<{ label: string; first: string; last: string; next: string; previous: string; page: string; summaryRange: string; summaryTotal: string; mobilePage: string; }>` | | | Textos (por defecto, los del idioma activo): `first`, `last`, `next`, `previous`, `page`. |
|
|
52
|
+
| `selected` | `boolean` | | `false` | If true, the item is selected/active |
|
|
53
|
+
| `shape` | `"rounded" \| "circular"` | | `rounded` | The shape of the pagination items |
|
|
54
|
+
| `size` | `"small" \| "medium" \| "large" \| "sm" \| "md" \| "lg"` | | `medium` | The size of the component |
|
|
55
|
+
| `variant` | `"text" \| "outlined"` | | `text` | The variant to use |
|
|
55
56
|
|
|
56
57
|
Tipos: `PaginationProps`, `PaginationShape`, `PaginationSize`, `PaginationVariant`, `PaginationItemType`, `PaginationLabels`, `PaginationItemProps`.
|
|
57
58
|
|
package/dist/Pagination.d.ts
CHANGED
|
@@ -4,6 +4,14 @@ export type PaginationShape = "rounded" | "circular";
|
|
|
4
4
|
export type PaginationSize = "small" | "medium" | "large" | "sm" | "md" | "lg";
|
|
5
5
|
export type PaginationVariant = "text" | "outlined";
|
|
6
6
|
export interface PaginationLabels {
|
|
7
|
+
/** Nombre del `<nav>` (si no se pasa `aria-label`). */
|
|
8
|
+
label: string;
|
|
9
|
+
/** Botones (lectores de pantalla); `page` lleva `{page}`. */
|
|
10
|
+
first: string;
|
|
11
|
+
last: string;
|
|
12
|
+
next: string;
|
|
13
|
+
previous: string;
|
|
14
|
+
page: string;
|
|
7
15
|
/** Con `pageSize`: `{from}`, `{to}` y `{total}`. */
|
|
8
16
|
summaryRange: string;
|
|
9
17
|
/** Sin `pageSize`: `{total}`. */
|
|
@@ -11,6 +19,7 @@ export interface PaginationLabels {
|
|
|
11
19
|
/** Indicador del celular con `compactOnMobile`: `{page}` y `{count}`. */
|
|
12
20
|
mobilePage: string;
|
|
13
21
|
}
|
|
22
|
+
/** Textos en castellano (los del diccionario `es`). Con `UiLocaleProvider` cambian solos. */
|
|
14
23
|
export declare const DEFAULT_PAGINATION_LABELS: PaginationLabels;
|
|
15
24
|
export interface PaginationProps extends Omit<React.HTMLAttributes<HTMLElement>, "onChange"> {
|
|
16
25
|
/** Total number of pages */
|
package/dist/Pagination.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Pagination.d.ts","sourceRoot":"","sources":["../src/Pagination.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Pagination.d.ts","sourceRoot":"","sources":["../src/Pagination.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CA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|
package/dist/PaginationItem.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import { type UiMessages } from "@rubenpazch/shared";
|
|
2
3
|
import type { PaginationShape, PaginationSize, PaginationVariant } from "./Pagination";
|
|
3
4
|
export interface PaginationItemProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "type"> {
|
|
4
5
|
/** The page number */
|
|
@@ -13,6 +14,8 @@ export interface PaginationItemProps extends Omit<React.ButtonHTMLAttributes<HTM
|
|
|
13
14
|
size?: PaginationSize;
|
|
14
15
|
/** The variant to use */
|
|
15
16
|
variant?: PaginationVariant;
|
|
17
|
+
/** Textos (por defecto, los del idioma activo): `first`, `last`, `next`, `previous`, `page`. */
|
|
18
|
+
labels?: Partial<UiMessages["pagination"]>;
|
|
16
19
|
}
|
|
17
20
|
declare const PaginationItem: React.ForwardRefExoticComponent<PaginationItemProps & React.RefAttributes<HTMLButtonElement>>;
|
|
18
21
|
export default PaginationItem;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PaginationItem.d.ts","sourceRoot":"","sources":["../src/PaginationItem.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"PaginationItem.d.ts","sourceRoot":"","sources":["../src/PaginationItem.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAIL,KAAK,UAAU,EAChB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,iBAAiB,EAClB,MAAM,cAAc,CAAC;AAEtB,MAAM,WAAW,mBAAoB,SAAQ,IAAI,CAC/C,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EAC7C,MAAM,CACP;IACC,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,IAAI,EACA,MAAM,GACN,OAAO,GACP,MAAM,GACN,MAAM,GACN,UAAU,GACV,gBAAgB,GAChB,cAAc,CAAC;IACnB,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,wCAAwC;IACxC,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,gCAAgC;IAChC,IAAI,CAAC,EAAE,cAAc,CAAC;IACtB,yBAAyB;IACzB,OAAO,CAAC,EAAE,iBAAiB,CAAC;IAC5B,gGAAgG;IAChG,MAAM,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC;CAC5C;AAWD,QAAA,MAAM,cAAc,+FA0InB,CAAC;AAIF,eAAe,cAAc,CAAC"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -496,7 +496,8 @@ const iconSizeMap = {
|
|
|
496
496
|
medium: "md",
|
|
497
497
|
large: "lg",
|
|
498
498
|
};
|
|
499
|
-
const PaginationItem = React.forwardRef(({ page, type, selected = false, disabled = false, shape = "rounded", size: sizeProp = "medium", variant = "text", className, ...props }, ref) => {
|
|
499
|
+
const PaginationItem = React.forwardRef(({ page, type, selected = false, disabled = false, shape = "rounded", size: sizeProp = "medium", variant = "text", className, labels, ...props }, ref) => {
|
|
500
|
+
const t = shared.useUiMessages("pagination", labels);
|
|
500
501
|
const size = shared.toLegacySize(sizeProp);
|
|
501
502
|
// Ellipsis are not interactive
|
|
502
503
|
if (type === "start-ellipsis" || type === "end-ellipsis") {
|
|
@@ -536,14 +537,14 @@ const PaginationItem = React.forwardRef(({ page, type, selected = false, disable
|
|
|
536
537
|
};
|
|
537
538
|
const classes = classNames$1(styles$1.item, styles$1.button, styles$1[`size-${size}`], styles$1[`shape-${shape}`], styles$1[`variant-${variant}`], selected && styles$1.selected, disabled && styles$1.disabled, isNavigationButton && styles$1.navigation, className);
|
|
538
539
|
return (jsxRuntimeExports.jsx("button", { ref: ref, type: "button", className: classes, disabled: disabled, "aria-label": type === "first"
|
|
539
|
-
?
|
|
540
|
+
? t.first
|
|
540
541
|
: type === "last"
|
|
541
|
-
?
|
|
542
|
+
? t.last
|
|
542
543
|
: type === "next"
|
|
543
|
-
?
|
|
544
|
+
? t.next
|
|
544
545
|
: type === "previous"
|
|
545
|
-
?
|
|
546
|
-
:
|
|
546
|
+
? t.previous
|
|
547
|
+
: shared.formatMessage(t.page, { page }), "aria-current": selected ? "page" : undefined, ...props, children: getButtonContent() }));
|
|
547
548
|
});
|
|
548
549
|
PaginationItem.displayName = "PaginationItem";
|
|
549
550
|
|
|
@@ -551,11 +552,8 @@ var css_248z = "/* Pagination root */\n.Pagination-module_root__aWgof {\n displ
|
|
|
551
552
|
var styles = {"root":"Pagination-module_root__aWgof","ul":"Pagination-module_ul__MfLr5","summary":"Pagination-module_summary__BlA-j","mobilePage":"Pagination-module_mobilePage__GRZee","compactOnMobile":"Pagination-module_compactOnMobile__jNDTZ","numbered":"Pagination-module_numbered__5gmrn"};
|
|
552
553
|
styleInject(css_248z);
|
|
553
554
|
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
summaryTotal: "{total} en total",
|
|
557
|
-
mobilePage: "{page} / {count}",
|
|
558
|
-
};
|
|
555
|
+
/** Textos en castellano (los del diccionario `es`). Con `UiLocaleProvider` cambian solos. */
|
|
556
|
+
shared.uiMessagesEs.pagination;
|
|
559
557
|
const interpolate = (template, values) => template.replace(/\{(\w+)\}/g, (_, key) => String(values[key] ?? ""));
|
|
560
558
|
const classNames = (...classes) => classes.filter(Boolean).join(" ");
|
|
561
559
|
// Utility to generate pagination items
|
|
@@ -632,7 +630,7 @@ const usePagination = (props) => {
|
|
|
632
630
|
}
|
|
633
631
|
return items;
|
|
634
632
|
};
|
|
635
|
-
const Pagination = React.forwardRef(({ count = 1, page: controlledPage, defaultPage = 1, onChange, onPageChange, "aria-label":
|
|
633
|
+
const Pagination = React.forwardRef(({ count = 1, page: controlledPage, defaultPage = 1, onChange, onPageChange, "aria-label": ariaLabelProp, disabled = false, hideNextButton = false, hidePrevButton = false, showFirstButton = false, showLastButton = false, boundaryCount = 1, siblingCount = 1, shape = "rounded", size: sizeProp = "medium", variant = "text", renderItem, className, totalCount, pageSize, compactOnMobile = false, hideWhenSinglePage = false, labels: labelsProp, ...props }, ref) => {
|
|
636
634
|
const size = shared.toLegacySize(sizeProp);
|
|
637
635
|
const [page, setPage] = React.useState(defaultPage);
|
|
638
636
|
const currentPage = controlledPage ?? page;
|
|
@@ -655,7 +653,9 @@ const Pagination = React.forwardRef(({ count = 1, page: controlledPage, defaultP
|
|
|
655
653
|
hideNextButton,
|
|
656
654
|
hidePrevButton,
|
|
657
655
|
});
|
|
658
|
-
const labels =
|
|
656
|
+
const labels = shared.useUiMessages("pagination", labelsProp);
|
|
657
|
+
const { intlLocale } = shared.useUiLocale();
|
|
658
|
+
const ariaLabel = ariaLabelProp ?? labels.label;
|
|
659
659
|
const classes = classNames(styles.root, compactOnMobile ? styles.compactOnMobile : undefined, className);
|
|
660
660
|
if (hideWhenSinglePage && count <= 1)
|
|
661
661
|
return null;
|
|
@@ -665,14 +665,14 @@ const Pagination = React.forwardRef(({ count = 1, page: controlledPage, defaultP
|
|
|
665
665
|
const from = totalCount === 0 ? 0 : (currentPage - 1) * pageSize + 1;
|
|
666
666
|
const to = Math.min(currentPage * pageSize, totalCount);
|
|
667
667
|
summary = interpolate(labels.summaryRange, {
|
|
668
|
-
from: from.toLocaleString(
|
|
669
|
-
to: to.toLocaleString(
|
|
670
|
-
total: totalCount.toLocaleString(
|
|
668
|
+
from: from.toLocaleString(intlLocale),
|
|
669
|
+
to: to.toLocaleString(intlLocale),
|
|
670
|
+
total: totalCount.toLocaleString(intlLocale),
|
|
671
671
|
});
|
|
672
672
|
}
|
|
673
673
|
else {
|
|
674
674
|
summary = interpolate(labels.summaryTotal, {
|
|
675
|
-
total: totalCount.toLocaleString(
|
|
675
|
+
total: totalCount.toLocaleString(intlLocale),
|
|
676
676
|
});
|
|
677
677
|
}
|
|
678
678
|
}
|
|
@@ -707,7 +707,7 @@ const Pagination = React.forwardRef(({ count = 1, page: controlledPage, defaultP
|
|
|
707
707
|
},
|
|
708
708
|
}) }), after] }, index));
|
|
709
709
|
}
|
|
710
|
-
return (jsxRuntimeExports.jsxs(React.Fragment, { children: [jsxRuntimeExports.jsx("li", { className: itemClass, children: jsxRuntimeExports.jsx(PaginationItem, { ...item, disabled: isDisabled, shape: shape, size: size, variant: variant, onClick: (e) => {
|
|
710
|
+
return (jsxRuntimeExports.jsxs(React.Fragment, { children: [jsxRuntimeExports.jsx("li", { className: itemClass, children: jsxRuntimeExports.jsx(PaginationItem, { ...item, labels: labelsProp, disabled: isDisabled, shape: shape, size: size, variant: variant, onClick: (e) => {
|
|
711
711
|
if (!isDisabled && item.type === "page") {
|
|
712
712
|
handleClick(e, item.page);
|
|
713
713
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { UiMessages } from '@rubenpazch/shared';
|
|
2
3
|
|
|
3
4
|
type PaginationShape = "rounded" | "circular";
|
|
4
5
|
/** Tamaño: sm, md, lg (estándar) o small, medium, large. */
|
|
5
6
|
type PaginationSize = "small" | "medium" | "large" | "sm" | "md" | "lg";
|
|
6
7
|
type PaginationVariant = "text" | "outlined";
|
|
7
8
|
interface PaginationLabels {
|
|
9
|
+
/** Nombre del `<nav>` (si no se pasa `aria-label`). */
|
|
10
|
+
label: string;
|
|
11
|
+
/** Botones (lectores de pantalla); `page` lleva `{page}`. */
|
|
12
|
+
first: string;
|
|
13
|
+
last: string;
|
|
14
|
+
next: string;
|
|
15
|
+
previous: string;
|
|
16
|
+
page: string;
|
|
8
17
|
/** Con `pageSize`: `{from}`, `{to}` y `{total}`. */
|
|
9
18
|
summaryRange: string;
|
|
10
19
|
/** Sin `pageSize`: `{total}`. */
|
|
@@ -86,6 +95,8 @@ interface PaginationItemProps extends Omit<React.ButtonHTMLAttributes<HTMLButton
|
|
|
86
95
|
size?: PaginationSize;
|
|
87
96
|
/** The variant to use */
|
|
88
97
|
variant?: PaginationVariant;
|
|
98
|
+
/** Textos (por defecto, los del idioma activo): `first`, `last`, `next`, `previous`, `page`. */
|
|
99
|
+
labels?: Partial<UiMessages["pagination"]>;
|
|
89
100
|
}
|
|
90
101
|
declare const PaginationItem: React.ForwardRefExoticComponent<PaginationItemProps & React.RefAttributes<HTMLButtonElement>>;
|
|
91
102
|
|
package/dist/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { toLegacySize } from '@rubenpazch/shared';
|
|
2
|
+
import { useUiMessages, toLegacySize, formatMessage, uiMessagesEs, useUiLocale } from '@rubenpazch/shared';
|
|
3
3
|
|
|
4
4
|
var jsxRuntime = {exports: {}};
|
|
5
5
|
|
|
@@ -494,7 +494,8 @@ const iconSizeMap = {
|
|
|
494
494
|
medium: "md",
|
|
495
495
|
large: "lg",
|
|
496
496
|
};
|
|
497
|
-
const PaginationItem = React.forwardRef(({ page, type, selected = false, disabled = false, shape = "rounded", size: sizeProp = "medium", variant = "text", className, ...props }, ref) => {
|
|
497
|
+
const PaginationItem = React.forwardRef(({ page, type, selected = false, disabled = false, shape = "rounded", size: sizeProp = "medium", variant = "text", className, labels, ...props }, ref) => {
|
|
498
|
+
const t = useUiMessages("pagination", labels);
|
|
498
499
|
const size = toLegacySize(sizeProp);
|
|
499
500
|
// Ellipsis are not interactive
|
|
500
501
|
if (type === "start-ellipsis" || type === "end-ellipsis") {
|
|
@@ -534,14 +535,14 @@ const PaginationItem = React.forwardRef(({ page, type, selected = false, disable
|
|
|
534
535
|
};
|
|
535
536
|
const classes = classNames$1(styles$1.item, styles$1.button, styles$1[`size-${size}`], styles$1[`shape-${shape}`], styles$1[`variant-${variant}`], selected && styles$1.selected, disabled && styles$1.disabled, isNavigationButton && styles$1.navigation, className);
|
|
536
537
|
return (jsxRuntimeExports.jsx("button", { ref: ref, type: "button", className: classes, disabled: disabled, "aria-label": type === "first"
|
|
537
|
-
?
|
|
538
|
+
? t.first
|
|
538
539
|
: type === "last"
|
|
539
|
-
?
|
|
540
|
+
? t.last
|
|
540
541
|
: type === "next"
|
|
541
|
-
?
|
|
542
|
+
? t.next
|
|
542
543
|
: type === "previous"
|
|
543
|
-
?
|
|
544
|
-
:
|
|
544
|
+
? t.previous
|
|
545
|
+
: formatMessage(t.page, { page }), "aria-current": selected ? "page" : undefined, ...props, children: getButtonContent() }));
|
|
545
546
|
});
|
|
546
547
|
PaginationItem.displayName = "PaginationItem";
|
|
547
548
|
|
|
@@ -549,11 +550,8 @@ var css_248z = "/* Pagination root */\n.Pagination-module_root__aWgof {\n displ
|
|
|
549
550
|
var styles = {"root":"Pagination-module_root__aWgof","ul":"Pagination-module_ul__MfLr5","summary":"Pagination-module_summary__BlA-j","mobilePage":"Pagination-module_mobilePage__GRZee","compactOnMobile":"Pagination-module_compactOnMobile__jNDTZ","numbered":"Pagination-module_numbered__5gmrn"};
|
|
550
551
|
styleInject(css_248z);
|
|
551
552
|
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
summaryTotal: "{total} en total",
|
|
555
|
-
mobilePage: "{page} / {count}",
|
|
556
|
-
};
|
|
553
|
+
/** Textos en castellano (los del diccionario `es`). Con `UiLocaleProvider` cambian solos. */
|
|
554
|
+
uiMessagesEs.pagination;
|
|
557
555
|
const interpolate = (template, values) => template.replace(/\{(\w+)\}/g, (_, key) => String(values[key] ?? ""));
|
|
558
556
|
const classNames = (...classes) => classes.filter(Boolean).join(" ");
|
|
559
557
|
// Utility to generate pagination items
|
|
@@ -630,7 +628,7 @@ const usePagination = (props) => {
|
|
|
630
628
|
}
|
|
631
629
|
return items;
|
|
632
630
|
};
|
|
633
|
-
const Pagination = React.forwardRef(({ count = 1, page: controlledPage, defaultPage = 1, onChange, onPageChange, "aria-label":
|
|
631
|
+
const Pagination = React.forwardRef(({ count = 1, page: controlledPage, defaultPage = 1, onChange, onPageChange, "aria-label": ariaLabelProp, disabled = false, hideNextButton = false, hidePrevButton = false, showFirstButton = false, showLastButton = false, boundaryCount = 1, siblingCount = 1, shape = "rounded", size: sizeProp = "medium", variant = "text", renderItem, className, totalCount, pageSize, compactOnMobile = false, hideWhenSinglePage = false, labels: labelsProp, ...props }, ref) => {
|
|
634
632
|
const size = toLegacySize(sizeProp);
|
|
635
633
|
const [page, setPage] = React.useState(defaultPage);
|
|
636
634
|
const currentPage = controlledPage ?? page;
|
|
@@ -653,7 +651,9 @@ const Pagination = React.forwardRef(({ count = 1, page: controlledPage, defaultP
|
|
|
653
651
|
hideNextButton,
|
|
654
652
|
hidePrevButton,
|
|
655
653
|
});
|
|
656
|
-
const labels =
|
|
654
|
+
const labels = useUiMessages("pagination", labelsProp);
|
|
655
|
+
const { intlLocale } = useUiLocale();
|
|
656
|
+
const ariaLabel = ariaLabelProp ?? labels.label;
|
|
657
657
|
const classes = classNames(styles.root, compactOnMobile ? styles.compactOnMobile : undefined, className);
|
|
658
658
|
if (hideWhenSinglePage && count <= 1)
|
|
659
659
|
return null;
|
|
@@ -663,14 +663,14 @@ const Pagination = React.forwardRef(({ count = 1, page: controlledPage, defaultP
|
|
|
663
663
|
const from = totalCount === 0 ? 0 : (currentPage - 1) * pageSize + 1;
|
|
664
664
|
const to = Math.min(currentPage * pageSize, totalCount);
|
|
665
665
|
summary = interpolate(labels.summaryRange, {
|
|
666
|
-
from: from.toLocaleString(
|
|
667
|
-
to: to.toLocaleString(
|
|
668
|
-
total: totalCount.toLocaleString(
|
|
666
|
+
from: from.toLocaleString(intlLocale),
|
|
667
|
+
to: to.toLocaleString(intlLocale),
|
|
668
|
+
total: totalCount.toLocaleString(intlLocale),
|
|
669
669
|
});
|
|
670
670
|
}
|
|
671
671
|
else {
|
|
672
672
|
summary = interpolate(labels.summaryTotal, {
|
|
673
|
-
total: totalCount.toLocaleString(
|
|
673
|
+
total: totalCount.toLocaleString(intlLocale),
|
|
674
674
|
});
|
|
675
675
|
}
|
|
676
676
|
}
|
|
@@ -705,7 +705,7 @@ const Pagination = React.forwardRef(({ count = 1, page: controlledPage, defaultP
|
|
|
705
705
|
},
|
|
706
706
|
}) }), after] }, index));
|
|
707
707
|
}
|
|
708
|
-
return (jsxRuntimeExports.jsxs(React.Fragment, { children: [jsxRuntimeExports.jsx("li", { className: itemClass, children: jsxRuntimeExports.jsx(PaginationItem, { ...item, disabled: isDisabled, shape: shape, size: size, variant: variant, onClick: (e) => {
|
|
708
|
+
return (jsxRuntimeExports.jsxs(React.Fragment, { children: [jsxRuntimeExports.jsx("li", { className: itemClass, children: jsxRuntimeExports.jsx(PaginationItem, { ...item, labels: labelsProp, disabled: isDisabled, shape: shape, size: size, variant: variant, onClick: (e) => {
|
|
709
709
|
if (!isDisabled && item.type === "page") {
|
|
710
710
|
handleClick(e, item.page);
|
|
711
711
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rubenpazch/pagination",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "Pagination component",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "dist/index.cjs.js",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"**/*.css"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@rubenpazch/icons": "6.6.
|
|
24
|
-
"@rubenpazch/shared": "5.
|
|
23
|
+
"@rubenpazch/icons": "6.6.1",
|
|
24
|
+
"@rubenpazch/shared": "5.4.0"
|
|
25
25
|
},
|
|
26
26
|
"exports": {
|
|
27
27
|
".": {
|