react-router-pagination 3.3.5 → 3.3.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/README.md +1 -1
- package/eslint.config.mjs +1 -1
- package/package.json +6 -1
- package/src/pagination/common/index.mts +5 -18
- package/src/super/pagination/common/index.cjs +20 -0
- package/src/super/pagination/common/index.mjs +5 -0
- package/src/super/pagination/common/index.mts +18 -0
- package/src/super/pagination/component.tsx +12 -12
package/README.md
CHANGED
package/eslint.config.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-router-pagination",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.7",
|
|
4
4
|
"description": "A React Router Pagination component",
|
|
5
5
|
"main": "./src/index.mjs",
|
|
6
6
|
"type": "module",
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
"@storybook/theming": "^8.6.7",
|
|
52
52
|
"@testing-library/jest-dom": "^6.6.3",
|
|
53
53
|
"@testing-library/react": "^16.2.0",
|
|
54
|
+
"@types/babel__register": "^7.17.3",
|
|
54
55
|
"@types/debug": "^4.1.12",
|
|
55
56
|
"@types/jest": "^29.5.14",
|
|
56
57
|
"@types/prop-types": "^15.7.14",
|
|
@@ -106,6 +107,10 @@
|
|
|
106
107
|
"#pagination/super/pagination/component": {
|
|
107
108
|
"require": "./src/super/pagination/component.cjs",
|
|
108
109
|
"import": "./src/super/pagination/component.mjs"
|
|
110
|
+
},
|
|
111
|
+
"#pagination/super/pagination/common": {
|
|
112
|
+
"require": "./src/super/pagination/common/index.cjs",
|
|
113
|
+
"import": "./src/super/pagination/common/index.mjs"
|
|
109
114
|
}
|
|
110
115
|
},
|
|
111
116
|
"exports": {
|
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export function calculateTotalPages (totalItemsInCollection: number | string, itemsPerPage: number | string): number {
|
|
7
|
-
const e = toInteger(totalItemsInCollection)
|
|
8
|
-
const p = toInteger(itemsPerPage)
|
|
9
|
-
const r = Boolean(e % p) // !!(e % p)
|
|
10
|
-
const l = Math.floor(e / p)
|
|
11
|
-
return r ? l + 1 : l
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function calculatePageNumber (pageNumber: number | string, totalPages: number | string): number {
|
|
15
|
-
const p = toInteger(pageNumber)
|
|
16
|
-
const t = toInteger(totalPages)
|
|
17
|
-
return Math.max(1, Math.min(p, t))
|
|
18
|
-
}
|
|
1
|
+
export {
|
|
2
|
+
toInteger,
|
|
3
|
+
calculateTotalPages,
|
|
4
|
+
calculatePageNumber
|
|
5
|
+
} from '#pagination/super/pagination/common'
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require('@babel/register')({
|
|
2
|
+
ignore: [
|
|
3
|
+
/node_modules\/(?!react-router-pagination)/
|
|
4
|
+
],
|
|
5
|
+
extensions: [
|
|
6
|
+
'.mts',
|
|
7
|
+
'.cts',
|
|
8
|
+
'.tsx'
|
|
9
|
+
]
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
const {
|
|
13
|
+
toInteger,
|
|
14
|
+
calculateTotalPages,
|
|
15
|
+
calculatePageNumber
|
|
16
|
+
} = require('./index.mts')
|
|
17
|
+
|
|
18
|
+
module.exports.toInteger = toInteger
|
|
19
|
+
module.exports.calculateTotalPages = calculateTotalPages
|
|
20
|
+
module.exports.calculatePageNumber = calculatePageNumber
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function toInteger (v: number | string): number {
|
|
2
|
+
const n = Number(v)
|
|
3
|
+
return isNaN(n) ? 0 : Math.round(n)
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function calculateTotalPages (totalItemsInCollection: number | string, itemsPerPage: number | string): number {
|
|
7
|
+
const e = toInteger(totalItemsInCollection)
|
|
8
|
+
const p = toInteger(itemsPerPage)
|
|
9
|
+
const r = Boolean(e % p) // !!(e % p)
|
|
10
|
+
const l = Math.floor(e / p)
|
|
11
|
+
return r ? l + 1 : l
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function calculatePageNumber (pageNumber: number | string, totalPages: number | string): number {
|
|
15
|
+
const p = toInteger(pageNumber)
|
|
16
|
+
const t = toInteger(totalPages)
|
|
17
|
+
return Math.max(1, Math.min(p, t))
|
|
18
|
+
}
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
toInteger,
|
|
14
14
|
calculateTotalPages,
|
|
15
15
|
calculatePageNumber
|
|
16
|
-
} from '#pagination/pagination/common'
|
|
16
|
+
} from '#pagination/super/pagination/common'
|
|
17
17
|
|
|
18
18
|
const getListItemClassName = (currentPageNumber: string | number, pageNumber: string | number): string => (
|
|
19
19
|
toInteger(currentPageNumber) === toInteger(pageNumber)
|
|
@@ -122,7 +122,7 @@ export abstract class AbstractPagination<P, S> extends Component<P & AbstractPag
|
|
|
122
122
|
<li key={getListItemKey(n)} className='zero-page'>
|
|
123
123
|
<Link to={getLinkTo(match, n)} onClick={() => { this.handlePageNumberSelect(n) }}>
|
|
124
124
|
<span className='page-number'>
|
|
125
|
-
|
|
125
|
+
1
|
|
126
126
|
</span>
|
|
127
127
|
</Link>
|
|
128
128
|
</li>
|
|
@@ -138,7 +138,7 @@ export abstract class AbstractPagination<P, S> extends Component<P & AbstractPag
|
|
|
138
138
|
<li key={getListItemKey(n)} className='last-page'>
|
|
139
139
|
<Link to={getLinkTo(match, n)} onClick={() => { this.handlePageNumberSelect(n) }}>
|
|
140
140
|
<span className='page-number'>
|
|
141
|
-
{n}
|
|
141
|
+
{String(n)}
|
|
142
142
|
</span>
|
|
143
143
|
</Link>
|
|
144
144
|
</li>
|
|
@@ -153,15 +153,15 @@ export abstract class AbstractPagination<P, S> extends Component<P & AbstractPag
|
|
|
153
153
|
const a = []
|
|
154
154
|
for (j; i < j; i = i + 1) {
|
|
155
155
|
const n = (i + 1)
|
|
156
|
-
a.push(
|
|
156
|
+
a.push(
|
|
157
157
|
<li key={getListItemKey(n)} className={getListItemClassName(pageNumber, n)}>
|
|
158
158
|
<Link to={getLinkTo(match, n)} onClick={() => { this.handlePageNumberSelect(n) }}>
|
|
159
159
|
<span className='page-number'>
|
|
160
|
-
{n}
|
|
160
|
+
{String(n)}
|
|
161
161
|
</span>
|
|
162
162
|
</Link>
|
|
163
163
|
</li>
|
|
164
|
-
)
|
|
164
|
+
)
|
|
165
165
|
}
|
|
166
166
|
return a
|
|
167
167
|
}
|
|
@@ -201,13 +201,13 @@ export abstract class AbstractPagination<P, S> extends Component<P & AbstractPag
|
|
|
201
201
|
{this.lastPageLinkItem(match, page, totalPages)}
|
|
202
202
|
</ul>
|
|
203
203
|
)
|
|
204
|
-
} else {
|
|
205
|
-
return (
|
|
206
|
-
<ul className='pagination'>
|
|
207
|
-
{this.pageLinkItems(match, page, totalPages)}
|
|
208
|
-
</ul>
|
|
209
|
-
)
|
|
210
204
|
}
|
|
205
|
+
|
|
206
|
+
return (
|
|
207
|
+
<ul className='pagination'>
|
|
208
|
+
{this.pageLinkItems(match, page, totalPages)}
|
|
209
|
+
</ul>
|
|
210
|
+
)
|
|
211
211
|
}
|
|
212
212
|
return null
|
|
213
213
|
}
|