11'use strict'
22
3- import React from 'react'
3+ import { Component , PropTypes } from 'react'
44import classnames from 'classnames'
55import { forEach } from './utils/objects'
66
77import { requireCss } from './themes'
88requireCss ( 'pagination' )
99
10- export default class Pagination extends React . Component {
10+ export default class Pagination extends Component {
1111 static displayName = 'Pagination'
1212
1313 static propTypes = {
14- className : React . PropTypes . string ,
15- index : React . PropTypes . number ,
16- jumper : React . PropTypes . bool ,
17- onChange : React . PropTypes . func ,
18- pages : React . PropTypes . number ,
19- size : React . PropTypes . number ,
20- style : React . PropTypes . object ,
21- total : React . PropTypes . number
14+ className : PropTypes . string ,
15+ index : PropTypes . number ,
16+ jumper : PropTypes . bool ,
17+ mini : PropTypes . bool ,
18+ onChange : PropTypes . func ,
19+ pages : PropTypes . number ,
20+ size : PropTypes . number ,
21+ style : PropTypes . object ,
22+ total : PropTypes . number
2223 }
2324
2425 static defaultProps = {
@@ -52,7 +53,11 @@ export default class Pagination extends React.Component {
5253
5354 let value = this . refs . input . value
5455 value = parseInt ( value )
55- if ( ! value ) {
56+ if ( isNaN ( value ) ) {
57+ return
58+ }
59+ if ( value < 1 ) {
60+ this . handleChange ( 1 )
5661 return
5762 }
5863
@@ -64,6 +69,9 @@ export default class Pagination extends React.Component {
6469
6570 handleChange ( index ) {
6671 this . setIndex ( index )
72+ if ( this . refs . input ) {
73+ this . refs . input . value = index
74+ }
6775 if ( this . props . onChange ) {
6876 this . props . onChange ( index )
6977 }
@@ -115,6 +123,7 @@ export default class Pagination extends React.Component {
115123
116124 render ( ) {
117125 let index = this . state . index ,
126+ { mini} = this . props ,
118127 { pages, max} = this . getPages ( ) ,
119128 items = [ ]
120129
@@ -125,13 +134,22 @@ export default class Pagination extends React.Component {
125134 </ li >
126135 )
127136
128- forEach ( pages , function ( i ) {
137+ if ( mini ) {
129138 items . push (
130- < li onClick = { this . handleChange . bind ( this , i ) } className = { classnames ( { active : i === index } ) } key = { i } >
131- < a > { i } </ a >
132- </ li >
139+ < form key = "i" onSubmit = { this . setInput . bind ( this ) } >
140+ < input ref = "input" defaultValue = { this . state . index } type = "text" className = "rct-form-control" / >
141+ </ form >
133142 )
134- } , this )
143+ items . push ( < span key = "s" > / { max } </ span > )
144+ } else {
145+ forEach ( pages , function ( i ) {
146+ items . push (
147+ < li onClick = { this . handleChange . bind ( this , i ) } className = { classnames ( { active : i === index } ) } key = { i } >
148+ < a > { i } </ a >
149+ </ li >
150+ )
151+ } , this )
152+ }
135153
136154 // Next
137155 items . push (
@@ -142,18 +160,19 @@ export default class Pagination extends React.Component {
142160
143161 let className = classnames (
144162 this . props . className ,
145- "rct-pagination-wrap"
163+ "rct-pagination-wrap" ,
164+ { "rct-pagination-mini" : mini }
146165 )
147166 return (
148167 < div style = { this . props . style } className = { className } >
149168 < ul className = "rct-pagination" >
150169 { items }
151170 </ ul >
152171 {
153- this . props . jumper &&
172+ this . props . jumper && ! mini &&
154173 < form onSubmit = { this . setInput . bind ( this ) } >
155174 < div className = "rct-input-group" >
156- < input ref = "input" type = "text" className = "rct-form-control" />
175+ < input ref = "input" defaultValue = { this . state . index } type = "text" className = "rct-form-control" />
157176 < span onClick = { this . setInput . bind ( this ) } className = "addon" > go</ span >
158177 </ div >
159178 </ form >
0 commit comments