@rubenpazch/pagination 3.2.5 → 3.3.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 +25 -20
- package/dist/Pagination.d.ts +25 -0
- package/dist/Pagination.d.ts.map +1 -1
- package/dist/index.cjs.js +79 -47
- package/dist/index.d.ts +25 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +79 -47
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -17,25 +17,30 @@ npm install @rubenpazch/pagination
|
|
|
17
17
|
|
|
18
18
|
## Pagination
|
|
19
19
|
|
|
20
|
-
| Prop
|
|
21
|
-
|
|
|
22
|
-
| `aria-label`
|
|
23
|
-
| `boundaryCount`
|
|
24
|
-
| `
|
|
25
|
-
| `
|
|
26
|
-
| `
|
|
27
|
-
| `
|
|
28
|
-
| `
|
|
29
|
-
| `
|
|
30
|
-
| `
|
|
31
|
-
| `
|
|
32
|
-
| `
|
|
33
|
-
| `
|
|
34
|
-
| `
|
|
35
|
-
| `
|
|
36
|
-
| `
|
|
37
|
-
| `
|
|
38
|
-
| `
|
|
20
|
+
| Prop | Tipo | Req. | Por defecto | Descripción |
|
|
21
|
+
| -------------------- | -------------------------------------------------------------- | ---- | ------------ | -------------------------------------------------------------------------------------------------------------------------------- |
|
|
22
|
+
| `aria-label` | `string` | | `Paginación` | 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 |
|
|
39
44
|
|
|
40
45
|
## PaginationItem
|
|
41
46
|
|
|
@@ -48,6 +53,6 @@ npm install @rubenpazch/pagination
|
|
|
48
53
|
| `size` | `"small" \| "medium" \| "large" \| "sm" \| "md" \| "lg"` | | `medium` | The size of the component |
|
|
49
54
|
| `variant` | `"text" \| "outlined"` | | `text` | The variant to use |
|
|
50
55
|
|
|
51
|
-
Tipos: `PaginationProps`, `PaginationShape`, `PaginationSize`, `PaginationVariant`, `PaginationItemType`, `PaginationItemProps`.
|
|
56
|
+
Tipos: `PaginationProps`, `PaginationShape`, `PaginationSize`, `PaginationVariant`, `PaginationItemType`, `PaginationLabels`, `PaginationItemProps`.
|
|
52
57
|
|
|
53
58
|
<!-- catalogo:fin -->
|
package/dist/Pagination.d.ts
CHANGED
|
@@ -3,6 +3,15 @@ export type PaginationShape = "rounded" | "circular";
|
|
|
3
3
|
/** Tamaño: sm, md, lg (estándar) o small, medium, large. */
|
|
4
4
|
export type PaginationSize = "small" | "medium" | "large" | "sm" | "md" | "lg";
|
|
5
5
|
export type PaginationVariant = "text" | "outlined";
|
|
6
|
+
export interface PaginationLabels {
|
|
7
|
+
/** Con `pageSize`: `{from}`, `{to}` y `{total}`. */
|
|
8
|
+
summaryRange: string;
|
|
9
|
+
/** Sin `pageSize`: `{total}`. */
|
|
10
|
+
summaryTotal: string;
|
|
11
|
+
/** Indicador del celular con `compactOnMobile`: `{page}` y `{count}`. */
|
|
12
|
+
mobilePage: string;
|
|
13
|
+
}
|
|
14
|
+
export declare const DEFAULT_PAGINATION_LABELS: PaginationLabels;
|
|
6
15
|
export interface PaginationProps extends Omit<React.HTMLAttributes<HTMLElement>, "onChange"> {
|
|
7
16
|
/** Total number of pages */
|
|
8
17
|
count?: number;
|
|
@@ -38,6 +47,22 @@ export interface PaginationProps extends Omit<React.HTMLAttributes<HTMLElement>,
|
|
|
38
47
|
variant?: PaginationVariant;
|
|
39
48
|
/** Custom render function for items */
|
|
40
49
|
renderItem?: (item: PaginationItemType) => React.ReactNode;
|
|
50
|
+
/**
|
|
51
|
+
* Total de registros. Muestra un resumen junto a la paginación:
|
|
52
|
+
* "Mostrando 1–50 de 230" si se indica `pageSize`, o "230 en total".
|
|
53
|
+
*/
|
|
54
|
+
totalCount?: number;
|
|
55
|
+
/** Registros por página, para calcular el rango del resumen. */
|
|
56
|
+
pageSize?: number;
|
|
57
|
+
/**
|
|
58
|
+
* En pantallas angostas (< 640 px) oculta los números y muestra solo
|
|
59
|
+
* anterior/siguiente con el indicador "3 / 10".
|
|
60
|
+
*/
|
|
61
|
+
compactOnMobile?: boolean;
|
|
62
|
+
/** No muestra nada cuando hay una sola página (o ninguna). */
|
|
63
|
+
hideWhenSinglePage?: boolean;
|
|
64
|
+
/** Textos de la interfaz; por defecto en español. */
|
|
65
|
+
labels?: Partial<PaginationLabels>;
|
|
41
66
|
}
|
|
42
67
|
export interface PaginationItemType {
|
|
43
68
|
page: number;
|
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;AAK1B,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,UAAU,CAAC;AACrD,4DAA4D;AAC5D,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAC/E,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,UAAU,CAAC;AAEpD,MAAM,WAAW,eAAgB,SAAQ,IAAI,CAC3C,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,EACjC,UAAU,CACX;IACC,4BAA4B;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iCAAiC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mCAAmC;IACnC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,8EAA8E;IAC9E,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,0FAA0F;IAC1F,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACrE,oEAAoE;IACpE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yCAAyC;IACzC,QAAQ,CAAC,E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OAAO,CAAC;IAC7B,qDAAqD;IACrD,MAAM,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EACA,MAAM,GACN,OAAO,GACP,MAAM,GACN,MAAM,GACN,UAAU,GACV,gBAAgB,GAChB,cAAc,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAC;CAC/D;AAgID,QAAA,MAAM,UAAU,qFAuKf,CAAC;AAIF,eAAe,UAAU,CAAC"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -547,10 +547,16 @@ const PaginationItem = React.forwardRef(({ page, type, selected = false, disable
|
|
|
547
547
|
});
|
|
548
548
|
PaginationItem.displayName = "PaginationItem";
|
|
549
549
|
|
|
550
|
-
var css_248z = "/* Pagination root */\n.Pagination-module_root__aWgof {\n display: flex;\n justify-content: center;\n align-items: center;\n}\n\n.Pagination-module_ul__MfLr5 {\n display: flex;\n flex-direction: row;\n align-items: center;\n padding: 0;\n margin: 0;\n list-style: none;\n gap: 4px;\n}\n";
|
|
551
|
-
var styles = {"root":"Pagination-module_root__aWgof","ul":"Pagination-module_ul__MfLr5"};
|
|
550
|
+
var css_248z = "/* Pagination root */\n.Pagination-module_root__aWgof {\n display: flex;\n justify-content: center;\n align-items: center;\n}\n\n.Pagination-module_ul__MfLr5 {\n display: flex;\n flex-direction: row;\n align-items: center;\n padding: 0;\n margin: 0;\n list-style: none;\n gap: 4px;\n}\n\n.Pagination-module_root__aWgof {\n flex-wrap: wrap;\n gap: var(--lb-space-3);\n}\n\n/* Resumen \"Mostrando 1–50 de 230\" */\n.Pagination-module_summary__BlA-j {\n margin: 0;\n font-size: var(--lb-font-size-sm);\n color: var(--lb-color-muted-foreground);\n}\n\n/* Indicador \"3 / 10\": solo en el celular con compactOnMobile */\n.Pagination-module_mobilePage__GRZee {\n display: none;\n padding: 0 var(--lb-space-3);\n font-size: var(--lb-font-size-sm);\n font-weight: var(--lb-font-weight-medium);\n color: var(--lb-color-foreground);\n}\n\n@media (max-width: 639px) {\n .Pagination-module_compactOnMobile__jNDTZ .Pagination-module_numbered__5gmrn {\n display: none;\n }\n\n .Pagination-module_compactOnMobile__jNDTZ .Pagination-module_mobilePage__GRZee {\n display: list-item;\n list-style: none;\n }\n}\n";
|
|
551
|
+
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
552
|
styleInject(css_248z);
|
|
553
553
|
|
|
554
|
+
const DEFAULT_PAGINATION_LABELS = {
|
|
555
|
+
summaryRange: "Mostrando {from}–{to} de {total}",
|
|
556
|
+
summaryTotal: "{total} en total",
|
|
557
|
+
mobilePage: "{page} / {count}",
|
|
558
|
+
};
|
|
559
|
+
const interpolate = (template, values) => template.replace(/\{(\w+)\}/g, (_, key) => String(values[key] ?? ""));
|
|
554
560
|
const classNames = (...classes) => classes.filter(Boolean).join(" ");
|
|
555
561
|
// Utility to generate pagination items
|
|
556
562
|
const usePagination = (props) => {
|
|
@@ -626,7 +632,7 @@ const usePagination = (props) => {
|
|
|
626
632
|
}
|
|
627
633
|
return items;
|
|
628
634
|
};
|
|
629
|
-
const Pagination = React.forwardRef(({ count = 1, page: controlledPage, defaultPage = 1, onChange, onPageChange, "aria-label": ariaLabel = "Paginación", disabled = false, hideNextButton = false, hidePrevButton = false, showFirstButton = false, showLastButton = false, boundaryCount = 1, siblingCount = 1, shape = "rounded", size: sizeProp = "medium", variant = "text", renderItem, className, ...props }, ref) => {
|
|
635
|
+
const Pagination = React.forwardRef(({ count = 1, page: controlledPage, defaultPage = 1, onChange, onPageChange, "aria-label": ariaLabel = "Paginación", 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) => {
|
|
630
636
|
const size = shared.toLegacySize(sizeProp);
|
|
631
637
|
const [page, setPage] = React.useState(defaultPage);
|
|
632
638
|
const currentPage = controlledPage ?? page;
|
|
@@ -649,50 +655,76 @@ const Pagination = React.forwardRef(({ count = 1, page: controlledPage, defaultP
|
|
|
649
655
|
hideNextButton,
|
|
650
656
|
hidePrevButton,
|
|
651
657
|
});
|
|
652
|
-
const
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
658
|
+
const labels = { ...DEFAULT_PAGINATION_LABELS, ...labelsProp };
|
|
659
|
+
const classes = classNames(styles.root, compactOnMobile ? styles.compactOnMobile : undefined, className);
|
|
660
|
+
if (hideWhenSinglePage && count <= 1)
|
|
661
|
+
return null;
|
|
662
|
+
let summary;
|
|
663
|
+
if (totalCount !== undefined) {
|
|
664
|
+
if (pageSize && pageSize > 0) {
|
|
665
|
+
const from = totalCount === 0 ? 0 : (currentPage - 1) * pageSize + 1;
|
|
666
|
+
const to = Math.min(currentPage * pageSize, totalCount);
|
|
667
|
+
summary = interpolate(labels.summaryRange, {
|
|
668
|
+
from: from.toLocaleString("es-PE"),
|
|
669
|
+
to: to.toLocaleString("es-PE"),
|
|
670
|
+
total: totalCount.toLocaleString("es-PE"),
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
else {
|
|
674
|
+
summary = interpolate(labels.summaryTotal, {
|
|
675
|
+
total: totalCount.toLocaleString("es-PE"),
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
const isNumbered = (type) => type === "page" || type === "start-ellipsis" || type === "end-ellipsis";
|
|
680
|
+
const mobileIndicator = compactOnMobile ? (jsxRuntimeExports.jsx("li", { className: styles.mobilePage, "aria-hidden": "true", children: interpolate(labels.mobilePage, { page: currentPage, count }) })) : null;
|
|
681
|
+
return (jsxRuntimeExports.jsxs("nav", { ref: ref, className: classes, "aria-label": ariaLabel, ...props, children: [summary && (jsxRuntimeExports.jsx("p", { className: styles.summary, "aria-live": "polite", children: summary })), jsxRuntimeExports.jsx("ul", { className: styles.ul, children: items.map((item, index) => {
|
|
682
|
+
const isDisabled = disabled || item.disabled;
|
|
683
|
+
const itemClass = isNumbered(item.type)
|
|
684
|
+
? styles.numbered
|
|
685
|
+
: undefined;
|
|
686
|
+
const after = item.type === "previous" ? mobileIndicator : null;
|
|
687
|
+
if (renderItem) {
|
|
688
|
+
return (jsxRuntimeExports.jsxs(React.Fragment, { children: [jsxRuntimeExports.jsx("li", { className: itemClass, children: renderItem({
|
|
689
|
+
...item,
|
|
690
|
+
disabled: isDisabled,
|
|
691
|
+
onClick: (e) => {
|
|
692
|
+
if (!isDisabled && item.type === "page") {
|
|
693
|
+
handleClick(e, item.page);
|
|
694
|
+
}
|
|
695
|
+
else if (!isDisabled && item.type === "next") {
|
|
696
|
+
handleClick(e, Math.min(count, currentPage + 1));
|
|
697
|
+
}
|
|
698
|
+
else if (!isDisabled && item.type === "previous") {
|
|
699
|
+
handleClick(e, Math.max(1, currentPage - 1));
|
|
700
|
+
}
|
|
701
|
+
else if (!isDisabled && item.type === "first") {
|
|
702
|
+
handleClick(e, 1);
|
|
703
|
+
}
|
|
704
|
+
else if (!isDisabled && item.type === "last") {
|
|
705
|
+
handleClick(e, count);
|
|
706
|
+
}
|
|
707
|
+
},
|
|
708
|
+
}) }), after] }, index));
|
|
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) => {
|
|
711
|
+
if (!isDisabled && item.type === "page") {
|
|
712
|
+
handleClick(e, item.page);
|
|
713
|
+
}
|
|
714
|
+
else if (!isDisabled && item.type === "next") {
|
|
715
|
+
handleClick(e, Math.min(count, currentPage + 1));
|
|
716
|
+
}
|
|
717
|
+
else if (!isDisabled && item.type === "previous") {
|
|
718
|
+
handleClick(e, Math.max(1, currentPage - 1));
|
|
719
|
+
}
|
|
720
|
+
else if (!isDisabled && item.type === "first") {
|
|
721
|
+
handleClick(e, 1);
|
|
722
|
+
}
|
|
723
|
+
else if (!isDisabled && item.type === "last") {
|
|
724
|
+
handleClick(e, count);
|
|
725
|
+
}
|
|
726
|
+
} }) }), after] }, index));
|
|
727
|
+
}) })] }));
|
|
696
728
|
});
|
|
697
729
|
Pagination.displayName = "Pagination";
|
|
698
730
|
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,14 @@ type PaginationShape = "rounded" | "circular";
|
|
|
4
4
|
/** Tamaño: sm, md, lg (estándar) o small, medium, large. */
|
|
5
5
|
type PaginationSize = "small" | "medium" | "large" | "sm" | "md" | "lg";
|
|
6
6
|
type PaginationVariant = "text" | "outlined";
|
|
7
|
+
interface PaginationLabels {
|
|
8
|
+
/** Con `pageSize`: `{from}`, `{to}` y `{total}`. */
|
|
9
|
+
summaryRange: string;
|
|
10
|
+
/** Sin `pageSize`: `{total}`. */
|
|
11
|
+
summaryTotal: string;
|
|
12
|
+
/** Indicador del celular con `compactOnMobile`: `{page}` y `{count}`. */
|
|
13
|
+
mobilePage: string;
|
|
14
|
+
}
|
|
7
15
|
interface PaginationProps extends Omit<React.HTMLAttributes<HTMLElement>, "onChange"> {
|
|
8
16
|
/** Total number of pages */
|
|
9
17
|
count?: number;
|
|
@@ -39,6 +47,22 @@ interface PaginationProps extends Omit<React.HTMLAttributes<HTMLElement>, "onCha
|
|
|
39
47
|
variant?: PaginationVariant;
|
|
40
48
|
/** Custom render function for items */
|
|
41
49
|
renderItem?: (item: PaginationItemType) => React.ReactNode;
|
|
50
|
+
/**
|
|
51
|
+
* Total de registros. Muestra un resumen junto a la paginación:
|
|
52
|
+
* "Mostrando 1–50 de 230" si se indica `pageSize`, o "230 en total".
|
|
53
|
+
*/
|
|
54
|
+
totalCount?: number;
|
|
55
|
+
/** Registros por página, para calcular el rango del resumen. */
|
|
56
|
+
pageSize?: number;
|
|
57
|
+
/**
|
|
58
|
+
* En pantallas angostas (< 640 px) oculta los números y muestra solo
|
|
59
|
+
* anterior/siguiente con el indicador "3 / 10".
|
|
60
|
+
*/
|
|
61
|
+
compactOnMobile?: boolean;
|
|
62
|
+
/** No muestra nada cuando hay una sola página (o ninguna). */
|
|
63
|
+
hideWhenSinglePage?: boolean;
|
|
64
|
+
/** Textos de la interfaz; por defecto en español. */
|
|
65
|
+
labels?: Partial<PaginationLabels>;
|
|
42
66
|
}
|
|
43
67
|
interface PaginationItemType {
|
|
44
68
|
page: number;
|
|
@@ -66,4 +90,4 @@ interface PaginationItemProps extends Omit<React.ButtonHTMLAttributes<HTMLButton
|
|
|
66
90
|
declare const PaginationItem: React.ForwardRefExoticComponent<PaginationItemProps & React.RefAttributes<HTMLButtonElement>>;
|
|
67
91
|
|
|
68
92
|
export { Pagination, PaginationItem };
|
|
69
|
-
export type { PaginationItemProps, PaginationItemType, PaginationProps, PaginationShape, PaginationSize, PaginationVariant };
|
|
93
|
+
export type { PaginationItemProps, PaginationItemType, PaginationLabels, PaginationProps, PaginationShape, PaginationSize, PaginationVariant };
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,YAAY,EACV,eAAe,EACf,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,YAAY,EACV,eAAe,EACf,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,YAAY,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/index.esm.js
CHANGED
|
@@ -545,10 +545,16 @@ const PaginationItem = React.forwardRef(({ page, type, selected = false, disable
|
|
|
545
545
|
});
|
|
546
546
|
PaginationItem.displayName = "PaginationItem";
|
|
547
547
|
|
|
548
|
-
var css_248z = "/* Pagination root */\n.Pagination-module_root__aWgof {\n display: flex;\n justify-content: center;\n align-items: center;\n}\n\n.Pagination-module_ul__MfLr5 {\n display: flex;\n flex-direction: row;\n align-items: center;\n padding: 0;\n margin: 0;\n list-style: none;\n gap: 4px;\n}\n";
|
|
549
|
-
var styles = {"root":"Pagination-module_root__aWgof","ul":"Pagination-module_ul__MfLr5"};
|
|
548
|
+
var css_248z = "/* Pagination root */\n.Pagination-module_root__aWgof {\n display: flex;\n justify-content: center;\n align-items: center;\n}\n\n.Pagination-module_ul__MfLr5 {\n display: flex;\n flex-direction: row;\n align-items: center;\n padding: 0;\n margin: 0;\n list-style: none;\n gap: 4px;\n}\n\n.Pagination-module_root__aWgof {\n flex-wrap: wrap;\n gap: var(--lb-space-3);\n}\n\n/* Resumen \"Mostrando 1–50 de 230\" */\n.Pagination-module_summary__BlA-j {\n margin: 0;\n font-size: var(--lb-font-size-sm);\n color: var(--lb-color-muted-foreground);\n}\n\n/* Indicador \"3 / 10\": solo en el celular con compactOnMobile */\n.Pagination-module_mobilePage__GRZee {\n display: none;\n padding: 0 var(--lb-space-3);\n font-size: var(--lb-font-size-sm);\n font-weight: var(--lb-font-weight-medium);\n color: var(--lb-color-foreground);\n}\n\n@media (max-width: 639px) {\n .Pagination-module_compactOnMobile__jNDTZ .Pagination-module_numbered__5gmrn {\n display: none;\n }\n\n .Pagination-module_compactOnMobile__jNDTZ .Pagination-module_mobilePage__GRZee {\n display: list-item;\n list-style: none;\n }\n}\n";
|
|
549
|
+
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
550
|
styleInject(css_248z);
|
|
551
551
|
|
|
552
|
+
const DEFAULT_PAGINATION_LABELS = {
|
|
553
|
+
summaryRange: "Mostrando {from}–{to} de {total}",
|
|
554
|
+
summaryTotal: "{total} en total",
|
|
555
|
+
mobilePage: "{page} / {count}",
|
|
556
|
+
};
|
|
557
|
+
const interpolate = (template, values) => template.replace(/\{(\w+)\}/g, (_, key) => String(values[key] ?? ""));
|
|
552
558
|
const classNames = (...classes) => classes.filter(Boolean).join(" ");
|
|
553
559
|
// Utility to generate pagination items
|
|
554
560
|
const usePagination = (props) => {
|
|
@@ -624,7 +630,7 @@ const usePagination = (props) => {
|
|
|
624
630
|
}
|
|
625
631
|
return items;
|
|
626
632
|
};
|
|
627
|
-
const Pagination = React.forwardRef(({ count = 1, page: controlledPage, defaultPage = 1, onChange, onPageChange, "aria-label": ariaLabel = "Paginación", disabled = false, hideNextButton = false, hidePrevButton = false, showFirstButton = false, showLastButton = false, boundaryCount = 1, siblingCount = 1, shape = "rounded", size: sizeProp = "medium", variant = "text", renderItem, className, ...props }, ref) => {
|
|
633
|
+
const Pagination = React.forwardRef(({ count = 1, page: controlledPage, defaultPage = 1, onChange, onPageChange, "aria-label": ariaLabel = "Paginación", 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) => {
|
|
628
634
|
const size = toLegacySize(sizeProp);
|
|
629
635
|
const [page, setPage] = React.useState(defaultPage);
|
|
630
636
|
const currentPage = controlledPage ?? page;
|
|
@@ -647,50 +653,76 @@ const Pagination = React.forwardRef(({ count = 1, page: controlledPage, defaultP
|
|
|
647
653
|
hideNextButton,
|
|
648
654
|
hidePrevButton,
|
|
649
655
|
});
|
|
650
|
-
const
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
656
|
+
const labels = { ...DEFAULT_PAGINATION_LABELS, ...labelsProp };
|
|
657
|
+
const classes = classNames(styles.root, compactOnMobile ? styles.compactOnMobile : undefined, className);
|
|
658
|
+
if (hideWhenSinglePage && count <= 1)
|
|
659
|
+
return null;
|
|
660
|
+
let summary;
|
|
661
|
+
if (totalCount !== undefined) {
|
|
662
|
+
if (pageSize && pageSize > 0) {
|
|
663
|
+
const from = totalCount === 0 ? 0 : (currentPage - 1) * pageSize + 1;
|
|
664
|
+
const to = Math.min(currentPage * pageSize, totalCount);
|
|
665
|
+
summary = interpolate(labels.summaryRange, {
|
|
666
|
+
from: from.toLocaleString("es-PE"),
|
|
667
|
+
to: to.toLocaleString("es-PE"),
|
|
668
|
+
total: totalCount.toLocaleString("es-PE"),
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
else {
|
|
672
|
+
summary = interpolate(labels.summaryTotal, {
|
|
673
|
+
total: totalCount.toLocaleString("es-PE"),
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
const isNumbered = (type) => type === "page" || type === "start-ellipsis" || type === "end-ellipsis";
|
|
678
|
+
const mobileIndicator = compactOnMobile ? (jsxRuntimeExports.jsx("li", { className: styles.mobilePage, "aria-hidden": "true", children: interpolate(labels.mobilePage, { page: currentPage, count }) })) : null;
|
|
679
|
+
return (jsxRuntimeExports.jsxs("nav", { ref: ref, className: classes, "aria-label": ariaLabel, ...props, children: [summary && (jsxRuntimeExports.jsx("p", { className: styles.summary, "aria-live": "polite", children: summary })), jsxRuntimeExports.jsx("ul", { className: styles.ul, children: items.map((item, index) => {
|
|
680
|
+
const isDisabled = disabled || item.disabled;
|
|
681
|
+
const itemClass = isNumbered(item.type)
|
|
682
|
+
? styles.numbered
|
|
683
|
+
: undefined;
|
|
684
|
+
const after = item.type === "previous" ? mobileIndicator : null;
|
|
685
|
+
if (renderItem) {
|
|
686
|
+
return (jsxRuntimeExports.jsxs(React.Fragment, { children: [jsxRuntimeExports.jsx("li", { className: itemClass, children: renderItem({
|
|
687
|
+
...item,
|
|
688
|
+
disabled: isDisabled,
|
|
689
|
+
onClick: (e) => {
|
|
690
|
+
if (!isDisabled && item.type === "page") {
|
|
691
|
+
handleClick(e, item.page);
|
|
692
|
+
}
|
|
693
|
+
else if (!isDisabled && item.type === "next") {
|
|
694
|
+
handleClick(e, Math.min(count, currentPage + 1));
|
|
695
|
+
}
|
|
696
|
+
else if (!isDisabled && item.type === "previous") {
|
|
697
|
+
handleClick(e, Math.max(1, currentPage - 1));
|
|
698
|
+
}
|
|
699
|
+
else if (!isDisabled && item.type === "first") {
|
|
700
|
+
handleClick(e, 1);
|
|
701
|
+
}
|
|
702
|
+
else if (!isDisabled && item.type === "last") {
|
|
703
|
+
handleClick(e, count);
|
|
704
|
+
}
|
|
705
|
+
},
|
|
706
|
+
}) }), after] }, index));
|
|
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) => {
|
|
709
|
+
if (!isDisabled && item.type === "page") {
|
|
710
|
+
handleClick(e, item.page);
|
|
711
|
+
}
|
|
712
|
+
else if (!isDisabled && item.type === "next") {
|
|
713
|
+
handleClick(e, Math.min(count, currentPage + 1));
|
|
714
|
+
}
|
|
715
|
+
else if (!isDisabled && item.type === "previous") {
|
|
716
|
+
handleClick(e, Math.max(1, currentPage - 1));
|
|
717
|
+
}
|
|
718
|
+
else if (!isDisabled && item.type === "first") {
|
|
719
|
+
handleClick(e, 1);
|
|
720
|
+
}
|
|
721
|
+
else if (!isDisabled && item.type === "last") {
|
|
722
|
+
handleClick(e, count);
|
|
723
|
+
}
|
|
724
|
+
} }) }), after] }, index));
|
|
725
|
+
}) })] }));
|
|
694
726
|
});
|
|
695
727
|
Pagination.displayName = "Pagination";
|
|
696
728
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rubenpazch/pagination",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.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/
|
|
24
|
-
"@rubenpazch/
|
|
23
|
+
"@rubenpazch/icons": "6.6.0",
|
|
24
|
+
"@rubenpazch/shared": "5.3.0"
|
|
25
25
|
},
|
|
26
26
|
"exports": {
|
|
27
27
|
".": {
|