Pagination
An a navigation list of page numbers.
Code
<script lang="ts">
import { Pagination } from '@geoffcox/sterling-svelte';
let itemRange : {index: number; count: number} = $state();
let page : number = $state();
let pageCount : number = $state();
</script>
<Pagination itemCount="163" bind:itemRange bind:page bind:pageCount pageSize="7" pageStep="5" />
Members
| Property Name | Type | Default | Comment |
---|
| itemCount | number | 0 |
| itemRange | $bindable({index: number; count: number;}) | undefined |
| page | $bindable(number) | 0 |
| pageCount | $bindable(number) | undefined |
| pageSize | number | undefined | 1 |
| pageStep | number | undefined | 10 |
| onChange | ((page: number, itemRange: {index: number; count: number;}) => void) | undefined | undefined |
| firstNumber | (Snippet<[number | undefined]>) | undefined | undefined |
| stepPreviousNumber | (Snippet<[number | undefined]>) | undefined | undefined |
| previousNumber | (Snippet<[number | undefined]>) | undefined | undefined |
| currentNumber | (Snippet<[number | undefined]>) | undefined | undefined |
| nextNumber | (Snippet<[number | undefined]>) | undefined | undefined |
| stepNextNumber | (Snippet<[number | undefined]>) | undefined | undefined |
| lastNumber | (Snippet<[number | undefined]>) | undefined | undefined |
Considerations
- Page numbers are positioned in the following order: first, step-previous, previous, current, next, step-next, last.
- The previous, next, step-previous, and step-next buttons support holding down the mouse button to continuously move.
- Page numbers are evenly spaced based on the number of digits in itemCount.
- Includes HTMLDivElement props, events, and methods.
Anatomy
<div class="sterling-pagination">
<div class="page-number first">
<button>
{@render pageNumber(firstNumber, 'first')}
</button>
</div>
<div class="page-number step-previous">
<button>
{@render pageNumber(stepPreviousNumber, 'step-previous')}
</button>
</div>
<div class="page-number previous">
<button>
{@render pageNumber(previousNumber, 'previous')}
</button>
</div>
<div class="page-number current">
<button>
{@render pageNumber(currentNumber, 'current')}
</button>
</div>
<div class="page-number next">
<button>
{@render pageNumber(nextNumber, 'next')}
</button>
</div>
<div class="page-number step-next">
<button>
{@render pageNumber(stepNextNumber, 'step-next')}
</button>
</div>
<div class="page-number last">
<button>
{@render pageNumber(lastNumber, 'last')}
</button>
</div>
</div>