Replace bespoke paginator with shared web-ui Pagination component
Swaps the custom paginator.svelte (used on the lists overview and list detail pages) for the shared @gabriel20xx/web-ui Pagination component, matching the workspace-wide pagination policy. Data fetching and client-side slicing logic are unchanged. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cfa06cd466
commit
a5dfd3dc5a
3 files changed
+4
-99
No files matched your search
@@ -1,95 +0,0 @@
|
|||||||
<script>
|
|
||||||
import { ChevronFirst, ChevronLast, ChevronLeft, ChevronRight } from '@lucide/svelte';
|
|
||||||
import Button from './button.svelte';
|
|
||||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from './select';
|
|
||||||
import { SimpleTooltip } from './tooltip';
|
|
||||||
|
|
||||||
const PAGE_SIZE_OPTIONS = [12, 24, 48, 96];
|
|
||||||
|
|
||||||
let { page, pageSize = 24, pageLength = 0, totalLength = 0, onPaging } = $props();
|
|
||||||
|
|
||||||
const hasPreviousPage = $derived(page > 1);
|
|
||||||
const firstItemIndex = $derived((page - 1) * pageSize + 1);
|
|
||||||
const lastItemIndex = $derived((page - 1) * pageSize + pageLength);
|
|
||||||
const hasNextPage = $derived(page * pageSize < totalLength);
|
|
||||||
|
|
||||||
// Passed as `Select`'s `items` prop so the trigger shows the right label immediately, even
|
|
||||||
// before the dropdown has ever been opened - bits-ui can't rely on `Select.Item` having
|
|
||||||
// mounted to the DOM yet to read its label back off of it.
|
|
||||||
const pageSizeItems = PAGE_SIZE_OPTIONS.map((size) => ({ value: String(size), label: String(size) }));
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div class="flex flex-wrap items-center justify-end gap-4 px-2 py-3 text-sm">
|
|
||||||
<Select
|
|
||||||
type="single"
|
|
||||||
value={String(pageSize)}
|
|
||||||
items={pageSizeItems}
|
|
||||||
onValueChange={(value) => onPaging({ page: 1, pageSize: Number(value) })}
|
|
||||||
>
|
|
||||||
<SelectTrigger class="w-24">
|
|
||||||
<SelectValue />
|
|
||||||
</SelectTrigger>
|
|
||||||
<SelectContent>
|
|
||||||
{#each pageSizeItems as item (item.value)}
|
|
||||||
<SelectItem value={item.value} label={item.label}>{item.label}</SelectItem>
|
|
||||||
{/each}
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
<p class="text-muted-fg">
|
|
||||||
{firstItemIndex.toLocaleString()}–{lastItemIndex.toLocaleString()} of {totalLength.toLocaleString()}
|
|
||||||
</p>
|
|
||||||
<div class="flex items-center gap-1">
|
|
||||||
<SimpleTooltip label="First page">
|
|
||||||
{#snippet children({ props })}
|
|
||||||
<Button
|
|
||||||
{...props}
|
|
||||||
variant="ghost"
|
|
||||||
size="icon"
|
|
||||||
disabled={!hasPreviousPage}
|
|
||||||
onclick={() => onPaging({ page: 1, pageSize })}
|
|
||||||
>
|
|
||||||
<ChevronFirst class="size-4" />
|
|
||||||
</Button>
|
|
||||||
{/snippet}
|
|
||||||
</SimpleTooltip>
|
|
||||||
<SimpleTooltip label="Previous page">
|
|
||||||
{#snippet children({ props })}
|
|
||||||
<Button
|
|
||||||
{...props}
|
|
||||||
variant="ghost"
|
|
||||||
size="icon"
|
|
||||||
disabled={!hasPreviousPage}
|
|
||||||
onclick={() => onPaging({ page: page - 1, pageSize })}
|
|
||||||
>
|
|
||||||
<ChevronLeft class="size-4" />
|
|
||||||
</Button>
|
|
||||||
{/snippet}
|
|
||||||
</SimpleTooltip>
|
|
||||||
<SimpleTooltip label="Next page">
|
|
||||||
{#snippet children({ props })}
|
|
||||||
<Button
|
|
||||||
{...props}
|
|
||||||
variant="ghost"
|
|
||||||
size="icon"
|
|
||||||
disabled={!hasNextPage}
|
|
||||||
onclick={() => onPaging({ page: page + 1, pageSize })}
|
|
||||||
>
|
|
||||||
<ChevronRight class="size-4" />
|
|
||||||
</Button>
|
|
||||||
{/snippet}
|
|
||||||
</SimpleTooltip>
|
|
||||||
<SimpleTooltip label="Last page">
|
|
||||||
{#snippet children({ props })}
|
|
||||||
<Button
|
|
||||||
{...props}
|
|
||||||
variant="ghost"
|
|
||||||
size="icon"
|
|
||||||
disabled={!hasNextPage}
|
|
||||||
onclick={() => onPaging({ page: Math.max(1, Math.ceil(totalLength / pageSize)), pageSize })}
|
|
||||||
>
|
|
||||||
<ChevronLast class="size-4" />
|
|
||||||
</Button>
|
|
||||||
{/snippet}
|
|
||||||
</SimpleTooltip>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
import { createDashboardViewMode } from '$lib/preferences/viewMode.svelte.js';
|
import { createDashboardViewMode } from '$lib/preferences/viewMode.svelte.js';
|
||||||
import Button from '$lib/components/ui/button.svelte';
|
import Button from '$lib/components/ui/button.svelte';
|
||||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '$lib/components/ui/select';
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '$lib/components/ui/select';
|
||||||
import Paginator from '$lib/components/ui/paginator.svelte';
|
import { Pagination } from '@gabriel20xx/web-ui';
|
||||||
import ListsGrid from '$lib/components/lists/ListsGrid.svelte';
|
import ListsGrid from '$lib/components/lists/ListsGrid.svelte';
|
||||||
import ListsTable from '$lib/components/lists/ListsTable.svelte';
|
import ListsTable from '$lib/components/lists/ListsTable.svelte';
|
||||||
|
|
||||||
@@ -155,7 +155,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<section class="rounded-lg border border-border bg-surface">
|
<section class="rounded-lg border border-border bg-surface">
|
||||||
<Paginator
|
<Pagination
|
||||||
{page}
|
{page}
|
||||||
{pageSize}
|
{pageSize}
|
||||||
pageLength={pageItems.length}
|
pageLength={pageItems.length}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
import { resolve } from '$app/paths';
|
import { resolve } from '$app/paths';
|
||||||
import { ArrowLeft, LoaderCircle } from '@lucide/svelte';
|
import { ArrowLeft, LoaderCircle } from '@lucide/svelte';
|
||||||
import Button from '$lib/components/ui/button.svelte';
|
import Button from '$lib/components/ui/button.svelte';
|
||||||
import Paginator from '$lib/components/ui/paginator.svelte';
|
import { Pagination } from '@gabriel20xx/web-ui';
|
||||||
import { createOverviewData } from '$lib/features/lists/listsData.svelte.js';
|
import { createOverviewData } from '$lib/features/lists/listsData.svelte.js';
|
||||||
import { listFieldsFor, listItemsFor, itemValuesFor, valueFor, fmtDate } from '$lib/features/lists/listHelpers.js';
|
import { listFieldsFor, listItemsFor, itemValuesFor, valueFor, fmtDate } from '$lib/features/lists/listHelpers.js';
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<Paginator
|
<Pagination
|
||||||
{page}
|
{page}
|
||||||
{pageSize}
|
{pageSize}
|
||||||
pageLength={pageItems.length}
|
pageLength={pageItems.length}
|
||||||
|
|||||||
Reference in new issue
Block a user