@@ -36,34 +36,38 @@ class Pagination extends Component {
36
36
37
37
const steps = [ ] ;
38
38
39
- // eslint-disable-next-line no-restricted-syntax
40
- for ( const key of Array ( 3 ) . keys ( ) ) {
41
- let page ;
42
-
43
- if ( currentActive > 2 ) {
44
- if ( currentActive >= total - 1 ) {
45
- page = ( key - 3 ) + total ;
39
+ if ( total >= 3 ) {
40
+ const innerSteps = total > 5 ? 3 : ( total - 2 ) ; // FIX THIS for 3,4 pages
41
+ // eslint-disable-next-line no-restricted-syntax
42
+ for ( const key of Array ( innerSteps ) . keys ( ) ) {
43
+ let page ;
44
+
45
+ if ( currentActive > 2 ) {
46
+ if ( ( currentActive >= total - 1 ) && total > 4 ) {
47
+ page = ( key - 3 ) + total ;
48
+ } else if ( total === 4 && currentActive === 4 ) {
49
+ page = currentActive + ( key - 2 ) ;
50
+ } else {
51
+ page = currentActive + ( key - 1 ) ;
52
+ }
46
53
} else {
47
- page = currentActive + ( key - 1 ) ;
54
+ page = key + 2 ;
48
55
}
49
- } else {
50
- page = key + 2 ;
56
+ /* eslint-disable jsx-a11y/click-events-have-key-events */
57
+ /* eslint-disable jsx-a11y/no-static-element-interactions */
58
+ steps . push ( < div
59
+ className = { classnames ( theme [ 'pagination-steps' ] , {
60
+ [ theme . active ] : page === currentActive ,
61
+ } ) }
62
+ data-react-active-page = { page === currentActive ? 'active' : undefined }
63
+ key = { page }
64
+ onClick = { ( ) => this . navigate ( page ) }
65
+ >
66
+ { page }
67
+ { /* eslint-disable-next-line react/jsx-closing-tag-location */ }
68
+ </ div > ) ;
51
69
}
52
- /* eslint-disable jsx-a11y/click-events-have-key-events */
53
- /* eslint-disable jsx-a11y/no-static-element-interactions */
54
- steps . push ( < div
55
- className = { classnames ( theme [ 'pagination-steps' ] , {
56
- [ theme . active ] : page === currentActive ,
57
- } ) }
58
- data-react-active-page = { page === currentActive ? 'active' : undefined }
59
- key = { page }
60
- onClick = { ( ) => this . navigate ( page ) }
61
- >
62
- { page }
63
- { /* eslint-disable-next-line react/jsx-closing-tag-location */ }
64
- </ div > ) ;
65
70
}
66
-
67
71
return [
68
72
< div
69
73
className = { classnames ( theme [ 'pagination-steps' ] , {
@@ -75,19 +79,21 @@ class Pagination extends Component {
75
79
>
76
80
{ 1 }
77
81
</ div > ,
78
- currentActive > 2 ? this . renderDots ( 'left' ) : null ,
79
- steps ,
80
- currentActive < total - 1 ? this . renderDots ( 'right' ) : null ,
81
- < div
82
- className = { classnames ( theme [ 'pagination-steps' ] , {
83
- [ theme . active ] : total === currentActive ,
84
- } ) }
85
- key = { total }
86
- data-react-active-page = { total === currentActive ? 'active' : undefined }
87
- onClick = { ( ) => this . navigate ( total ) }
88
- >
89
- { total }
90
- </ div > ,
82
+ total > 5 && currentActive > 2 ? this . renderDots ( 'left' ) : null ,
83
+ total >= 3 && steps ,
84
+ total > 5 && currentActive < total - 1 ? this . renderDots ( 'right' ) : null ,
85
+ total >= 2 && (
86
+ < div
87
+ className = { classnames ( theme [ 'pagination-steps' ] , {
88
+ [ theme . active ] : total === currentActive ,
89
+ } ) }
90
+ key = { total }
91
+ data-react-active-page = { total === currentActive ? 'active' : undefined }
92
+ onClick = { ( ) => this . navigate ( total ) }
93
+ >
94
+ { total }
95
+ </ div >
96
+ ) ,
91
97
] ;
92
98
} ;
93
99
0 commit comments