Paginators
Navigate between multiple pages of content.
import { Paginator } from '@brainandbones/skeleton';
Examples
List Pagination
1 to 5 of 10
Table Pagination
Positions | Name | Weight | Symbol |
---|---|---|---|
1 | Hydrogen | 1.0079 | H |
2 | Helium | 4.0026 | He |
3 | Lithium | 6.941 | Li |
4 | Beryllium | 9.0122 | Be |
5 | Boron | 10.811 | B |
1 to 5 of 10
Usage
const page: any = {
offset: 0,
limit: 5,
size: source.length
amounts: [1,2,5,10],
};
function onPageChange(e: any): void { console.log('event:page', e.detail); }
function onAmountChange(e: any): void { console.log('event:amount', e.detail); }
<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.
const source: any[] = [ /* any array of objects */ ]
$: sourcePaginated = source.slice(
page.offset * page.limit, // start
page.offset * page.limit + page.limit // end
);
<ul>
{#each sourcePaginated as row}
<li>{row}</li>
{/each}
</ul>
Properties
Prop | Type | Default | Description |
---|---|---|---|
offset | number | 0 | Index of the first list item to display. |
limit | number | 5 | Current number of items to display. |
size | number | 10 | The total size (length) of your source content. |
amounts | number[] | [1,5,10,50,100] | List of amounts available to the select input. |
Prop | Type | Default | Description |
---|---|---|---|
justify | string | justify-between | Provide classes to set flexbox justification. |
text | string | text-xs | Provide classes to style page context text. |
select | string | - | Provide arbitrary classes to style the select input. |
buttons | string | btn-ghost | Provide any desired Button element classes. |
Events
Name | Description |
---|---|
amount | Fires when the amount selection input changes. Provides the selected amount value. |
page | Fires when the next/back buttons are pressed. Provides the new offset value. |