22import React from 'react' ;
33import KEYCODE from './KeyCode' ;
44
5- class Options extends React . Component {
5+ interface Props {
6+ disabled : boolean ;
7+ locale : any ;
8+ rootPrefixCls : string ;
9+ selectPrefixCls : string ;
10+ current : number ;
11+ pageSize : number ;
12+ pageSizeOptions : ( string | number ) [ ] ;
13+ goButton : boolean | string ;
14+ changeSize : ( size : number ) => void ;
15+ quickGo : ( value : number ) => void ;
16+ buildOptionText ?: ( value : string | number ) => string ;
17+ selectComponentClass : React . ComponentType < any > & {
18+ Option ?: React . ComponentType < any > ;
19+ } ;
20+ }
21+
22+ interface State {
23+ goInputText : string ;
24+ }
25+
26+ class Options extends React . Component < Props , State > {
627 static defaultProps = {
728 pageSizeOptions : [ '10' , '20' , '50' , '100' ] ,
829 } ;
@@ -11,33 +32,32 @@ class Options extends React.Component {
1132 goInputText : '' ,
1233 } ;
1334
14- getValidValue ( ) {
35+ getValidValue = ( ) => {
1536 const { goInputText } = this . state ;
1637 // eslint-disable-next-line no-restricted-globals
17- return ! goInputText || isNaN ( goInputText ) ? undefined : Number ( goInputText ) ;
18- }
38+ return ! goInputText || Number . isNaN ( goInputText )
39+ ? undefined
40+ : Number ( goInputText ) ;
41+ } ;
1942
20- buildOptionText = ( value ) => `${ value } ${ this . props . locale . items_per_page } ` ;
43+ buildOptionText = ( value : string ) =>
44+ `${ value } ${ this . props . locale . items_per_page } ` ;
2145
22- changeSize = ( value ) => {
46+ changeSize = ( value : number ) => {
2347 this . props . changeSize ( Number ( value ) ) ;
2448 } ;
2549
26- handleChange = ( e ) => {
27- this . setState ( {
28- goInputText : e . target . value ,
29- } ) ;
50+ handleChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
51+ this . setState ( { goInputText : e . target . value } ) ;
3052 } ;
3153
32- handleBlur = ( e ) => {
54+ handleBlur = ( e : React . FocusEvent < HTMLInputElement , Element > ) => {
3355 const { goButton, quickGo, rootPrefixCls } = this . props ;
3456 const { goInputText } = this . state ;
3557 if ( goButton || goInputText === '' ) {
3658 return ;
3759 }
38- this . setState ( {
39- goInputText : '' ,
40- } ) ;
60+ this . setState ( { goInputText : '' } ) ;
4161 if (
4262 e . relatedTarget &&
4363 ( e . relatedTarget . className . indexOf ( `${ rootPrefixCls } -item-link` ) >= 0 ||
@@ -48,15 +68,13 @@ class Options extends React.Component {
4868 quickGo ( this . getValidValue ( ) ) ;
4969 } ;
5070
51- go = ( e ) => {
71+ go = ( e : any ) => {
5272 const { goInputText } = this . state ;
5373 if ( goInputText === '' ) {
5474 return ;
5575 }
5676 if ( e . keyCode === KEYCODE . ENTER || e . type === 'click' ) {
57- this . setState ( {
58- goInputText : '' ,
59- } ) ;
77+ this . setState ( { goInputText : '' } ) ;
6078 this . props . quickGo ( this . getValidValue ( ) ) ;
6179 }
6280 } ;
@@ -72,9 +90,9 @@ class Options extends React.Component {
7290 }
7391 return pageSizeOptions . concat ( [ pageSize . toString ( ) ] ) . sort ( ( a , b ) => {
7492 // eslint-disable-next-line no-restricted-globals
75- const numberA = isNaN ( Number ( a ) ) ? 0 : Number ( a ) ;
93+ const numberA = Number . isNaN ( Number ( a ) ) ? 0 : Number ( a ) ;
7694 // eslint-disable-next-line no-restricted-globals
77- const numberB = isNaN ( Number ( b ) ) ? 0 : Number ( b ) ;
95+ const numberB = Number . isNaN ( Number ( b ) ) ? 0 : Number ( b ) ;
7896 return numberA - numberB ;
7997 } ) ;
8098 }
0 commit comments