@@ -2,7 +2,7 @@ import type { SelectProps } from 'rc-select';
22import type { OptionProps } from 'rc-select/es/Option' ;
33import KEYCODE from 'rc-util/lib/KeyCode' ;
44import React from 'react' ;
5- import type { PaginationLocale } from './interface' ;
5+ import type { PaginationLocale , PaginationPageSizeChanger } from './interface' ;
66
77interface InternalSelectProps extends SelectProps {
88 /**
@@ -11,16 +11,15 @@ interface InternalSelectProps extends SelectProps {
1111 popupMatchSelectWidth ?: boolean ;
1212}
1313
14- interface OptionsProps {
14+ interface OptionsProps
15+ extends Partial < Pick < PaginationPageSizeChanger , 'options' | 'showSearch' > > {
1516 disabled ?: boolean ;
1617 locale : PaginationLocale ;
1718 rootPrefixCls : string ;
1819 selectPrefixCls ?: string ;
1920 pageSize : number ;
20- pageSizeOptions ?: ( string | number ) [ ] ;
21- showSearch ?: boolean ;
2221 goButton ?: boolean | string ;
23- changeSize ?: ( size : number ) => void ;
22+ onChange ?: ( size : number ) => void ;
2423 quickGo ?: ( value : number ) => void ;
2524 buildOptionText ?: ( value : string | number ) => string ;
2625 selectComponentClass : React . ComponentType < Partial < InternalSelectProps > > & {
@@ -32,18 +31,18 @@ const defaultPageSizeOptions = ['10', '20', '50', '100'];
3231
3332const Options : React . FC < OptionsProps > = ( props ) => {
3433 const {
35- pageSizeOptions = defaultPageSizeOptions ,
3634 locale,
37- changeSize,
3835 pageSize,
3936 goButton,
4037 quickGo,
4138 rootPrefixCls,
4239 selectComponentClass : Select ,
43- showSearch,
4440 selectPrefixCls,
4541 disabled,
4642 buildOptionText,
43+ options = defaultPageSizeOptions ,
44+ onChange,
45+ showSearch,
4746 } = props ;
4847
4948 const [ goInputText , setGoInputText ] = React . useState ( '' ) ;
@@ -59,8 +58,8 @@ const Options: React.FC<OptionsProps> = (props) => {
5958 ? buildOptionText
6059 : ( value : string ) => `${ value } ${ locale . items_per_page } ` ;
6160
62- const changeSizeHandle = ( value : number ) => {
63- changeSize ?.( Number ( value ) ) ;
61+ const handleChangeSize = ( value : number ) => {
62+ onChange ?.( Number ( value ) ) ;
6463 } ;
6564
6665 const handleChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
@@ -94,13 +93,13 @@ const Options: React.FC<OptionsProps> = (props) => {
9493
9594 const getPageSizeOptions = ( ) => {
9695 if (
97- pageSizeOptions . some (
98- ( option ) => option . toString ( ) === pageSize . toString ( ) ,
96+ options . some (
97+ ( option : unknown ) => option . toString ( ) === pageSize . toString ( ) ,
9998 )
10099 ) {
101- return pageSizeOptions ;
100+ return options ;
102101 }
103- return pageSizeOptions . concat ( [ pageSize . toString ( ) ] ) . sort ( ( a , b ) => {
102+ return options . concat ( [ pageSize . toString ( ) ] ) . sort ( ( a , b ) => {
104103 const numberA = Number . isNaN ( Number ( a ) ) ? 0 : Number ( a ) ;
105104 const numberB = Number . isNaN ( Number ( b ) ) ? 0 : Number ( b ) ;
106105 return numberA - numberB ;
@@ -111,16 +110,16 @@ const Options: React.FC<OptionsProps> = (props) => {
111110
112111 // ============== render ==============
113112
114- if ( ! changeSize && ! quickGo ) {
113+ if ( ! onChange && ! quickGo ) {
115114 return null ;
116115 }
117116
118117 let changeSelect : React . ReactNode = null ;
119118 let goInput : React . ReactNode = null ;
120119 let gotoButton : React . ReactNode = null ;
121120
122- if ( changeSize && Select ) {
123- const options = getPageSizeOptions ( ) . map < React . ReactNode > ( ( opt , i ) => (
121+ if ( onChange && Select ) {
122+ const slectOptions = getPageSizeOptions ( ) . map < React . ReactNode > ( ( opt , i ) => (
124123 < Select . Option key = { i } value = { opt . toString ( ) } >
125124 { mergeBuildOptionText ( opt ) }
126125 </ Select . Option >
@@ -134,13 +133,13 @@ const Options: React.FC<OptionsProps> = (props) => {
134133 className = { `${ prefixCls } -size-changer` }
135134 optionLabelProp = "children"
136135 popupMatchSelectWidth = { false }
137- value = { ( pageSize || pageSizeOptions [ 0 ] ) . toString ( ) }
138- onChange = { changeSizeHandle }
136+ value = { ( pageSize || options [ 0 ] ) . toString ( ) }
137+ onChange = { handleChangeSize }
139138 getPopupContainer = { ( triggerNode ) => triggerNode . parentNode }
140139 aria-label = { locale . page_size }
141140 defaultOpen = { false }
142141 >
143- { options }
142+ { slectOptions }
144143 </ Select >
145144 ) ;
146145 }
0 commit comments