1- import React from 'react'
2- import PropTypes from 'prop-types '
3- import { TablePagination , IconButton } from '@material-ui/core'
1+ import React , { MouseEvent } from 'react'
2+ import { TablePagination , TablePaginationProps , IconButton } from '@material-ui/core '
3+ import { TablePaginationActionsProps } from '@material-ui/core/TablePagination/TablePaginationActions '
44import { useTheme , makeStyles } from '@material-ui/core/styles'
55
66import {
@@ -10,25 +10,34 @@ import {
1010 LastPage as LastPageIcon ,
1111} from '@material-ui/icons/'
1212
13- const BaseTablePaginationActions = ( props ) => {
13+ import { ITheme } from '_theme/'
14+
15+ export interface IBaseTablePaginationActionsProps {
16+ count : number
17+ page : number
18+ rowsPerPage : number
19+ onChangePage : ( event : React . MouseEvent < HTMLButtonElement > , newPage : number ) => void
20+ }
21+
22+ const BaseTablePaginationActions : React . FC < TablePaginationActionsProps > = ( props ) => {
1423 const classes = useStyles ( )
1524 const theme = useTheme ( )
16- const { count, page, itemsPerPage , onChangePage } = props
25+ const { count, page, rowsPerPage , onChangePage } = props
1726
18- const handleFirstPageButtonClick = ( event ) => {
27+ const handleFirstPageButtonClick = ( event : MouseEvent < HTMLButtonElement > ) => {
1928 onChangePage ( event , 0 )
2029 }
2130
22- const handleBackButtonClick = ( event ) => {
31+ const handleBackButtonClick = ( event : MouseEvent < HTMLButtonElement > ) => {
2332 onChangePage ( event , page - 1 )
2433 }
2534
26- const handleNextButtonClick = ( event ) => {
35+ const handleNextButtonClick = ( event : MouseEvent < HTMLButtonElement > ) => {
2736 onChangePage ( event , page + 1 )
2837 }
2938
30- const handleLastPageButtonClick = ( event ) => {
31- onChangePage ( event , Math . max ( 0 , Math . ceil ( count / itemsPerPage ) - 1 ) )
39+ const handleLastPageButtonClick = ( event : MouseEvent < HTMLButtonElement > ) => {
40+ onChangePage ( event , Math . max ( 0 , Math . ceil ( count / rowsPerPage ) - 1 ) )
3241 }
3342
3443 return (
@@ -49,14 +58,14 @@ const BaseTablePaginationActions = (props) => {
4958 </ IconButton >
5059 < IconButton
5160 onClick = { handleNextButtonClick }
52- disabled = { page >= Math . ceil ( count / itemsPerPage ) - 1 }
61+ disabled = { page >= Math . ceil ( count / rowsPerPage ) - 1 }
5362 aria-label = "next page"
5463 >
5564 { theme . direction === 'rtl' ? < KeyboardArrowLeft /> : < KeyboardArrowRight /> }
5665 </ IconButton >
5766 < IconButton
5867 onClick = { handleLastPageButtonClick }
59- disabled = { page >= Math . ceil ( count / itemsPerPage ) - 1 }
68+ disabled = { page >= Math . ceil ( count / rowsPerPage ) - 1 }
6069 aria-label = "last page"
6170 >
6271 { theme . direction === 'rtl' ? < FirstPageIcon /> : < LastPageIcon /> }
@@ -65,7 +74,9 @@ const BaseTablePaginationActions = (props) => {
6574 )
6675}
6776
68- const BaseTablePagination = ( props ) => {
77+ export type IBaseTablePaginationProps = TablePaginationProps
78+
79+ const BaseTablePagination : React . FC < IBaseTablePaginationProps > = ( props ) => {
6980 const { count, page, rowsPerPage, onChangePage, onChangeRowsPerPage = ( ) => { } } = props
7081
7182 return (
@@ -86,19 +97,11 @@ const BaseTablePagination = (props) => {
8697 )
8798}
8899
89- const useStyles = makeStyles ( ( theme ) => ( {
100+ const useStyles = makeStyles < ITheme > ( ( theme ) => ( {
90101 root : {
91102 flexShrink : 0 ,
92103 marginLeft : theme . spacing ( 2.5 ) ,
93104 } ,
94105} ) )
95106
96- BaseTablePagination . propTypes = {
97- count : PropTypes . number . isRequired ,
98- page : PropTypes . number . isRequired ,
99- rowsPerPage : PropTypes . number . isRequired ,
100- onChangePage : PropTypes . func . isRequired ,
101- onChangeRowsPerPage : PropTypes . func ,
102- }
103-
104107export default BaseTablePagination
0 commit comments