1
1
import React , { Component } from 'react'
2
2
import './style.css' ;
3
-
3
+ import ReactButton from './button' ;
4
4
5
5
export default class ReactPagination extends Component {
6
6
limit = 20 ;
@@ -20,6 +20,8 @@ export default class ReactPagination extends Component {
20
20
third : [ ]
21
21
}
22
22
} ;
23
+ this . selectPage = this . selectPage . bind ( this ) ;
24
+
23
25
}
24
26
componentDidMount ( ) {
25
27
this . limit = this . props . limit ;
@@ -118,6 +120,7 @@ export default class ReactPagination extends Component {
118
120
}
119
121
this . setState ( state ) ;
120
122
}
123
+
121
124
selectPage ( page ) {
122
125
this . props . returnSelectedPage ( page ) ;
123
126
let state = this . state ;
@@ -131,73 +134,25 @@ export default class ReactPagination extends Component {
131
134
this . setState ( state ) ;
132
135
}
133
136
goPrev ( ) {
134
- if ( this . current > 0 ) {
137
+ if ( this . state . current > 0 ) {
135
138
this . selectPage ( this . state . current - 1 ) ;
136
139
}
137
140
}
138
141
139
142
goNext ( ) {
140
- this . selectPage ( this . state . current + 1 ) ;
143
+
144
+ if ( this . pageCount > this . state . current ) {
145
+ this . selectPage ( this . state . current + 1 ) ;
146
+ }
141
147
}
142
- onClick ( event , n ) {
143
- this . selectPage ( n ) ;
144
- func2 ( ) ;
145
- }
148
+
146
149
render ( ) {
147
150
148
- let activeButtonColor = '#ccc'
149
- let buttonColor = '#fff' ;
151
+ let activeButtonColor = '#ccc'
152
+ let buttonColor = '#fff' ;
150
153
151
- let first = this . state . pagination . first . map ( ( n , i ) => {
152
- let btnStyle = { backgroundColor :buttonColor } ;
153
- if ( this . state . current === n ) {
154
- btnStyle . backgroundColor = activeButtonColor
155
- }
156
154
157
- return (
158
- < li
159
- key = { i }
160
- onClick = { ( ) => this . selectPage ( n ) }
161
- style = { btnStyle }
162
- >
163
- < a > { n } </ a >
164
- </ li >
165
- )
166
- } )
167
- let second = this . state . pagination . second . map ( ( n , i ) => {
168
-
169
- let btnStyle = { backgroundColor :buttonColor } ;
170
- if ( this . state . current === n ) {
171
- btnStyle . backgroundColor = activeButtonColor
172
- }
173
-
174
- return (
175
- < li
176
- key = { i }
177
- onClick = { ( ) => this . selectPage ( n ) }
178
- style = { btnStyle }
179
- >
180
- < a > { n } </ a >
181
- </ li >
182
- )
183
- } )
184
- let third = this . state . pagination . third . map ( ( n , i ) => {
185
-
186
- let btnStyle = { backgroundColor :buttonColor } ;
187
- if ( this . state . current === n ) {
188
- btnStyle . backgroundColor = activeButtonColor
189
- }
190
155
191
- return (
192
- < li
193
- key = { i }
194
- onClick = { ( ) => this . selectPage ( n ) }
195
- style = { btnStyle }
196
- >
197
- < a > { n } </ a >
198
- </ li >
199
- )
200
- } )
201
156
return (
202
157
< div >
203
158
< div style = { { 'display' : this . state . show ? 'block' : 'none' } } >
@@ -210,13 +165,17 @@ export default class ReactPagination extends Component {
210
165
211
166
< li
212
167
style = { { 'display' : this . state . current > 1 ? 'block' : 'none' } }
213
- onClick = { this . goPrev }
168
+ onClick = { this . goPrev . bind ( this ) }
214
169
className = "prev"
215
170
>
216
171
< a > Prev</ a >
217
172
</ li >
218
173
219
- { first }
174
+ < ReactButton
175
+ selectPage = { this . selectPage }
176
+ section = "first"
177
+ current = { this . state . current }
178
+ pagination = { this . state . pagination } />
220
179
221
180
< li
222
181
style = { { 'display' : this . state . pagination . second . length > 0 ? 'block' : 'none' } }
@@ -225,7 +184,11 @@ export default class ReactPagination extends Component {
225
184
< a > ...</ a >
226
185
</ li >
227
186
228
- { second }
187
+ < ReactButton
188
+ selectPage = { this . selectPage }
189
+ section = "second"
190
+ current = { this . state . current }
191
+ pagination = { this . state . pagination } />
229
192
230
193
< li
231
194
style = { { 'display' : this . state . pagination . third . length > 0 ? 'block' : 'none' } }
@@ -234,11 +197,15 @@ export default class ReactPagination extends Component {
234
197
< a > ...</ a >
235
198
</ li >
236
199
237
- { third }
200
+ < ReactButton
201
+ selectPage = { this . selectPage }
202
+ section = "third"
203
+ current = { this . state . current }
204
+ pagination = { this . state . pagination } />
238
205
239
206
< li
240
207
style = { { 'display' : this . state . next != 0 ? 'block' : 'none' } }
241
- onClick = { this . goNext }
208
+ onClick = { this . goNext . bind ( this ) }
242
209
className = "next"
243
210
>
244
211
< span > Next</ span >
0 commit comments