react-router-pagination 3.2.308 → 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/babel.config.cjs CHANGED
@@ -35,13 +35,34 @@ const presets = [
35
35
  useBuiltIns: 'usage',
36
36
  corejs: 3
37
37
  }
38
+ ],
39
+ '@babel/react',
40
+ '@babel/typescript'
41
+ ]
42
+
43
+ const plugins = [
44
+ '@babel/syntax-jsx',
45
+ [
46
+ 'module-resolver', {
47
+ alias: {
48
+ '#pagination/pagination/component': './src/pagination/component.tsx',
49
+ '#pagination/super/pagination/component': './src/super/pagination/component.tsx'
50
+ }
51
+ }
38
52
  ]
39
53
  ]
40
54
 
55
+ // @ts-ignore
41
56
  module.exports = (api) => {
42
57
  if (api) api.cache.using(env)
43
58
 
44
59
  return {
45
- presets
60
+ presets,
61
+ plugins,
62
+ ignore: [
63
+ /node_modules\/(?!react-component-instance)\//,
64
+ /node_modules\/(?!react-component-snapshot)\//,
65
+ /node_modules\/(?!react-component-name)\//
66
+ ]
46
67
  }
47
68
  }
package/eslint.config.mjs CHANGED
@@ -137,7 +137,7 @@ export default [
137
137
  }),
138
138
  standard({
139
139
  files: [
140
- 'src/**/__tests__/**/*.{mts,tsx}',
140
+ 'src/**/__tests__/**/*.{mjs,jsx}',
141
141
  'stories/**/__tests__/**/*.{mjs,jsx}'
142
142
  ],
143
143
  languageOptions: {
@@ -211,7 +211,8 @@ export default [
211
211
  project: 'tsconfig.json'
212
212
  },
213
213
  globals: {
214
- ...globals.browser
214
+ ...globals.browser,
215
+ ReactRouterPaginationTypes: 'readonly'
215
216
  }
216
217
  },
217
218
  plugins: {
@@ -220,9 +221,16 @@ export default [
220
221
  rules: {
221
222
  ...reactRules,
222
223
  '@typescript-eslint/no-magic-numbers': 'off',
223
- '@typescript-eslint/prefer-destructuring': 'off',
224
+ '@typescript-eslint/prefer-destructuring': 'warn',
224
225
  '@typescript-eslint/class-methods-use-this': 'off',
225
- '@typescript-eslint/no-empty-function': 'off'
226
+ '@typescript-eslint/no-empty-function': 'warn',
227
+ '@typescript-eslint/no-unsafe-assignment': 'warn',
228
+ '@typescript-eslint/no-unsafe-member-access': 'warn',
229
+ '@typescript-eslint/no-unsafe-call': 'warn',
230
+ '@typescript-eslint/no-unsafe-return': 'warn',
231
+ '@typescript-eslint/strict-boolean-expressions': 'warn',
232
+ '@typescript-eslint/prefer-nullish-coalescing': 'warn',
233
+ '@typescript-eslint/no-unsafe-argument': 'warn'
226
234
  },
227
235
  settings: {
228
236
  ...reactSettings
package/index.d.mts ADDED
@@ -0,0 +1,46 @@
1
+ declare global {
2
+ namespace ReactRouterPaginationTypes {
3
+ export interface AbstractPaginationProps {
4
+ onClick: (pageNumber: number) => void
5
+ pageNumber: string | number
6
+ totalPages: string | number
7
+ match: {
8
+ path?: string
9
+ params?: object
10
+ }
11
+ }
12
+
13
+ export interface AbstractPaginationState {
14
+ pageNumber: number
15
+ totalPages: number
16
+ }
17
+
18
+ export interface CenteredProps extends AbstractPaginationProps {
19
+ spread: string | number
20
+ onChange: (pageNumber: number) => void
21
+ }
22
+
23
+ export interface CenteredState extends AbstractPaginationState {
24
+ spread: number
25
+ }
26
+
27
+ export interface StandardProps extends AbstractPaginationProps {
28
+ pageNumber: string | number
29
+ totalPages: string | number
30
+ spread: string | number
31
+ onChange: (pageNumber: number) => void
32
+ }
33
+
34
+ export interface StandardState extends AbstractPaginationState {
35
+ pageNumber: number
36
+ totalPages: number
37
+ spread: number
38
+ }
39
+
40
+ export interface PaginationProps {
41
+ format?: string
42
+ }
43
+ }
44
+ }
45
+
46
+ export {}
@@ -0,0 +1,26 @@
1
+ export default {
2
+ bail: true,
3
+ verbose: true,
4
+ rootDir: '.',
5
+ roots: [
6
+ './src'
7
+ ],
8
+ clearMocks: true,
9
+ collectCoverage: true,
10
+ coverageDirectory: './coverage',
11
+ coverageProvider: 'v8',
12
+ testRegex: '(/__tests__/.*|(\\.|/))(test|spec)\\.(jsx?|mjs?)$',
13
+ transform: {
14
+ '^.+\\.jsx$': 'babel-jest',
15
+ '^.+\\.mjs$': 'babel-jest',
16
+ '^.+\\.tsx$': 'babel-jest',
17
+ '^.+\\.mts$': 'babel-jest'
18
+ },
19
+ transformIgnorePatterns: [
20
+ '/node_modules\\/(?!react-component-instance)\\/',
21
+ '/node_modules\\/(?!react-component-snapshot)\\/',
22
+ '/node_modules\\/(?!react-component-name)\\/'
23
+ ],
24
+ moduleFileExtensions: ['js', 'jsx', 'mjs'],
25
+ testEnvironment: 'jest-fixed-jsdom'
26
+ }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "react-router-pagination",
3
- "version": "3.2.308",
3
+ "version": "3.3.0",
4
4
  "description": "A React Router Pagination component",
5
5
  "main": "./src/index.mjs",
6
6
  "type": "module",
7
- "types": "./src/index.d.mts",
7
+ "types": "./index.d.mts",
8
8
  "author": {
9
9
  "name": "Jonathan Perry for Sequence Media Limited",
10
10
  "email": "sequencemedia@sequencemedia.net",
@@ -40,21 +40,25 @@
40
40
  "@babel/register": "^7.25.9",
41
41
  "@chromatic-com/storybook": "^3.2.6",
42
42
  "@sequencemedia/eslint-config-standard": "^0.2.43",
43
- "@sequencemedia/eslint-config-typescript": "^0.1.62",
43
+ "@sequencemedia/eslint-config-typescript": "^0.1.63",
44
44
  "@storybook/addon-essentials": "^8.6.7",
45
45
  "@storybook/addon-links": "^8.6.7",
46
46
  "@storybook/addon-webpack5-compiler-babel": "^3.0.5",
47
47
  "@storybook/manager-api": "^8.6.7",
48
48
  "@storybook/react": "^8.6.7",
49
49
  "@storybook/react-webpack5": "^8.6.7",
50
+ "@storybook/test": "^8.6.7",
50
51
  "@storybook/theming": "^8.6.7",
52
+ "@testing-library/jest-dom": "^6.6.3",
53
+ "@testing-library/react": "^16.2.0",
51
54
  "@types/debug": "^4.1.12",
52
55
  "@types/jest": "^29.5.14",
56
+ "@types/prop-types": "^15.7.14",
53
57
  "@types/react": "^19.0.12",
58
+ "@types/react-dom": "^19.0.4",
54
59
  "@types/react-router": "^5.1.20",
55
- "@types/react-test-renderer": "^19.0.0",
56
- "@typescript-eslint/eslint-plugin": "^8.26.1",
57
- "@typescript-eslint/parser": "^8.26.1",
60
+ "@typescript-eslint/eslint-plugin": "^8.27.0",
61
+ "@typescript-eslint/parser": "^8.27.0",
58
62
  "babel-plugin-module-resolver": "^5.0.2",
59
63
  "core-js": "^3.41.0",
60
64
  "cross-env": "^7.0.3",
@@ -65,19 +69,45 @@
65
69
  "globals": "^16.0.0",
66
70
  "husky": "^9.1.7",
67
71
  "jest": "^29.7.0",
72
+ "jest-environment-jsdom": "^29.7.0",
73
+ "jest-fixed-jsdom": "^0.0.9",
68
74
  "prop-types": "^15.8.1",
69
75
  "react": "^19.0.0",
76
+ "react-component-snapshot": "^0.0.7",
70
77
  "react-dom": "^19.0.0",
71
78
  "react-router": "^7.4.0",
72
79
  "react-test-renderer": "^19.0.0",
73
80
  "storybook": "^8.6.7"
74
81
  },
75
82
  "imports": {
76
- "#pagination": "./src/pagination/index.tsx",
77
- "#pagination/centered": "./src/pagination/centered/index.tsx",
78
- "#pagination/common": "./src/pagination/common/index.mts",
79
- "#pagination/component": "./src/pagination/component.tsx",
80
- "#pagination/standard": "./src/pagination/standard/index.tsx"
83
+ "#pagination": {
84
+ "require": "./src/index.cjs",
85
+ "import": "./src/index.mjs"
86
+ },
87
+ "#pagination/pagination": {
88
+ "require": "./src/pagination/index.cjs",
89
+ "import": "./src/pagination/index.mjs"
90
+ },
91
+ "#pagination/pagination/centered": {
92
+ "require": "./src/pagination/centered/index.cjs",
93
+ "import": "./src/pagination/centered/index.mjs"
94
+ },
95
+ "#pagination/pagination/common": {
96
+ "require": "./src/pagination/common/index.cjs",
97
+ "import": "./src/pagination/common/index.mjs"
98
+ },
99
+ "#pagination/pagination/component": {
100
+ "require": "./src/pagination/component.cjs",
101
+ "import": "./src/pagination/component.mjs"
102
+ },
103
+ "#pagination/pagination/standard": {
104
+ "require": "./src/pagination/standard/index.cjs",
105
+ "import": "./src/pagination/standard/index.mjs"
106
+ },
107
+ "#pagination/super/pagination/component": {
108
+ "require": "./src/super/pagination/component.cjs",
109
+ "import": "./src/super/pagination/component.mjs"
110
+ }
81
111
  },
82
112
  "exports": {
83
113
  ".": {
package/src/index.cjs CHANGED
@@ -9,8 +9,4 @@ require('@babel/register')({
9
9
  ]
10
10
  })
11
11
 
12
- const {
13
- default: component
14
- } = require('./index.tsx')
15
-
16
- module.exports = component
12
+ module.exports = require('./index.tsx')
package/src/index.d.mts CHANGED
@@ -1,46 +1,3 @@
1
- declare namespace ReactRouterPaginationTypes {
2
- export interface AbstractPaginationProps {
3
- onClick: (pageNumber: number) => void
4
- pageNumber: string | number
5
- totalPages: string | number
6
- match: {
7
- path?: string
8
- params?: object
9
- }
10
- }
11
-
12
- export interface AbstractPaginationState {
13
- pageNumber: number
14
- totalPages: number
15
- }
16
-
17
- export interface CenteredProps extends AbstractPaginationProps {
18
- spread: string | number
19
- onChange: (pageNumber: number) => void
20
- }
21
-
22
- export interface CenteredState extends AbstractPaginationState {
23
- spread: number
24
- }
25
-
26
- export interface StandardProps extends AbstractPaginationProps {
27
- pageNumber: string | number
28
- totalPages: string | number
29
- spread: string | number
30
- onChange: (pageNumber: number) => void
31
- }
32
-
33
- export interface StandardState extends AbstractPaginationState {
34
- pageNumber: number
35
- totalPages: number
36
- spread: number
37
- }
38
-
39
- export interface PaginationProps {
40
- format?: string
41
- }
42
- }
43
-
44
1
  declare module 'react-router-pagination' {
45
2
  import type { JSX } from 'react'
46
3
 
package/src/index.tsx CHANGED
@@ -1,5 +1,4 @@
1
1
  import type { JSX } from 'react'
2
- import type ReactRouterPaginationTypes from 'react-router-pagination'
3
2
  import React, { Component } from 'react'
4
3
 
5
4
  import {
@@ -1,12 +1,12 @@
1
1
  import debug from 'debug'
2
2
 
3
- import type ReactRouterPaginationTypes from 'react-router-pagination'
3
+ import AbstractPagination from '#pagination/super/pagination/component' // '../../super/pagination/component.tsx'
4
4
 
5
- import AbstractPagination, {
5
+ import {
6
6
  toInteger,
7
7
  calculateTotalPages,
8
8
  calculatePageNumber
9
- } from '#pagination/component'
9
+ } from '#pagination/pagination/component'
10
10
 
11
11
  const error = debug('react-router-pagination/pagination/component')
12
12
 
@@ -1,30 +1,18 @@
1
1
  /**
2
2
  * Pagination component
3
3
  */
4
- import type { JSX } from 'react'
5
- import type ReactRouterPaginationTypes from 'react-router-pagination'
6
- import React, { Component } from 'react'
7
-
8
- import {
9
- Link,
10
- generatePath
11
- } from 'react-router'
12
-
13
4
  import {
14
5
  toInteger,
15
6
  calculateTotalPages,
16
7
  calculatePageNumber
17
- } from './common/index.mts'
8
+ } from '#pagination/pagination/common'
18
9
 
19
- const getListItemClassName = (currentPageNumber: string | number, pageNumber: string | number): string => (
20
- toInteger(currentPageNumber) === toInteger(pageNumber)
21
- ? 'current-page'
22
- : 'page'
23
- )
10
+ import AbstractPagination from '#pagination/super/pagination/component' // '../super/pagination/component.tsx'
24
11
 
25
- const getListItemKey = (key: string | number): string => `list-item-${key}`
26
-
27
- const getLinkTo = ({ path = '/:pageNumber', params = {} } = {}, pageNumber = 0): string => generatePath(path, { ...params, pageNumber })
12
+ import type {
13
+ AbstractPaginationProps,
14
+ AbstractPaginationState
15
+ } from '#pagination/super/pagination/component'
28
16
 
29
17
  export {
30
18
  toInteger,
@@ -32,194 +20,6 @@ export {
32
20
  calculatePageNumber
33
21
  }
34
22
 
35
- type AbstractPaginationProps = ReactRouterPaginationTypes.AbstractPaginationProps
36
-
37
- type AbstractPaginationState = ReactRouterPaginationTypes.AbstractPaginationState
38
-
39
- export default abstract class AbstractPagination<P, S> extends Component<P & AbstractPaginationProps, S & AbstractPaginationState> { // eslint-disable-line @typescript-eslint/no-unnecessary-type-parameters -- Base
40
- static defaultProps = {
41
- onClick () {},
42
- pageNumber: 0,
43
- totalPages: 0,
44
- match: {}
45
- }
46
-
47
- static calculateTotalPages = calculateTotalPages
48
-
49
- static calculatePageNumber = calculatePageNumber
50
-
51
- x (): number {
52
- return 0
53
- }
54
-
55
- y (): number {
56
- return 0
57
- }
58
-
59
- z (): number {
60
- return 0
61
- }
62
-
63
- zeroIndex (pageNumber: string | number, totalPages: string | number): number { // eslint-disable-line no-unused-vars -- Base
64
- return 0
65
- }
66
-
67
- lastIndex (pageNumber: string | number, totalPages: string | number): number { // eslint-disable-line no-unused-vars -- Base
68
- return 0
69
- }
70
-
71
- hasReversePageLink (pageNumber: string | number, totalPages: string | number): boolean {
72
- return (this.zeroIndex(pageNumber, totalPages) - 1) > 0
73
- }
74
-
75
- hasForwardPageLink (pageNumber: string | number, totalPages: string | number): boolean {
76
- const i = Number(pageNumber)
77
- const j = Number(totalPages)
78
- return (this.lastIndex(i, j) + 1) < j
79
- }
80
-
81
- hasZeroPageLink (pageNumber: string | number, totalPages: string | number): boolean {
82
- const i = Number(pageNumber)
83
- const j = Number(totalPages)
84
- return this.zeroIndex(i, j) > 0
85
- }
86
-
87
- hasLastPageLink (pageNumber: string | number, totalPages: string | number): boolean {
88
- const i = Number(pageNumber)
89
- const j = Number(totalPages)
90
- return this.lastIndex(i, j) < j
91
- }
92
-
93
- reversePageLinkItem (match: object, pageNumber: string | number, totalPages: string | number): JSX.Element | null {
94
- if (this.hasReversePageLink(pageNumber, totalPages)) {
95
- const n = this.zeroIndex(pageNumber, totalPages)
96
- return (
97
- <li key={getListItemKey('reverse')} className='reverse-page'>
98
- <Link to={getLinkTo(match, n)} onClick={() => { this.handlePageNumberSelect(n) }}>
99
- <span className='reverse'>
100
- {'\u2039'}
101
- </span>
102
- </Link>
103
- </li>
104
- )
105
- }
106
- return null
107
- }
108
-
109
- forwardPageLinkItem (match: object, pageNumber: string | number, totalPages: string | number): JSX.Element | null {
110
- if (this.hasForwardPageLink(pageNumber, totalPages)) {
111
- const n = this.lastIndex(pageNumber, totalPages) + 1
112
- return (
113
- <li key={getListItemKey('forward')} className='forward-page'>
114
- <Link to={getLinkTo(match, n)} onClick={() => { this.handlePageNumberSelect(n) }}>
115
- <span className='forward'>
116
- {'\u203A'}
117
- </span>
118
- </Link>
119
- </li>
120
- )
121
- }
122
- return null
123
- }
124
-
125
- zeroPageLinkItem (match: object, pageNumber: string | number, totalPages: string | number): JSX.Element | null {
126
- if (this.hasZeroPageLink(pageNumber, totalPages)) {
127
- const n = 1
128
- return (
129
- <li key={getListItemKey(n)} className='zero-page'>
130
- <Link to={getLinkTo(match, n)} onClick={() => { this.handlePageNumberSelect(n) }}>
131
- <span className='page-number'>
132
- {n}
133
- </span>
134
- </Link>
135
- </li>
136
- )
137
- }
138
- return null
139
- }
140
-
141
- lastPageLinkItem (match: object, pageNumber: string | number, totalPages: string | number): JSX.Element | null {
142
- if (this.hasLastPageLink(pageNumber, totalPages)) {
143
- const n = toInteger(totalPages)
144
- return (
145
- <li key={getListItemKey(n)} className='last-page'>
146
- <Link to={getLinkTo(match, n)} onClick={() => { this.handlePageNumberSelect(n) }}>
147
- <span className='page-number'>
148
- {n}
149
- </span>
150
- </Link>
151
- </li>
152
- )
153
- }
154
- return null
155
- }
156
-
157
- pageLinkItems (match: object, pageNumber: string | number, totalPages: string | number): JSX.Element[] {
158
- let i = this.zeroIndex(pageNumber, totalPages)
159
- const j = this.lastIndex(pageNumber, totalPages)
160
- const a = []
161
- for (j; i < j; i = i + 1) {
162
- const n = (i + 1)
163
- a.push((
164
- <li key={getListItemKey(n)} className={getListItemClassName(pageNumber, n)}>
165
- <Link to={getLinkTo(match, n)} onClick={() => { this.handlePageNumberSelect(n) }}>
166
- <span className='page-number'>
167
- {n}
168
- </span>
169
- </Link>
170
- </li>
171
- ))
172
- }
173
- return a
174
- }
175
-
176
- static getDerivedStateFromProps ({ pageNumber, totalPages }: AbstractPaginationProps): AbstractPaginationState {
177
- return {
178
- pageNumber: toInteger(pageNumber),
179
- totalPages: toInteger(totalPages)
180
- }
181
- }
182
-
183
- shouldComponentUpdate (props: AbstractPaginationProps): boolean {
184
- return (
185
- toInteger(props.pageNumber) !== toInteger(this.props.pageNumber) ||
186
- toInteger(props.totalPages) !== toInteger(this.props.totalPages) ||
187
- props.match !== this.props.match
188
- )
189
- }
190
-
191
- handlePageNumberSelect = (pageNumber: number): void => {
192
- this.props.onClick(pageNumber)
193
- }
194
-
195
- render (): JSX.Element | null {
196
- const { totalPages } = this.state
197
- if (totalPages > 1) {
198
- const { match } = this.props
199
- const { pageNumber } = this.state
200
- const page = calculatePageNumber(pageNumber, totalPages)
201
- if (totalPages > this.z()) {
202
- return (
203
- <ul className='pagination'>
204
- {this.zeroPageLinkItem(match, page, totalPages)}
205
- {this.reversePageLinkItem(match, page, totalPages)}
206
- {this.pageLinkItems(match, page, totalPages)}
207
- {this.forwardPageLinkItem(match, page, totalPages)}
208
- {this.lastPageLinkItem(match, page, totalPages)}
209
- </ul>
210
- )
211
- } else {
212
- return (
213
- <ul className='pagination'>
214
- {this.pageLinkItems(match, page, totalPages)}
215
- </ul>
216
- )
217
- }
218
- }
219
- return null
220
- }
221
- }
222
-
223
23
  export class Pagination extends AbstractPagination<AbstractPaginationProps, AbstractPaginationState> {
224
24
  state = {
225
25
  pageNumber: toInteger(this.props.pageNumber),
@@ -1,12 +1,12 @@
1
1
  import debug from 'debug'
2
2
 
3
- import type ReactRouterPaginationTypes from 'react-router-pagination'
3
+ import AbstractPagination from '#pagination/super/pagination/component' // '../../super/pagination/component.tsx'
4
4
 
5
- import AbstractPagination, {
5
+ import {
6
6
  toInteger,
7
7
  calculateTotalPages,
8
8
  calculatePageNumber
9
- } from '#pagination/component'
9
+ } from '#pagination/pagination/component'
10
10
 
11
11
  const error = debug('react-router-pagination/pagination/component')
12
12
 
@@ -0,0 +1,12 @@
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
+ module.exports = require('./component.tsx')
@@ -0,0 +1 @@
1
+ export * from './component.cjs'
@@ -0,0 +1,220 @@
1
+ /**
2
+ * Pagination component
3
+ */
4
+ import type { JSX } from 'react'
5
+ import React, { Component } from 'react'
6
+
7
+ import {
8
+ Link,
9
+ generatePath
10
+ } from 'react-router'
11
+
12
+ import {
13
+ toInteger,
14
+ calculateTotalPages,
15
+ calculatePageNumber
16
+ } from '#pagination/pagination/common'
17
+
18
+ const getListItemClassName = (currentPageNumber: string | number, pageNumber: string | number): string => (
19
+ toInteger(currentPageNumber) === toInteger(pageNumber)
20
+ ? 'current-page'
21
+ : 'page'
22
+ )
23
+
24
+ const getListItemKey = (key: string | number): string => `list-item-${key}`
25
+
26
+ const getLinkTo = ({ path = '/:pageNumber', params = {} } = {}, pageNumber = 0): string => generatePath(path, { ...params, pageNumber })
27
+
28
+ export {
29
+ toInteger,
30
+ calculateTotalPages,
31
+ calculatePageNumber
32
+ }
33
+
34
+ export type AbstractPaginationProps = ReactRouterPaginationTypes.AbstractPaginationProps
35
+
36
+ export type AbstractPaginationState = ReactRouterPaginationTypes.AbstractPaginationState
37
+
38
+ export default abstract class AbstractPagination<P, S> extends Component<P & AbstractPaginationProps, S & AbstractPaginationState> { // eslint-disable-line @typescript-eslint/no-unnecessary-type-parameters -- Base
39
+ static defaultProps = {
40
+ onClick () {},
41
+ pageNumber: 0,
42
+ totalPages: 0,
43
+ match: {}
44
+ }
45
+
46
+ static calculateTotalPages = calculateTotalPages
47
+
48
+ static calculatePageNumber = calculatePageNumber
49
+
50
+ x (): number {
51
+ return 0
52
+ }
53
+
54
+ y (): number {
55
+ return 0
56
+ }
57
+
58
+ z (): number {
59
+ return 0
60
+ }
61
+
62
+ zeroIndex (pageNumber: string | number, totalPages: string | number): number { // eslint-disable-line no-unused-vars -- Base
63
+ return 0
64
+ }
65
+
66
+ lastIndex (pageNumber: string | number, totalPages: string | number): number { // eslint-disable-line no-unused-vars -- Base
67
+ return 0
68
+ }
69
+
70
+ hasReversePageLink (pageNumber: string | number, totalPages: string | number): boolean {
71
+ return (this.zeroIndex(pageNumber, totalPages) - 1) > 0
72
+ }
73
+
74
+ hasForwardPageLink (pageNumber: string | number, totalPages: string | number): boolean {
75
+ const i = Number(pageNumber)
76
+ const j = Number(totalPages)
77
+ return (this.lastIndex(i, j) + 1) < j
78
+ }
79
+
80
+ hasZeroPageLink (pageNumber: string | number, totalPages: string | number): boolean {
81
+ const i = Number(pageNumber)
82
+ const j = Number(totalPages)
83
+ return this.zeroIndex(i, j) > 0
84
+ }
85
+
86
+ hasLastPageLink (pageNumber: string | number, totalPages: string | number): boolean {
87
+ const i = Number(pageNumber)
88
+ const j = Number(totalPages)
89
+ return this.lastIndex(i, j) < j
90
+ }
91
+
92
+ reversePageLinkItem (match: object, pageNumber: string | number, totalPages: string | number): JSX.Element | null {
93
+ if (this.hasReversePageLink(pageNumber, totalPages)) {
94
+ const n = this.zeroIndex(pageNumber, totalPages)
95
+ return (
96
+ <li key={getListItemKey('reverse')} className='reverse-page'>
97
+ <Link to={getLinkTo(match, n)} onClick={() => { this.handlePageNumberSelect(n) }}>
98
+ <span className='reverse'>
99
+ {'\u2039'}
100
+ </span>
101
+ </Link>
102
+ </li>
103
+ )
104
+ }
105
+ return null
106
+ }
107
+
108
+ forwardPageLinkItem (match: object, pageNumber: string | number, totalPages: string | number): JSX.Element | null {
109
+ if (this.hasForwardPageLink(pageNumber, totalPages)) {
110
+ const n = this.lastIndex(pageNumber, totalPages) + 1
111
+ return (
112
+ <li key={getListItemKey('forward')} className='forward-page'>
113
+ <Link to={getLinkTo(match, n)} onClick={() => { this.handlePageNumberSelect(n) }}>
114
+ <span className='forward'>
115
+ {'\u203A'}
116
+ </span>
117
+ </Link>
118
+ </li>
119
+ )
120
+ }
121
+ return null
122
+ }
123
+
124
+ zeroPageLinkItem (match: object, pageNumber: string | number, totalPages: string | number): JSX.Element | null {
125
+ if (this.hasZeroPageLink(pageNumber, totalPages)) {
126
+ const n = 1
127
+ return (
128
+ <li key={getListItemKey(n)} className='zero-page'>
129
+ <Link to={getLinkTo(match, n)} onClick={() => { this.handlePageNumberSelect(n) }}>
130
+ <span className='page-number'>
131
+ {n}
132
+ </span>
133
+ </Link>
134
+ </li>
135
+ )
136
+ }
137
+ return null
138
+ }
139
+
140
+ lastPageLinkItem (match: object, pageNumber: string | number, totalPages: string | number): JSX.Element | null {
141
+ if (this.hasLastPageLink(pageNumber, totalPages)) {
142
+ const n = toInteger(totalPages)
143
+ return (
144
+ <li key={getListItemKey(n)} className='last-page'>
145
+ <Link to={getLinkTo(match, n)} onClick={() => { this.handlePageNumberSelect(n) }}>
146
+ <span className='page-number'>
147
+ {n}
148
+ </span>
149
+ </Link>
150
+ </li>
151
+ )
152
+ }
153
+ return null
154
+ }
155
+
156
+ pageLinkItems (match: object, pageNumber: string | number, totalPages: string | number): JSX.Element[] {
157
+ let i = this.zeroIndex(pageNumber, totalPages)
158
+ const j = this.lastIndex(pageNumber, totalPages)
159
+ const a = []
160
+ for (j; i < j; i = i + 1) {
161
+ const n = (i + 1)
162
+ a.push((
163
+ <li key={getListItemKey(n)} className={getListItemClassName(pageNumber, n)}>
164
+ <Link to={getLinkTo(match, n)} onClick={() => { this.handlePageNumberSelect(n) }}>
165
+ <span className='page-number'>
166
+ {n}
167
+ </span>
168
+ </Link>
169
+ </li>
170
+ ))
171
+ }
172
+ return a
173
+ }
174
+
175
+ static getDerivedStateFromProps ({ pageNumber, totalPages }: AbstractPaginationProps): AbstractPaginationState {
176
+ return {
177
+ pageNumber: toInteger(pageNumber),
178
+ totalPages: toInteger(totalPages)
179
+ }
180
+ }
181
+
182
+ shouldComponentUpdate (props: AbstractPaginationProps): boolean {
183
+ return (
184
+ toInteger(props.pageNumber) !== toInteger(this.props.pageNumber) ||
185
+ toInteger(props.totalPages) !== toInteger(this.props.totalPages) ||
186
+ props.match !== this.props.match
187
+ )
188
+ }
189
+
190
+ handlePageNumberSelect = (pageNumber: number): void => {
191
+ this.props.onClick(pageNumber)
192
+ }
193
+
194
+ render (): JSX.Element | null {
195
+ const { totalPages } = this.state
196
+ if (totalPages > 1) {
197
+ const { match } = this.props
198
+ const { pageNumber } = this.state
199
+ const page = calculatePageNumber(pageNumber, totalPages)
200
+ if (totalPages > this.z()) {
201
+ return (
202
+ <ul className='pagination'>
203
+ {this.zeroPageLinkItem(match, page, totalPages)}
204
+ {this.reversePageLinkItem(match, page, totalPages)}
205
+ {this.pageLinkItems(match, page, totalPages)}
206
+ {this.forwardPageLinkItem(match, page, totalPages)}
207
+ {this.lastPageLinkItem(match, page, totalPages)}
208
+ </ul>
209
+ )
210
+ } else {
211
+ return (
212
+ <ul className='pagination'>
213
+ {this.pageLinkItems(match, page, totalPages)}
214
+ </ul>
215
+ )
216
+ }
217
+ }
218
+ return null
219
+ }
220
+ }
package/src/.babelrc DELETED
@@ -1,27 +0,0 @@
1
- {
2
- "presets": [
3
- "@babel/typescript",
4
- [
5
- "@babel/env",
6
- {
7
- "targets": {
8
- "node": "current",
9
- "browsers": [
10
- "last 4 versions",
11
- "safari >= 9",
12
- "ios >= 8",
13
- "ie >= 9",
14
- "> 2%"
15
- ]
16
- },
17
- "useBuiltIns": "usage",
18
- "corejs": 3
19
- }
20
- ],
21
- "@babel/react"
22
- ],
23
- "plugins": [
24
- "@babel/syntax-jsx",
25
- "@babel/transform-typescript"
26
- ]
27
- }