TablePaginationActions.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import {
  2. makeStyles,
  3. Theme,
  4. createStyles,
  5. IconButton,
  6. Typography,
  7. } from '@material-ui/core';
  8. import { KeyboardArrowLeft, KeyboardArrowRight } from '@material-ui/icons';
  9. import React from 'react';
  10. import { useTranslation } from 'react-i18next';
  11. import { TablePaginationActionsProps } from './Types';
  12. const useStyles = makeStyles((theme: Theme) =>
  13. createStyles({
  14. root: {
  15. display: 'flex',
  16. alignItems: 'center',
  17. flexShrink: 0,
  18. marginLeft: theme.spacing(2.5),
  19. },
  20. page: {
  21. display: 'flex',
  22. justifyContent: 'center',
  23. alignItems: 'center',
  24. width: '24px',
  25. height: '24px',
  26. backgroundColor: theme.palette.common.white,
  27. },
  28. btn: {
  29. width: '24px',
  30. height: '24px',
  31. border: '1px solid #c4c4c4',
  32. borderRadius: '2px 0 0 2px',
  33. backgroundColor: 'rgba(0,0,0,0.1)',
  34. cursor: 'pointer',
  35. },
  36. })
  37. );
  38. const TablePaginationActions = (props: TablePaginationActionsProps) => {
  39. const classes = useStyles();
  40. const { count, page, rowsPerPage, onChangePage } = props;
  41. // i18n
  42. const { t: commonTrans } = useTranslation();
  43. const gridTrans = commonTrans('grid');
  44. const handleBackButtonClick = (
  45. event: React.MouseEvent<HTMLButtonElement>
  46. ) => {
  47. onChangePage(event, page - 1);
  48. };
  49. const handleNextButtonClick = (
  50. event: React.MouseEvent<HTMLButtonElement>
  51. ) => {
  52. onChangePage(event, page + 1);
  53. };
  54. return (
  55. <div className={classes.root}>
  56. <IconButton
  57. onClick={handleBackButtonClick}
  58. disabled={page === 0}
  59. aria-label={gridTrans.prevLabel}
  60. className={classes.btn}
  61. >
  62. <KeyboardArrowLeft />
  63. </IconButton>
  64. <Typography variant="body2" className={classes.page}>
  65. {page + 1}
  66. </Typography>
  67. <IconButton
  68. onClick={handleNextButtonClick}
  69. disabled={page >= Math.ceil(count / rowsPerPage) - 1}
  70. aria-label={gridTrans.nextLabel}
  71. className={classes.btn}
  72. >
  73. <KeyboardArrowRight />
  74. </IconButton>
  75. </div>
  76. );
  77. };
  78. export default TablePaginationActions;