Skip to content

Instantly share code, notes, and snippets.

@begoon
Created July 8, 2023 14:43
Show Gist options
  • Save begoon/78c42eb24974ac3190e042f095119f58 to your computer and use it in GitHub Desktop.
Save begoon/78c42eb24974ac3190e042f095119f58 to your computer and use it in GitHub Desktop.
Simple paginator for Svelte
<script lang="ts">
import PageLink from "./PageLink.svelte";
export let pages: number;
export let current: number;
export let query: string | undefined;
</script>
{#if pages > 1}
{#if pages < 20}
{#each Array(pages) as _, i}
<PageLink {current} {i} {query} />
{/each}
{:else}
<PageLink {current} i={0} {query} />
{#if current > 3}...{/if}
{#each Array(5) as _, i}
{@const j = current - 2 + i}
{#if j >= 1 && j <= pages - 2}
<PageLink {current} i={j} {query} />
{/if}
{/each}
{#if current < pages - 4}...{/if}
<PageLink {current} i={pages - 1} {query} />
{/if}
{/if}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment