Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 31 additions & 23 deletions components/common/PaginatedTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import {
SelectTrigger,
SelectValue,
} from 'components/ui/select'
import { Card, CardContent, CardHeader, CardTitle } from 'components/ui/card'
import {
Card,
CardContent,
CardFooter,
CardHeader,
CardTitle,
} from 'components/ui/card'
import { ChevronLeft, ChevronRight } from 'lucide-react'
import { type ReactNode } from 'react'
import { type ColumnDef } from '@tanstack/react-table'
Expand Down Expand Up @@ -56,19 +62,33 @@ export default function PaginatedTable<T>({
}: PaginatedTableProps<T>) {
return (
<Card className="flex min-h-0 flex-1 flex-col">
<CardHeader className="flex-row items-center justify-between">
<CardTitle>
{title} ({total})
</CardTitle>
<CardHeader>
<CardTitle>{title}</CardTitle>
</CardHeader>
<CardContent className="min-h-0 flex-1 p-0">
<DataTable
columns={columns}
data={items}
trackBy={trackBy}
loading={loading}
loadingText={loadingText}
emptyText={emptyText}
onRowClick={onRowClick}
scrollAreaClassName="h-full overflow-auto"
/>
</CardContent>
<CardFooter className="justify-between border-t pt-4">
<div className="text-sm text-muted-foreground">全 {total} 件</div>
<div className="flex items-center gap-2">
<Select
value={String(perPage)}
onValueChange={(v) => onPageSizeChange(Number(v))}
>
<SelectTrigger className="w-24">
<SelectTrigger size="sm" className="w-24">
<SelectValue />
</SelectTrigger>
<SelectContent>
{/* footer 下端の Select なので上方向に開く */}
<SelectContent position="popper" side="top" align="end">
{PAGE_SIZE_OPTIONS.map((o) => (
<SelectItem key={o.value} value={o.value}>
{o.label}
Expand All @@ -79,19 +99,19 @@ export default function PaginatedTable<T>({
<div className="flex items-center gap-1">
<Button
variant="outline"
size="icon"
size="icon-sm"
aria-label="前のページ"
disabled={currentPage <= 1}
onClick={() => onPageChange(currentPage - 1)}
>
<ChevronLeft className="size-4" />
</Button>
<span className="text-sm px-2">
<span className="px-2 text-sm">
{currentPage} / {lastPage}
</span>
<Button
variant="outline"
size="icon"
size="icon-sm"
aria-label="次のページ"
disabled={currentPage >= lastPage}
onClick={() => onPageChange(currentPage + 1)}
Expand All @@ -100,19 +120,7 @@ export default function PaginatedTable<T>({
</Button>
</div>
</div>
</CardHeader>
<CardContent className="min-h-0 flex-1 p-0">
<DataTable
columns={columns}
data={items}
trackBy={trackBy}
loading={loading}
loadingText={loadingText}
emptyText={emptyText}
onRowClick={onRowClick}
scrollAreaClassName="h-full overflow-auto"
/>
</CardContent>
</CardFooter>
</Card>
)
}
Loading