mirror of
https://github.com/portainer/portainer.git
synced 2025-07-22 23:09:41 +02:00
refactor(app): move react components to react codebase [EE-3179] (#6971)
This commit is contained in:
parent
212400c283
commit
18252ab854
346 changed files with 642 additions and 644 deletions
98
app/react/components/PaginationControls/PageSelector.tsx
Normal file
98
app/react/components/PaginationControls/PageSelector.tsx
Normal file
|
@ -0,0 +1,98 @@
|
|||
import { generatePagesArray } from './generatePagesArray';
|
||||
import { PageButton } from './PageButton';
|
||||
import { PageInput } from './PageInput';
|
||||
|
||||
interface Props {
|
||||
boundaryLinks?: boolean;
|
||||
currentPage: number;
|
||||
directionLinks?: boolean;
|
||||
itemsPerPage: number;
|
||||
onPageChange(page: number): void;
|
||||
totalCount: number;
|
||||
maxSize: number;
|
||||
isInputVisible?: boolean;
|
||||
}
|
||||
|
||||
export function PageSelector({
|
||||
currentPage,
|
||||
totalCount,
|
||||
itemsPerPage,
|
||||
onPageChange,
|
||||
maxSize = 5,
|
||||
directionLinks = true,
|
||||
boundaryLinks = false,
|
||||
isInputVisible = false,
|
||||
}: Props) {
|
||||
const pages = generatePagesArray(
|
||||
currentPage,
|
||||
totalCount,
|
||||
itemsPerPage,
|
||||
maxSize
|
||||
);
|
||||
const last = pages[pages.length - 1];
|
||||
|
||||
if (pages.length <= 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{isInputVisible && (
|
||||
<PageInput
|
||||
onChange={(page) => onPageChange(page)}
|
||||
totalPages={Math.ceil(totalCount / itemsPerPage)}
|
||||
/>
|
||||
)}
|
||||
<ul className="pagination">
|
||||
{boundaryLinks ? (
|
||||
<PageButton
|
||||
onPageChange={onPageChange}
|
||||
page={1}
|
||||
disabled={currentPage === 1}
|
||||
>
|
||||
«
|
||||
</PageButton>
|
||||
) : null}
|
||||
{directionLinks ? (
|
||||
<PageButton
|
||||
onPageChange={onPageChange}
|
||||
page={currentPage - 1}
|
||||
disabled={currentPage === 1}
|
||||
>
|
||||
‹
|
||||
</PageButton>
|
||||
) : null}
|
||||
{pages.map((pageNumber, index) => (
|
||||
<PageButton
|
||||
onPageChange={onPageChange}
|
||||
page={pageNumber}
|
||||
disabled={pageNumber === '...'}
|
||||
active={currentPage === pageNumber}
|
||||
key={index}
|
||||
>
|
||||
{pageNumber}
|
||||
</PageButton>
|
||||
))}
|
||||
|
||||
{directionLinks ? (
|
||||
<PageButton
|
||||
onPageChange={onPageChange}
|
||||
page={currentPage + 1}
|
||||
disabled={currentPage === last}
|
||||
>
|
||||
›
|
||||
</PageButton>
|
||||
) : null}
|
||||
{boundaryLinks ? (
|
||||
<PageButton
|
||||
disabled={currentPage === last}
|
||||
onPageChange={onPageChange}
|
||||
page={last}
|
||||
>
|
||||
»
|
||||
</PageButton>
|
||||
) : null}
|
||||
</ul>
|
||||
</>
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue