import { Button } from '@components/common/ui/Button.js'; import { ButtonGroup } from '@components/common/ui/ButtonGroup.js'; import { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious } from '@components/common/ui/Pagination.js'; import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue } from '@components/common/ui/Select.js'; import React from 'react'; export interface GridPaginationProps { total: number; limit: number; page: number; } export function GridPagination({ total, limit, page }: GridPaginationProps) { const limitInput = React.useRef(null); React.useEffect(() => { if (limitInput.current) { limitInput.current.value = limit.toString(); } }, []); const onKeyPress = (e: React.ChangeEvent) => { e.preventDefault(); let pageNumber = parseInt(e.target.value, 10); if (page < 1) pageNumber = 1; if (page > Math.ceil(total / limit)) pageNumber = Math.ceil(total / limit); const url = new URL(window.location.href); url.searchParams.set('page', pageNumber.toString()); window.location.href = url.href; }; const onPrev = (e: React.MouseEvent) => { e.preventDefault(); const prev = page - 1; if (page === 1) return; const url = new URL(window.location.href); url.searchParams.set('page', prev.toString()); window.location.href = url.href; }; const onNext = (e: React.MouseEvent) => { e.preventDefault(); const next = page + 1; if (page * limit >= total) return; const url = new URL(window.location.href); url.searchParams.set('page', next.toString()); window.location.href = url.href; }; const onFirst = (e: React.MouseEvent) => { e.preventDefault(); if (page === 1) return; const url = new URL(window.location.href); url.searchParams.delete('page'); window.location.href = url.href; }; const onLast = (e: React.MouseEvent) => { e.preventDefault(); if (page === Math.ceil(total / limit)) return; const url = new URL(window.location.href); url.searchParams.set('page', Math.ceil(total / limit).toString()); window.location.href = url.href; }; return (
{ onPrev(e); }} /> {page > 1 && ( { onFirst(e); }} > 1 )} {page >= 3 && ( )} {page} {page < Math.ceil(total / limit) - 1 && ( )} {page * limit < total && ( { onLast(e); }} > {Math.ceil(total / limit)} )}
); }