@centreon/react-components
Version:
react components used by centreon web frontend
97 lines (87 loc) • 2.97 kB
JavaScript
/* eslint-disable react/forbid-prop-types */
/* eslint-disable react/jsx-filename-extension */
/* eslint-disable react/prop-types */
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import IconButton from '@material-ui/core/IconButton';
import FirstPageIcon from '@material-ui/icons/FirstPage';
import KeyboardArrowLeft from '@material-ui/icons/KeyboardArrowLeft';
import KeyboardArrowRight from '@material-ui/icons/KeyboardArrowRight';
import LastPageIcon from '@material-ui/icons/LastPage';
const styles = (theme) => ({
root: {
flexShrink: 0,
color: theme.palette.text.secondary,
marginLeft: theme.spacing(2.5),
},
});
class TablePaginationActions extends Component {
handleFirstPageButtonClick = (event) => {
const { onChangePage } = this.props;
onChangePage(event, 0);
};
handleBackButtonClick = (event) => {
const { onChangePage, page } = this.props;
onChangePage(event, page - 1);
};
handleNextButtonClick = (event) => {
const { onChangePage, page } = this.props;
onChangePage(event, page + 1);
};
handleLastPageButtonClick = (event) => {
const { count, rowsPerPage, onChangePage } = this.props;
onChangePage(event, Math.max(0, Math.ceil(count / rowsPerPage) - 1));
};
render() {
const { classes, count, page, theme, rowsPerPage } = this.props;
return (
<div className={classes.root}>
<IconButton
onClick={this.handleFirstPageButtonClick}
disabled={page === 0}
aria-label="First Page"
>
{theme.direction === 'rtl' ? <LastPageIcon /> : <FirstPageIcon />}
</IconButton>
<IconButton
onClick={this.handleBackButtonClick}
disabled={page === 0}
aria-label="Previous Page"
>
{theme.direction === 'rtl' ? (
<KeyboardArrowRight />
) : (
<KeyboardArrowLeft />
)}
</IconButton>
<IconButton
onClick={this.handleNextButtonClick}
disabled={page >= Math.ceil(count / rowsPerPage) - 1}
aria-label="Next Page"
>
{theme.direction === 'rtl' ? (
<KeyboardArrowLeft />
) : (
<KeyboardArrowRight />
)}
</IconButton>
<IconButton
onClick={this.handleLastPageButtonClick}
disabled={page >= Math.ceil(count / rowsPerPage) - 1}
aria-label="Last Page"
>
{theme.direction === 'rtl' ? <FirstPageIcon /> : <LastPageIcon />}
</IconButton>
</div>
);
}
}
TablePaginationActions.propTypes = {
count: PropTypes.number.isRequired,
page: PropTypes.number.isRequired,
rowsPerPage: PropTypes.number.isRequired,
theme: PropTypes.object.isRequired,
classes: PropTypes.object.isRequired,
};
export default withStyles(styles, { withTheme: true })(TablePaginationActions);