Paginators

Navigate between multiple pages of content.

javascript
import { Paginator } from '@brainandbones/skeleton';

Examples

List Pagination



1 to 5 of 10

Table Pagination

Positions Name Weight Symbol
1Hydrogen1.0079H
2Helium4.0026He
3Lithium6.941Li
4Beryllium9.0122Be
5Boron10.811B

1 to 5 of 10

Usage

typescript
const page: any = {
    offset: 0,
    limit: 5,
    size: source.length
    amounts: [1,2,5,10],
};
typescript
function onPageChange(e: any): void { console.log('event:page', e.detail); }
function onAmountChange(e: any): void { console.log('event:amount', e.detail); }
html
<Paginator
    bind:offset={page.offset}
    bind:limit={page.limit}
    bind:size={page.size}
    bind:amounts={page.amounts}
    on:page={onPageChange}
    on:amount={onAmountChange}
></Paginator>

Utilizing Pagination

Once your paginator component is setup you'll need to limit your content. This can be accomplished with the JavaScript slice method. See a minimal example below.

typescript
const source: any[] = [ /* any array of objects */ ]
typescript
$: sourcePaginated = source.slice(
    page.offset * page.limit, // start
    page.offset * page.limit + page.limit // end
);
html
<ul>
    {#each sourcePaginated as row}
    <li>{row}</li>
    {/each}
</ul>

Properties

Prop Type Default Description
offsetnumber0Index of the first list item to display.
limitnumber5Current number of items to display.
sizenumber10The total size (length) of your source content.
amountsnumber[][1,5,10,50,100]List of amounts available to the select input.
Prop Type Default Description
justifystringjustify-betweenProvide classes to set flexbox justification.
textstringtext-xsProvide classes to style page context text.
selectstring-Provide arbitrary classes to style the select input.
buttonsstringbtn-ghostProvide any desired Button element classes.

Events

Name Description
amountFires when the amount selection input changes. Provides the selected amount value.
pageFires when the next/back buttons are pressed. Provides the new offset value.