File size: 2,615 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
import React from 'react';
import PropTypes from 'prop-types';
import InputBase from '@mui/material/InputBase';
import MenuItem from '@mui/material/MenuItem';
import Select from '@mui/material/Select';
import Toolbar from '@mui/material/Toolbar';
import Typography from '@mui/material/Typography';
import { makeStyles } from 'tss-react/mui';
import { getPageValue } from '../utils.js';
import clsx from 'clsx';
const useStyles = makeStyles({ name: 'MUIDataTableJumpToPage' })(theme => ({
root: {
color: theme.palette.text.primary,
},
caption: {
flexShrink: 0,
},
/* Styles applied to the Select component root element */
selectRoot: {
marginRight: 32,
marginLeft: 8,
},
select: {
paddingTop: 6,
paddingBottom: 7,
paddingLeft: 8,
paddingRight: 24,
textAlign: 'right',
textAlignLast: 'right',
fontSize: theme.typography.pxToRem(14),
},
/* Styles applied to Select component icon class */
selectIcon: {},
/* Styles applied to InputBase component */
input: {
color: 'inhert',
fontSize: 'inhert',
flexShrink: 0,
},
}));
function JumpToPage(props) {
const { classes } = useStyles();
const handlePageChange = event => {
props.changePage(parseInt(event.target.value, 10));
};
const { count, textLabels, rowsPerPage, page, changePage } = props;
const textLabel = textLabels.pagination.jumpToPage;
let pages = [];
let lastPage = Math.min(1000, getPageValue(count, rowsPerPage, 1000000));
for (let ii = 0; ii <= lastPage; ii++) {
pages.push(ii);
}
const MenuItemComponent = MenuItem;
let myStyle = {
display: 'flex',
minHeight: '52px',
alignItems: 'center',
};
return (
<Toolbar style={myStyle} className={classes.root}>
<Typography color="inherit" variant="body2" className={classes.caption}>
{textLabel}
</Typography>
<Select
classes={{ select: classes.select, icon: classes.selectIcon }}
input={<InputBase className={clsx(classes.input, classes.selectRoot)} />}
value={getPageValue(count, rowsPerPage, page)}
onChange={handlePageChange}
style={{ marginRight: 0 }}>
{pages.map(pageVal => (
<MenuItemComponent className={classes.menuItem} key={pageVal} value={pageVal}>
{pageVal + 1}
</MenuItemComponent>
))}
</Select>
</Toolbar>
);
}
JumpToPage.propTypes = {
count: PropTypes.number.isRequired,
page: PropTypes.number.isRequired,
rowsPerPage: PropTypes.number.isRequired,
textLabels: PropTypes.object.isRequired,
};
export default JumpToPage;
|