mirror of
https://github.com/umami-software/umami.git
synced 2026-02-06 13:47:15 +01:00
Moved code into src folder. Added build for component library.
This commit is contained in:
parent
7a7233ead4
commit
ede658771e
490 changed files with 749 additions and 442 deletions
45
src/components/common/Pager.js
Normal file
45
src/components/common/Pager.js
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import styles from './Pager.module.css';
|
||||
import { Button, Flexbox, Icon, Icons } from 'react-basics';
|
||||
import useMessages from 'components/hooks/useMessages';
|
||||
|
||||
export function Pager({ page, pageSize, count, onPageChange }) {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const maxPage = Math.ceil(count / pageSize);
|
||||
const lastPage = page === maxPage;
|
||||
const firstPage = page === 1;
|
||||
|
||||
if (count === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const handlePageChange = value => {
|
||||
const nextPage = page + value;
|
||||
if (nextPage > 0 && nextPage <= maxPage) {
|
||||
onPageChange(nextPage);
|
||||
}
|
||||
};
|
||||
|
||||
if (maxPage === 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Flexbox justifyContent="center" className={styles.container}>
|
||||
<Button onClick={() => handlePageChange(-1)} disabled={firstPage}>
|
||||
<Icon rotate={90}>
|
||||
<Icons.ChevronDown />
|
||||
</Icon>
|
||||
</Button>
|
||||
<Flexbox alignItems="center" className={styles.text}>
|
||||
{formatMessage(labels.pageOf, { current: page, total: maxPage })}
|
||||
</Flexbox>
|
||||
<Button onClick={() => handlePageChange(1)} disabled={lastPage}>
|
||||
<Icon rotate={270}>
|
||||
<Icons.ChevronDown />
|
||||
</Icon>
|
||||
</Button>
|
||||
</Flexbox>
|
||||
);
|
||||
}
|
||||
|
||||
export default Pager;
|
||||
Loading…
Add table
Add a link
Reference in a new issue