forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits

table-pagination.tsx55 lines, 2.2 KiBHistoryRawDownload
1import { Button } from "@/components/ui/button";
2import { IconChevronLeft, IconChevronRight } from "@/components/ui/icons";
3import { useT } from "@/stores/preferences-context";
4
5export type TablePaginationProps = {
6 /** Zero-based current page index. */
7 pageIndex: number;
8 pageCount: number;
9 pageSize: number;
10 /** Total row count (across all pages). */
11 total: number;
12 onPageChange: (pageIndex: number) => void;
13};
14
15/** Footer: "X kayıttan a-b arası" + prev/next + "page / total". */
16export function TablePagination(props: TablePaginationProps) {
17 const t = useT();
18 const start = () => (props.total === 0 ? 0 : props.pageIndex * props.pageSize + 1);
19 const end = () => Math.min((props.pageIndex + 1) * props.pageSize, props.total);
20
21 return (
22 <div class="flex w-full flex-col gap-2 rounded-lg border border-border-line bg-surface-overlay px-2.5 py-1.5 sm:flex-row sm:items-center sm:justify-between">
23 <span class="text-[11px] font-medium tabular-nums text-muted-foreground">
24 {t("common.pageRange", { start: start(), end: end(), total: props.total })}
25 </span>
26 <div class="flex items-center justify-end gap-1">
27 <Button
28 type="button"
29 variant="outline"
30 size="sm"
31 class="h-7 gap-1 px-1.5 text-[11px]"
32 disabled={props.pageIndex <= 0}
33 onClick={() => props.onPageChange(Math.max(0, props.pageIndex - 1))}
34 >
35 <IconChevronLeft class="h-3 w-3" />
36 <span class="hidden sm:inline">{t("common.prev")}</span>
37 </Button>
38 <span class="min-w-12 rounded-md border border-border-line bg-surface-base px-1.5 py-0.5 text-center text-[11px] font-semibold tabular-nums text-foreground">
39 {t("common.pageOf", { page: props.pageIndex + 1, total: props.pageCount })}
40 </span>
41 <Button
42 type="button"
43 variant="outline"
44 size="sm"
45 class="h-7 gap-1 px-1.5 text-[11px]"
46 disabled={props.pageIndex >= props.pageCount - 1}
47 onClick={() => props.onPageChange(Math.min(props.pageCount - 1, props.pageIndex + 1))}
48 >
49 <span class="hidden sm:inline">{t("common.next")}</span>
50 <IconChevronRight class="h-3 w-3" />
51 </Button>
52 </div>
53 </div>
54 );
55}