This repository was archived by the owner on Apr 25, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +32
-23
lines changed
Expand file tree Collapse file tree 2 files changed +32
-23
lines changed Original file line number Diff line number Diff line change 1111 font-size : 1.2rem ;
1212 align-items : center ;
1313
14+ div ,
1415 a :not (:last-child ) {
1516 & .pageLink {
1617 border-right : 1px solid var (--border );
3334 transition : 0.5s ;
3435 line-height : 42px ;
3536
36- & :hover {
37+ & :hover:not ( .ellipsis ) {
3738 cursor : pointer ;
3839 background-color : var (--main-color );
3940 text-decoration : none ;
Original file line number Diff line number Diff line change @@ -14,31 +14,39 @@ const Pagination: FunctionComponent<Props> = ({ currentPage, pages }) => {
1414 return < > </ >
1515 }
1616
17+
1718 return (
1819 < div className = { styles . pagination } >
19- { pages . map ( ( p , index ) => {
20- const isActive = p === currentPage
21- const className = isActive ? `${ styles . pageActive } ` : ''
20+ { pages
21+ . filter ( page => ( currentPage - 3 < page && currentPage + 3 > page )
22+ || pages [ 0 ] === page
23+ || pages . length === page )
24+ . map ( ( curr , index , array ) => {
25+ const isActive = curr === currentPage
26+ const className = isActive ? `${ styles . pageActive } ` : ''
2227
23- return (
24- < a
25- onClick = { ( ) => {
26- router . push ( {
27- pathname : router . pathname ,
28- query : {
29- ...router . query ,
30- page : p . toString ( ) ,
31- } ,
32- } )
33- } }
34- key = { `pagination-${ index } ` }
35- className = { `${ className } ${ styles . pageLink } ` }
36- >
37- { p }
38- </ a >
39- )
40- } ) }
41- </ div >
28+ return (
29+ < >
30+ { index > 0 && array [ index - 1 ] + 1 !== curr && < div className = { `${ styles . pageLink } ${ styles . ellipsis } ` } > ...</ div > }
31+ < a
32+ onClick = { ( ) => {
33+ router . push ( {
34+ pathname : router . pathname ,
35+ query : {
36+ ...router . query ,
37+ page : curr . toString ( ) ,
38+ } ,
39+ } )
40+ } }
41+ key = { `pagination-${ index } ` }
42+ className = { `${ className } ${ styles . pageLink } ` }
43+ >
44+ { curr }
45+ </ a >
46+ </ >
47+ )
48+ } ) }
49+ </ div >
4250 )
4351}
4452export default Pagination
You can’t perform that action at this time.
0 commit comments