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 '
4
4
import { useTheme , makeStyles } from '@material-ui/core/styles'
5
5
6
6
import {
@@ -10,25 +10,34 @@ import {
10
10
LastPage as LastPageIcon ,
11
11
} from '@material-ui/icons/'
12
12
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 ) => {
14
23
const classes = useStyles ( )
15
24
const theme = useTheme ( )
16
- const { count, page, itemsPerPage , onChangePage } = props
25
+ const { count, page, rowsPerPage , onChangePage } = props
17
26
18
- const handleFirstPageButtonClick = ( event ) => {
27
+ const handleFirstPageButtonClick = ( event : MouseEvent < HTMLButtonElement > ) => {
19
28
onChangePage ( event , 0 )
20
29
}
21
30
22
- const handleBackButtonClick = ( event ) => {
31
+ const handleBackButtonClick = ( event : MouseEvent < HTMLButtonElement > ) => {
23
32
onChangePage ( event , page - 1 )
24
33
}
25
34
26
- const handleNextButtonClick = ( event ) => {
35
+ const handleNextButtonClick = ( event : MouseEvent < HTMLButtonElement > ) => {
27
36
onChangePage ( event , page + 1 )
28
37
}
29
38
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 ) )
32
41
}
33
42
34
43
return (
@@ -49,14 +58,14 @@ const BaseTablePaginationActions = (props) => {
49
58
</ IconButton >
50
59
< IconButton
51
60
onClick = { handleNextButtonClick }
52
- disabled = { page >= Math . ceil ( count / itemsPerPage ) - 1 }
61
+ disabled = { page >= Math . ceil ( count / rowsPerPage ) - 1 }
53
62
aria-label = "next page"
54
63
>
55
64
{ theme . direction === 'rtl' ? < KeyboardArrowLeft /> : < KeyboardArrowRight /> }
56
65
</ IconButton >
57
66
< IconButton
58
67
onClick = { handleLastPageButtonClick }
59
- disabled = { page >= Math . ceil ( count / itemsPerPage ) - 1 }
68
+ disabled = { page >= Math . ceil ( count / rowsPerPage ) - 1 }
60
69
aria-label = "last page"
61
70
>
62
71
{ theme . direction === 'rtl' ? < FirstPageIcon /> : < LastPageIcon /> }
@@ -65,7 +74,9 @@ const BaseTablePaginationActions = (props) => {
65
74
)
66
75
}
67
76
68
- const BaseTablePagination = ( props ) => {
77
+ export type IBaseTablePaginationProps = TablePaginationProps
78
+
79
+ const BaseTablePagination : React . FC < IBaseTablePaginationProps > = ( props ) => {
69
80
const { count, page, rowsPerPage, onChangePage, onChangeRowsPerPage = ( ) => { } } = props
70
81
71
82
return (
@@ -86,19 +97,11 @@ const BaseTablePagination = (props) => {
86
97
)
87
98
}
88
99
89
- const useStyles = makeStyles ( ( theme ) => ( {
100
+ const useStyles = makeStyles < ITheme > ( ( theme ) => ( {
90
101
root : {
91
102
flexShrink : 0 ,
92
103
marginLeft : theme . spacing ( 2.5 ) ,
93
104
} ,
94
105
} ) )
95
106
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
-
104
107
export default BaseTablePagination
0 commit comments