@0xchain/pagination 1.1.0-beta.18 → 1.1.0-beta.19
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 +13 -0
- package/LICENSE +21 -0
- package/dist/index.js +117 -95
- package/package.json +19 -7
- package/tsconfig.json +0 -3
- package/vite.config.ts +1 -12
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present 0xchain
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.js
CHANGED
|
@@ -1,136 +1,158 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx
|
|
3
|
-
import * as
|
|
4
|
-
import { Pagination
|
|
5
|
-
import { Select
|
|
6
|
-
import { twMerge
|
|
7
|
-
import { useTranslations
|
|
8
|
-
import { ChevronRight
|
|
9
|
-
const
|
|
10
|
-
function
|
|
11
|
-
className
|
|
12
|
-
total:
|
|
13
|
-
pageSize
|
|
14
|
-
pageSizeOptions
|
|
15
|
-
currentPage
|
|
16
|
-
layout
|
|
17
|
-
onPageChange
|
|
18
|
-
onPageSizeChange
|
|
19
|
-
totalLabel
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Pagination, PaginationContent, PaginationItem, PaginationLink, PaginationEllipsis } from "@0xchain/ui/pagination";
|
|
5
|
+
import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from "@0xchain/ui/select";
|
|
6
|
+
import { twMerge } from "tailwind-merge";
|
|
7
|
+
import { useTranslations } from "next-intl";
|
|
8
|
+
import { ChevronRight, ChevronLeft } from "lucide-react";
|
|
9
|
+
const limit = 1e4;
|
|
10
|
+
function CustomPagination({
|
|
11
|
+
className,
|
|
12
|
+
total: initialTotal,
|
|
13
|
+
pageSize,
|
|
14
|
+
pageSizeOptions = [10, 30, 50],
|
|
15
|
+
currentPage,
|
|
16
|
+
layout = ["prev", "page", "next", "ellipsis", "sizes", "total"],
|
|
17
|
+
onPageChange,
|
|
18
|
+
onPageSizeChange,
|
|
19
|
+
totalLabel
|
|
20
20
|
}) {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
) }, "first")
|
|
38
|
-
), o > 2 && i.push(
|
|
39
|
-
/* @__PURE__ */ e(r, { children: /* @__PURE__ */ e(v, {}) }, "ellipsis-start")
|
|
40
|
-
));
|
|
41
|
-
for (let c = o; c <= m; c++)
|
|
42
|
-
i.push(
|
|
43
|
-
/* @__PURE__ */ e(r, { children: /* @__PURE__ */ e(
|
|
44
|
-
a,
|
|
21
|
+
const t = useTranslations();
|
|
22
|
+
const total = Math.min(initialTotal, limit);
|
|
23
|
+
const totalPages = Math.ceil(total / pageSize);
|
|
24
|
+
const renderPageNumbers = () => {
|
|
25
|
+
const pages = [];
|
|
26
|
+
const maxVisiblePages = 3;
|
|
27
|
+
let startPage = Math.max(1, currentPage - Math.floor(maxVisiblePages / 2));
|
|
28
|
+
const endPage = Math.min(totalPages, startPage + maxVisiblePages - 1);
|
|
29
|
+
if (endPage - startPage + 1 < maxVisiblePages) {
|
|
30
|
+
startPage = Math.max(1, endPage - maxVisiblePages + 1);
|
|
31
|
+
}
|
|
32
|
+
if (startPage > 1) {
|
|
33
|
+
pages.push(
|
|
34
|
+
/* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(
|
|
35
|
+
PaginationLink,
|
|
45
36
|
{
|
|
46
37
|
size: "sm",
|
|
47
|
-
className:
|
|
38
|
+
className: twMerge(
|
|
48
39
|
"h-6 min-w-6 w-fit rounded-md cursor-pointer",
|
|
49
|
-
|
|
40
|
+
currentPage === 1 ? "bg-[#000]! text-primary-foreground!" : ""
|
|
50
41
|
),
|
|
51
|
-
onClick: () =>
|
|
52
|
-
children:
|
|
42
|
+
onClick: () => onPageChange?.(1),
|
|
43
|
+
children: "1"
|
|
53
44
|
}
|
|
54
|
-
) },
|
|
45
|
+
) }, "first")
|
|
55
46
|
);
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
47
|
+
if (startPage > 2) {
|
|
48
|
+
pages.push(
|
|
49
|
+
/* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationEllipsis, {}) }, "ellipsis-start")
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
for (let i = startPage; i <= endPage; i++) {
|
|
54
|
+
pages.push(
|
|
55
|
+
/* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(
|
|
56
|
+
PaginationLink,
|
|
57
|
+
{
|
|
58
|
+
size: "sm",
|
|
59
|
+
className: twMerge(
|
|
60
|
+
"h-6 min-w-6 w-fit rounded-md cursor-pointer",
|
|
61
|
+
currentPage === i ? "bg-[#000]! text-primary-foreground!" : ""
|
|
62
|
+
),
|
|
63
|
+
onClick: () => onPageChange?.(i),
|
|
64
|
+
children: i
|
|
65
|
+
}
|
|
66
|
+
) }, i)
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
if (endPage < totalPages) {
|
|
70
|
+
if (endPage < totalPages - 1) {
|
|
71
|
+
pages.push(
|
|
72
|
+
/* @__PURE__ */ jsx(PaginationItem, { className: "cursor-pointer", children: /* @__PURE__ */ jsx(PaginationEllipsis, {}) }, "ellipsis-end")
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
pages.push(
|
|
76
|
+
/* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(
|
|
77
|
+
PaginationLink,
|
|
78
|
+
{
|
|
79
|
+
size: "sm",
|
|
80
|
+
className: twMerge(
|
|
81
|
+
"h-6 min-w-6 w-fit rounded-md cursor-pointer",
|
|
82
|
+
currentPage === totalPages ? "bg-[#000]! text-primary-foreground!" : ""
|
|
83
|
+
),
|
|
84
|
+
onClick: () => onPageChange?.(totalPages),
|
|
85
|
+
children: totalPages
|
|
86
|
+
}
|
|
87
|
+
) }, "last")
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
return pages;
|
|
72
91
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
92
|
+
if (total <= pageSizeOptions[0]) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
return /* @__PURE__ */ jsx(Pagination, { className: twMerge("w-full max-w-screen mt-3", className), children: /* @__PURE__ */ jsxs(PaginationContent, { className: "w-full flex flex-row items-center justify-between flex-wrap", children: [
|
|
96
|
+
layout.includes("total") && /* @__PURE__ */ jsx(PaginationItem, { className: "mr-auto order-1 flex-1 overflow-hidden md:overflow-visible md:order-0 ", children: totalLabel || /* @__PURE__ */ jsxs("span", { className: "text-sm block text-muted-foreground w-full truncate", children: [
|
|
97
|
+
t("common.pagination.total"),
|
|
76
98
|
" ",
|
|
77
|
-
|
|
99
|
+
initialTotal,
|
|
78
100
|
" ",
|
|
79
|
-
|
|
80
|
-
|
|
101
|
+
t("common.pagination.item"),
|
|
102
|
+
initialTotal > limit ? `${t("common.pagination.totalTip")}` : ""
|
|
81
103
|
] }) }, "total"),
|
|
82
|
-
/* @__PURE__ */
|
|
83
|
-
switch (
|
|
104
|
+
/* @__PURE__ */ jsx("div", { className: "w-full md:w-auto md:flex-2 flex items-center justify-center", children: layout.filter((item) => item !== "total" && item !== "sizes").map((item) => {
|
|
105
|
+
switch (item) {
|
|
84
106
|
case "prev":
|
|
85
|
-
return /* @__PURE__ */
|
|
86
|
-
|
|
107
|
+
return /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(
|
|
108
|
+
PaginationLink,
|
|
87
109
|
{
|
|
88
110
|
"aria-label": "Go to previous page",
|
|
89
111
|
size: "sm",
|
|
90
|
-
className:
|
|
112
|
+
className: twMerge(
|
|
91
113
|
"flex items-center justify-center pointer gap-1 shrink-0 cursor-pointer px-2",
|
|
92
|
-
|
|
114
|
+
currentPage === 1 ? "pointer-events-none opacity-50" : ""
|
|
93
115
|
),
|
|
94
|
-
onClick: () =>
|
|
95
|
-
children: /* @__PURE__ */
|
|
116
|
+
onClick: () => onPageChange?.(Math.max(1, currentPage - 1)),
|
|
117
|
+
children: /* @__PURE__ */ jsx(ChevronLeft, { size: 16 })
|
|
96
118
|
}
|
|
97
119
|
) }, "prev");
|
|
98
120
|
case "page":
|
|
99
|
-
return /* @__PURE__ */
|
|
121
|
+
return /* @__PURE__ */ jsx(React.Fragment, { children: renderPageNumbers() }, "page");
|
|
100
122
|
case "next":
|
|
101
|
-
return /* @__PURE__ */
|
|
102
|
-
|
|
123
|
+
return /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(
|
|
124
|
+
PaginationLink,
|
|
103
125
|
{
|
|
104
126
|
size: "sm",
|
|
105
|
-
className:
|
|
127
|
+
className: twMerge(
|
|
106
128
|
"flex items-center justify-center pointer gap-1 shrink-0 cursor-pointer px-2",
|
|
107
|
-
|
|
129
|
+
currentPage === totalPages ? "pointer-events-none opacity-50" : ""
|
|
108
130
|
),
|
|
109
|
-
onClick: () =>
|
|
110
|
-
children: /* @__PURE__ */
|
|
131
|
+
onClick: () => onPageChange?.(Math.min(totalPages, currentPage + 1)),
|
|
132
|
+
children: /* @__PURE__ */ jsx(ChevronRight, { size: 16 })
|
|
111
133
|
}
|
|
112
134
|
) }, "next");
|
|
113
135
|
default:
|
|
114
136
|
return null;
|
|
115
137
|
}
|
|
116
138
|
}) }),
|
|
117
|
-
|
|
118
|
-
/* @__PURE__ */
|
|
119
|
-
/* @__PURE__ */
|
|
120
|
-
|
|
139
|
+
layout.includes("sizes") && onPageSizeChange && /* @__PURE__ */ jsxs(PaginationItem, { className: "gap-2 flex shrink-0 order-1 lg:order-0 items-center py-0.5 flex-1 justify-end", children: [
|
|
140
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm text-muted-foreground", children: t("common.pagination.sizeLabel") }),
|
|
141
|
+
/* @__PURE__ */ jsxs(
|
|
142
|
+
Select,
|
|
121
143
|
{
|
|
122
|
-
value:
|
|
123
|
-
onValueChange: (
|
|
144
|
+
value: pageSize.toString(),
|
|
145
|
+
onValueChange: (value) => onPageSizeChange(Number(value)),
|
|
124
146
|
children: [
|
|
125
|
-
/* @__PURE__ */
|
|
126
|
-
|
|
147
|
+
/* @__PURE__ */ jsx(
|
|
148
|
+
SelectTrigger,
|
|
127
149
|
{
|
|
128
150
|
size: "sm",
|
|
129
151
|
className: "border border-input w-[70px] focus:ring-0 text-foreground bg-background focus-visible:outline-0 focus-ring-0 focus-visible:ring-0 focus-visible:ring-offset-0 focus-visible:border-input py-1",
|
|
130
|
-
children: /* @__PURE__ */
|
|
152
|
+
children: /* @__PURE__ */ jsx(SelectValue, {})
|
|
131
153
|
}
|
|
132
154
|
),
|
|
133
|
-
/* @__PURE__ */
|
|
155
|
+
/* @__PURE__ */ jsx(SelectContent, { className: "w-20 bg-card", children: pageSizeOptions.map((size) => /* @__PURE__ */ jsx(SelectItem, { value: size.toString(), className: "text-sm px-2 py-1 cursor-pointer hover:bg-background", children: size }, size)) })
|
|
134
156
|
]
|
|
135
157
|
}
|
|
136
158
|
)
|
|
@@ -138,5 +160,5 @@ function K({
|
|
|
138
160
|
] }) });
|
|
139
161
|
}
|
|
140
162
|
export {
|
|
141
|
-
|
|
163
|
+
CustomPagination as default
|
|
142
164
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xchain/pagination",
|
|
3
|
-
"version": "1.1.0-beta.
|
|
3
|
+
"version": "1.1.0-beta.19",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -13,16 +13,28 @@
|
|
|
13
13
|
"default": "./dist/index.js"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
|
-
"
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"lucide-react": "0.539.0",
|
|
18
|
+
"next-intl": "4.8.2",
|
|
17
19
|
"react": "19.1.1",
|
|
18
20
|
"react-dom": "19.1.1",
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"@0xchain/ui": "1.1.0-beta.
|
|
21
|
+
"tailwind-merge": "3.3.1"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@0xchain/ui": "1.1.0-beta.19"
|
|
23
25
|
},
|
|
24
26
|
"devDependencies": {
|
|
25
|
-
"
|
|
27
|
+
"lucide-react": "0.539.0",
|
|
28
|
+
"next-intl": "4.8.2",
|
|
29
|
+
"react": "19.1.1",
|
|
30
|
+
"react-dom": "19.1.1",
|
|
31
|
+
"rollup-plugin-preserve-use-client": "3.0.1",
|
|
32
|
+
"tailwind-merge": "3.3.1"
|
|
33
|
+
},
|
|
34
|
+
"nx": {
|
|
35
|
+
"tags": [
|
|
36
|
+
"type:ui"
|
|
37
|
+
]
|
|
26
38
|
},
|
|
27
39
|
"publishConfig": {
|
|
28
40
|
"access": "public"
|
package/tsconfig.json
CHANGED
package/vite.config.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types='vitest' />
|
|
2
1
|
import { defineConfig } from 'vite';
|
|
3
2
|
import react from '@vitejs/plugin-react';
|
|
4
3
|
import dts from 'vite-plugin-dts';
|
|
@@ -16,31 +15,21 @@ export default defineConfig(() => ({
|
|
|
16
15
|
tsconfigPath: path.join(__dirname, 'tsconfig.lib.json')
|
|
17
16
|
}),
|
|
18
17
|
],
|
|
19
|
-
// Uncomment this if you are using workers.
|
|
20
|
-
// worker: {
|
|
21
|
-
// plugins: [ nxViteTsPaths() ],
|
|
22
|
-
// },
|
|
23
|
-
// Configuration for building your library.
|
|
24
|
-
// See: https://vitejs.dev/guide/build.html#library-mode
|
|
25
18
|
build: {
|
|
26
19
|
outDir: './dist',
|
|
27
20
|
emptyOutDir: true,
|
|
28
|
-
minify:
|
|
21
|
+
minify: false,
|
|
29
22
|
reportCompressedSize: true,
|
|
30
23
|
commonjsOptions: {
|
|
31
24
|
transformMixedEsModules: true,
|
|
32
25
|
},
|
|
33
26
|
lib: {
|
|
34
|
-
// Could also be a dictionary or array of multiple entry points.
|
|
35
27
|
entry: 'src/index.tsx',
|
|
36
28
|
name: '@0xchain/pagination',
|
|
37
29
|
fileName: 'index',
|
|
38
|
-
// Change this to the formats you want to support.
|
|
39
|
-
// Don't forget to update your package.json as well.
|
|
40
30
|
formats: ['es' as const],
|
|
41
31
|
},
|
|
42
32
|
rollupOptions: {
|
|
43
|
-
// External packages that should not be bundled into your library.
|
|
44
33
|
external: [
|
|
45
34
|
'react', 'react-dom', 'react/jsx-runtime', 'tailwind-merge', 'lucide-react', 'next-intl',
|
|
46
35
|
/^@0xchain\/.+/,
|