|
1
|
"use client" |
|
2
|
|
|
3
|
import * as React from "react" |
|
4
|
|
|
5
|
import { useDataTableContext } from "@/blocks/data-table/context/use-data-table-context" |
|
6
|
import { Skeleton } from "@/components/skeleton" |
|
7
|
import { Table } from "@/components/table" |
|
8
|
|
|
9
|
interface DataTablePaginationProps { |
|
10
|
/** |
|
11
|
* The translations for strings in the pagination component. |
|
12
|
*/ |
|
13
|
translations?: React.ComponentProps<typeof Table.Pagination>["translations"] |
|
14
|
} |
|
15
|
|
|
16
|
/** |
|
17
|
* This component adds a pagination component and functionality to the data table. |
|
18
|
*/ |
|
19
|
const DataTablePagination = (props: DataTablePaginationProps) => { |
|
20
|
const { instance } = useDataTableContext() |
|
21
|
|
|
22
|
if (!instance.enablePagination) { |
|
23
|
throw new Error( |
|
24
|
"DataTable.Pagination was rendered but pagination is not enabled. Make sure to pass pagination to 'useDataTable'" |
|
25
|
) |
|
26
|
} |
|
27
|
|
|
28
|
if (instance.showSkeleton) { |
|
29
|
return <DataTablePaginationSkeleton /> |
|
30
|
} |
|
31
|
|
|
32
|
return ( |
|
33
|
<Table.Pagination |
|
34
|
translations={props.translations} |
|
35
|
className="flex-shrink-0" |
|
36
|
canNextPage={instance.getCanNextPage()} |
|
37
|
canPreviousPage={instance.getCanPreviousPage()} |
|
38
|
pageCount={instance.getPageCount()} |
|
39
|
count={instance.rowCount} |
|
40
|
nextPage={instance.nextPage} |
|
41
|
previousPage={instance.previousPage} |
|
42
|
pageIndex={instance.pageIndex} |
|
43
|
pageSize={instance.pageSize} |
|
44
|
/> |
|
45
|
) |
|
46
|
} |
|
47
|
DataTablePagination.displayName = "DataTable.Pagination" |
|
48
|
|
|
49
|
const DataTablePaginationSkeleton = () => { |
|
50
|
return ( |
|
51
|
<div> |
|
52
|
<div className="flex items-center justify-between p-4"> |
|
53
|
<Skeleton className="h-7 w-[138px]" /> |
|
54
|
<div className="flex items-center gap-x-2"> |
|
55
|
<Skeleton className="h-7 w-24" /> |
|
56
|
<Skeleton className="h-7 w-11" /> |
|
57
|
<Skeleton className="h-7 w-11" /> |
|
58
|
</div> |
|
59
|
</div> |
|
60
|
</div> |
|
61
|
) |
|
62
|
} |
|
63
|
|
|
64
|
export { DataTablePagination } |
|
65
|
export type { DataTablePaginationProps } |
|
66
|
|