@@ -9,119 +9,116 @@ import {
9
9
import PaginationLink from "./PaginationLink"
10
10
import { mediaQueries } from "gatsby-design-tokens/dist/theme-gatsbyjs-org"
11
11
12
- class Pagination extends React . Component {
13
- changePage = e => {
14
- navigate ( e . target . value ? `/blog/page/${ e . target . value } ` : `/blog/` )
15
- }
16
- render ( ) {
17
- const { numPages, currentPage } = this . props . context
18
- const isFirst = currentPage === 1
19
- const isLast = currentPage === numPages
20
- const prevPageNum =
21
- currentPage - 1 === 1 ? `` : `page/${ ( currentPage - 1 ) . toString ( ) } `
22
- const nextPageNum = ( currentPage + 1 ) . toString ( )
23
- const prevPageLink = isFirst ? null : `/blog/${ prevPageNum } `
24
- const nextPageLink = isLast ? null : `/blog/page/${ nextPageNum } `
12
+ function changePage ( e ) {
13
+ navigate ( e . target . value ? `/blog/page/${ e . target . value } ` : `/blog/` )
14
+ }
25
15
26
- const prevNextLinkStyles = {
27
- "&&" : {
28
- borderBottom : 0 ,
29
- color : `gatsby` ,
30
- } ,
31
- }
16
+ export default function Pagination ( { context } ) {
17
+ const { numPages, currentPage } = context
18
+ const isFirst = currentPage === 1
19
+ const isLast = currentPage === numPages
20
+ const prevPageNum =
21
+ currentPage - 1 === 1 ? `` : `page/${ ( currentPage - 1 ) . toString ( ) } `
22
+ const nextPageNum = ( currentPage + 1 ) . toString ( )
23
+ const prevPageLink = isFirst ? null : `/blog/${ prevPageNum } `
24
+ const nextPageLink = isLast ? null : `/blog/page/${ nextPageNum } `
25
+
26
+ const prevNextLinkStyles = {
27
+ "&&" : {
28
+ borderBottom : 0 ,
29
+ color : `gatsby` ,
30
+ } ,
31
+ }
32
32
33
- return (
33
+ return (
34
+ < div
35
+ sx = { {
36
+ display : `flex` ,
37
+ justifyContent : `space-between` ,
38
+ mx : - 6 ,
39
+ p : 6 ,
40
+ flexDirection : `column` ,
41
+ fontSize : 1 ,
42
+ [ mediaQueries . md ] : {
43
+ background : `transparent` ,
44
+ borderTop : 0 ,
45
+ marginBottom : 0 ,
46
+ paddingTop : 0 ,
47
+ flexDirection : `row` ,
48
+ } ,
49
+ } }
50
+ >
34
51
< div
35
52
sx = { {
36
53
display : `flex` ,
54
+ margin : `0` ,
55
+ padding : `0` ,
37
56
justifyContent : `space-between` ,
38
- mx : - 6 ,
39
- p : 6 ,
40
- flexDirection : `column` ,
41
- fontSize : 1 ,
57
+ alignItems : `center` ,
58
+ mb : 3 ,
42
59
[ mediaQueries . md ] : {
43
- background : `transparent` ,
44
- borderTop : 0 ,
45
- marginBottom : 0 ,
46
- paddingTop : 0 ,
47
- flexDirection : `row` ,
60
+ width : `15rem` ,
61
+ mb : 0 ,
48
62
} ,
49
63
} }
50
64
>
51
- < div
65
+ < PaginationLink to = { prevPageLink } sx = { prevNextLinkStyles } >
66
+ < ArrowBackIcon />
67
+ Newer posts
68
+ </ PaginationLink >
69
+ < PaginationLink to = { nextPageLink } sx = { prevNextLinkStyles } >
70
+ Older posts
71
+ < ArrowForwardIcon />
72
+ </ PaginationLink >
73
+ </ div >
74
+ < div
75
+ sx = { {
76
+ display : `flex` ,
77
+ alignItems : `center` ,
78
+ justifyContent : `flex-end` ,
79
+ fontSize : 1 ,
80
+ } }
81
+ >
82
+ < span > Showing page </ span >
83
+ < select
84
+ aria-label = "Pagination Dropdown"
85
+ value = { currentPage === 1 ? `` : currentPage . toString ( ) }
86
+ onChange = { changePage }
52
87
sx = { {
53
- display : `flex` ,
54
- margin : `0` ,
55
- padding : `0` ,
56
- justifyContent : `space-between` ,
57
- alignItems : `center` ,
58
- mb : 3 ,
59
- [ mediaQueries . md ] : {
60
- width : `15rem` ,
61
- mb : 0 ,
62
- } ,
88
+ appearance : `none` ,
89
+ border : `none` ,
90
+ padding : `0.5ch 2ch 0.5ch 0.5ch` ,
91
+ color : `gatsby` ,
92
+ fontWeight : `bold` ,
63
93
} }
64
94
>
65
- < PaginationLink to = { prevPageLink } sx = { prevNextLinkStyles } >
66
- < ArrowBackIcon />
67
- Newer posts
68
- </ PaginationLink >
69
- < PaginationLink to = { nextPageLink } sx = { prevNextLinkStyles } >
70
- Older posts
71
- < ArrowForwardIcon />
72
- </ PaginationLink >
73
- </ div >
74
- < div
95
+ { Array . from ( { length : numPages } , ( _ , i ) => (
96
+ < option
97
+ value = { `${ i === 0 ? `` : i + 1 } ` }
98
+ key = { `pagination-number${ i + 1 } ` }
99
+ aria-label = { `Goto Page ${ i + 1 } ` }
100
+ aria-current = { currentPage === i + 1 }
101
+ >
102
+ { i + 1 }
103
+ </ option >
104
+ ) ) }
105
+ </ select >
106
+ < svg
107
+ width = "10"
108
+ height = "5"
109
+ viewBox = "0 0 10 5"
75
110
sx = { {
76
- display : `flex ` ,
77
- alignItems : `center` ,
78
- justifyContent : `flex-end ` ,
79
- fontSize : 1 ,
111
+ position : `relative ` ,
112
+ right : 4 ,
113
+ fill : `gatsby ` ,
114
+ pointerEvents : `none` ,
80
115
} }
81
116
>
82
- < span > Showing page </ span >
83
- < select
84
- aria-label = "Pagination Dropdown"
85
- value = { currentPage === 1 ? `` : currentPage . toString ( ) }
86
- onChange = { this . changePage }
87
- sx = { {
88
- appearance : `none` ,
89
- border : `none` ,
90
- padding : `0.5ch 2ch 0.5ch 0.5ch` ,
91
- color : `gatsby` ,
92
- fontWeight : `bold` ,
93
- } }
94
- >
95
- { Array . from ( { length : numPages } , ( _ , i ) => (
96
- < option
97
- value = { `${ i === 0 ? `` : i + 1 } ` }
98
- key = { `pagination-number${ i + 1 } ` }
99
- aria-label = { `Goto Page ${ i + 1 } ` }
100
- aria-current = { currentPage === i + 1 }
101
- >
102
- { i + 1 }
103
- </ option >
104
- ) ) }
105
- </ select >
106
- < svg
107
- width = "10"
108
- height = "5"
109
- viewBox = "0 0 10 5"
110
- sx = { {
111
- position : `relative` ,
112
- right : 4 ,
113
- fill : `gatsby` ,
114
- pointerEvents : `none` ,
115
- } }
116
- >
117
- < path d = "M0 0l5 4.998L10 0z" fillRule = "evenodd" />
118
- </ svg >
119
- < span > of </ span >
120
- < span > { numPages } </ span >
121
- </ div >
117
+ < path d = "M0 0l5 4.998L10 0z" fillRule = "evenodd" />
118
+ </ svg >
119
+ < span > of </ span >
120
+ < span > { numPages } </ span >
122
121
</ div >
123
- )
124
- }
122
+ </ div >
123
+ )
125
124
}
126
-
127
- export default Pagination
0 commit comments