mirror of
https://github.com/hanzoai/dataroom.git
synced 2026-10-30 18:41:07 +00:00
110 lines
3.5 KiB
TypeScript
110 lines
3.5 KiB
TypeScript
import {
|
|
ChevronLeftIcon,
|
|
ChevronRightIcon,
|
|
ChevronsLeftIcon,
|
|
ChevronsRightIcon,
|
|
} from "lucide-react";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
import { Card } from "@/components/ui/card";
|
|
import {
|
|
Select,
|
|
SelectContent,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
} from "@/components/ui/select";
|
|
|
|
interface PaginationProps {
|
|
currentPage: number;
|
|
pageSize: number;
|
|
totalItems: number;
|
|
totalPages: number;
|
|
onPageChange: (page: number) => void;
|
|
onPageSizeChange: (size: number) => void;
|
|
totalShownItems: number;
|
|
itemName: string;
|
|
}
|
|
|
|
export function Pagination({
|
|
currentPage,
|
|
pageSize,
|
|
totalItems,
|
|
totalPages,
|
|
onPageChange,
|
|
onPageSizeChange,
|
|
totalShownItems,
|
|
itemName,
|
|
}: PaginationProps) {
|
|
return (
|
|
<Card className="mt-4 p-4">
|
|
<div className="flex items-center justify-between">
|
|
<div className="flex-1 text-sm text-muted-foreground">
|
|
Showing <span className="font-bold">{totalShownItems}</span> of{" "}
|
|
{totalItems} {itemName}
|
|
</div>
|
|
<div className="flex items-center space-x-6 lg:space-x-8">
|
|
<div className="hidden items-center space-x-2 sm:flex">
|
|
<p className="text-sm font-medium">Items per page</p>
|
|
<Select
|
|
value={`${pageSize}`}
|
|
onValueChange={(value) => onPageSizeChange(Number(value))}
|
|
>
|
|
<SelectTrigger className="h-8 w-[70px]">
|
|
<SelectValue placeholder={pageSize} />
|
|
</SelectTrigger>
|
|
<SelectContent side="top">
|
|
{[10, 20, 30, 40, 50].map((size) => (
|
|
<SelectItem key={size} value={`${size}`}>
|
|
{size}
|
|
</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
</div>
|
|
<div className="flex w-[100px] items-center justify-center text-sm font-medium">
|
|
Page {currentPage} of {totalPages || 1}
|
|
</div>
|
|
<div className="flex items-center space-x-2">
|
|
<Button
|
|
variant="outline"
|
|
className="hidden h-8 w-8 p-0 lg:flex"
|
|
onClick={() => onPageChange(1)}
|
|
disabled={currentPage === 1}
|
|
>
|
|
<span className="sr-only">Go to first page</span>
|
|
<ChevronsLeftIcon className="h-4 w-4" />
|
|
</Button>
|
|
<Button
|
|
variant="outline"
|
|
className="h-8 w-8 p-0"
|
|
onClick={() => onPageChange(currentPage - 1)}
|
|
disabled={currentPage === 1}
|
|
>
|
|
<span className="sr-only">Go to previous page</span>
|
|
<ChevronLeftIcon className="h-4 w-4" />
|
|
</Button>
|
|
<Button
|
|
variant="outline"
|
|
className="h-8 w-8 p-0"
|
|
onClick={() => onPageChange(currentPage + 1)}
|
|
disabled={currentPage === totalPages || totalPages === 0}
|
|
>
|
|
<span className="sr-only">Go to next page</span>
|
|
<ChevronRightIcon className="h-4 w-4" />
|
|
</Button>
|
|
<Button
|
|
variant="outline"
|
|
className="hidden h-8 w-8 p-0 lg:flex"
|
|
onClick={() => onPageChange(totalPages)}
|
|
disabled={currentPage === totalPages || totalPages === 0}
|
|
>
|
|
<span className="sr-only">Go to last page</span>
|
|
<ChevronsRightIcon className="h-4 w-4" />
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</Card>
|
|
);
|
|
}
|