Files
family_budget/frontend/src/components/Pagination.tsx
2026-03-02 00:33:09 +03:00

59 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
interface Props {
page: number;
pageSize: number;
totalItems: number;
totalPages: number;
onPageChange: (page: number) => void;
onPageSizeChange: (size: number) => void;
}
export function Pagination({
page,
pageSize,
totalItems,
totalPages,
onPageChange,
onPageSizeChange,
}: Props) {
const from = (page - 1) * pageSize + 1;
const to = Math.min(page * pageSize, totalItems);
return (
<div className="pagination">
<div className="pagination-info">
{totalItems > 0
? `Показано ${from}${to} из ${totalItems}`
: 'Нет записей'}
</div>
<div className="pagination-controls">
<select
className="pagination-size"
value={pageSize}
onChange={(e) => onPageSizeChange(Number(e.target.value))}
>
<option value={10}>10</option>
<option value={50}>50</option>
<option value={100}>100</option>
</select>
<button
className="btn-page"
disabled={page <= 1}
onClick={() => onPageChange(page - 1)}
>
&larr;
</button>
<span className="pagination-current">
{page} / {totalPages || 1}
</span>
<button
className="btn-page"
disabled={page >= totalPages}
onClick={() => onPageChange(page + 1)}
>
&rarr;
</button>
</div>
</div>
);
}