@@ -66,33 +66,39 @@ export default function usePagination(props = {}) {
6666 count - boundaryCount - 1 ,
6767 ) ;
6868
69+ // Start ellipsis
70+ const startEllipsis = [ ] ;
71+ if ( siblingsStart > boundaryCount + 2 ) {
72+ startEllipsis . push ( 'start-ellipsis' ) ;
73+ } else if ( boundaryCount + 1 < count - boundaryCount ) {
74+ startEllipsis . push ( boundaryCount + 1 ) ;
75+ }
76+
77+ // End ellipsis
78+ const endEllipsis = [ ] ;
79+ if ( siblingsEnd < count - boundaryCount - 1 ) {
80+ endEllipsis . push ( 'end-ellipsis' ) ;
81+ } else if ( count - boundaryCount > boundaryCount ) {
82+ endEllipsis . push ( count - boundaryCount ) ;
83+ }
84+
85+ const body =
86+ boundaryCount === 0 && siblingCount === 0
87+ ? [ page ]
88+ : [
89+ ...startPages ,
90+ ...startEllipsis ,
91+ ...range ( siblingsStart , siblingsEnd ) ,
92+ ...endEllipsis ,
93+ ...endPages ,
94+ ] ;
95+
6996 // Basic list of items to render
7097 // for example itemList = ['first', 'previous', 1, 'ellipsis', 4, 5, 6, 'ellipsis', 10, 'next', 'last']
7198 const itemList = [
7299 ...( showFirstButton ? [ 'first' ] : [ ] ) ,
73100 ...( hidePrevButton ? [ ] : [ 'previous' ] ) ,
74- ...startPages ,
75-
76- // Start ellipsis
77- // eslint-disable-next-line no-nested-ternary
78- ...( siblingsStart > boundaryCount + 2
79- ? [ 'start-ellipsis' ]
80- : boundaryCount + 1 < count - boundaryCount
81- ? [ boundaryCount + 1 ]
82- : [ ] ) ,
83-
84- // Sibling pages
85- ...range ( siblingsStart , siblingsEnd ) ,
86-
87- // End ellipsis
88- // eslint-disable-next-line no-nested-ternary
89- ...( siblingsEnd < count - boundaryCount - 1
90- ? [ 'end-ellipsis' ]
91- : count - boundaryCount > boundaryCount
92- ? [ count - boundaryCount ]
93- : [ ] ) ,
94-
95- ...endPages ,
101+ ...body ,
96102 ...( hideNextButton ? [ ] : [ 'next' ] ) ,
97103 ...( showLastButton ? [ 'last' ] : [ ] ) ,
98104 ] ;
0 commit comments