2.1.15 ā€¢ Published 10 days ago

@jill64/svelte-pagination v2.1.15

Weekly downloads
-
License
MIT
Repository
github
Last release
10 days ago

@jill64/svelte-pagination

šŸ“– Pagination component for Svelte

Demo

Installation

npm i @jill64/svelte-pagination

Quick Example

<!-- /src/route/[page=int]/+page.svelte -->
<script>
  import { PaginateItems } from '@jill64/svelte-pagination'

  export let data

  $: ({ lastPage } = data)
</script>

<div>
  <PaginateItems {lastPage} slug="[page=int]" />
</div>

<style>
  div {
    /* Your Navigation Box Style */
  }
  div :global(.paginate-page-link) {
    /* Page Link Style */
  }
  div :global(.paginate-navigation) {
    /* Navigation Link Style */
  }
  div :global(.paginate-rest-indicator) {
    /* Rest Indicator (...) Style */
  }
  div :global(.paginate-current-page) {
    /* Current Page Indicator Style */
  }
</style>

Key Feature

This component uses SvelteKit route parameters for page management.
This enables SvelteKit features like preloading and prefetching when out of the box.
Therefore, it is necessary to pass the ID of the route parameter that manages the number of pages to the Paginate component as the slug property.

Keyboard Navigation

By default, the PaginateItems component is keyboard navigable.

keyaction
ā†’Next Page
āŒ˜ + ā†’Last Page
ā†Previous Page
āŒ˜ + ā†First Page

This behavior can be disabled by passing disableKeyboardNavigationprop.

Optional Props

namedefaultdescription
sideSize2Number of pages from start/end page
centerSize3Number of pages from current page
previousLabelļ¼œ PreviousPrevious button label
nextLabelNext ļ¼žNext button label
firstLabelļ¼œļ¼œFirst button label
lastLabelļ¼žļ¼žLast button label

!NOTE You can always hide that label by setting the value of the label prop to Falsy.

Calculate Last Page

You can also use the included utility functions to calculate the last page.

<!-- /src/route/[page=int]/+page.svelte -->
<script>
  import { PaginateItems, calcLastPage } from '@jill64/svelte-pagination'

  export let data

  $: ({ totalCount } = data)
</script>

<div>
  <PaginateItems
    lastPage={calcLastPage({
      total: totalCount
      per: 30 // Count per page
    })}
    slug="[page=int]"
  />
</div>

Prepared Page Param Matcher

Integer parameter matcher (commonly used for pagination) is available.

// /src/params/int.js
export { int as match } from '@jill64/svelte-pagination'

Migrate from v1

In v2, container elements are now user-managed.
Instead of <Paginate>, you must use <PaginateItems> and wrap it with any element.
This allows for more fine-grained styling and manipulation of container elements.

  • The .paginate-container class is no longer used.
<script>
-  import { Paginate } from '@jill64/svelte-pagination'
+  import { PaginateItems } from '@jill64/svelte-pagination'

  export let data

  $: ({ lastPage } = data)
</script>

+ <div>
-  <Paginate {lastPage} slug="[page=int]" />
+  <PaginateItems {lastPage} slug="[page=int]" />
+ </div>

License

MIT

2.1.15

10 days ago

2.1.14

26 days ago

2.1.13

1 month ago

2.1.12

1 month ago

2.1.11

2 months ago

2.1.10

2 months ago

2.1.9

2 months ago

2.1.8

3 months ago

2.1.7

3 months ago

2.1.6

3 months ago

2.1.5

4 months ago

2.1.4

4 months ago

2.1.3

4 months ago

2.1.2

5 months ago

2.1.1

5 months ago

2.1.0

5 months ago

2.0.0

5 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

7 months ago

1.0.0

7 months ago

0.1.26

7 months ago

0.1.25

7 months ago

0.1.24

7 months ago

0.1.23

7 months ago

0.1.22

7 months ago

0.1.21

7 months ago

0.1.20

7 months ago

0.1.19

7 months ago

0.1.18

7 months ago

0.1.17

7 months ago

0.1.16

7 months ago

0.1.15

7 months ago

0.1.14

7 months ago

0.1.13

7 months ago

0.1.12

7 months ago

0.1.11

7 months ago

0.1.10

7 months ago

0.1.9

7 months ago

0.1.8

7 months ago

0.1.7

7 months ago

0.1.6

7 months ago

0.1.5

8 months ago

0.1.3

8 months ago

0.1.2

8 months ago

0.1.1

8 months ago

0.1.0

8 months ago