From be03ebb311cba892212151e30de0e4eb0f518d42 Mon Sep 17 00:00:00 2001 From: metamethods Date: Fri, 3 Jan 2025 01:49:14 -0800 Subject: [PATCH] feat: allow passing page url param --- src/lib/Pagination.svelte | 35 +++++++++++++++++++++-------------- src/routes/+page.svelte | 8 +++++++- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/lib/Pagination.svelte b/src/lib/Pagination.svelte index b07eeae..ea3aa9f 100644 --- a/src/lib/Pagination.svelte +++ b/src/lib/Pagination.svelte @@ -2,10 +2,15 @@ let { items, itemsPerPage, - pageItems = $bindable() - }: { items: Array; itemsPerPage: number; pageItems: Array } = $props(); + pageItems = $bindable(), + currentPage = 0 + }: { + items: Array; + itemsPerPage: number; + pageItems: Array; + currentPage?: number; + } = $props(); - let currentPage = $state(0); let pageIndexStart = $derived(currentPage * itemsPerPage); let pageIndexEnd = $derived(Math.min(itemsPerPage * (currentPage + 1), items.length)); @@ -20,21 +25,23 @@ showing {pageIndexStart + 1} to {pageIndexEnd} of {items.length} - entires + entires ()

- currentPage--}>prev - currentPage++}>next
- - diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 15a4025..8ae14fb 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,4 +1,5 @@