page-nav
Pagination: previous and next, the first and last page, and the pages around the current one, with gaps shown as "…". The current page is marked aria-current="page". page is two-way.
Try it: events appear here (pagechange).
Source: page-nav.zb, and its registry item.
Install
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/page-nav.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/page-nav.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/page-nav.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/page-nav.json
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/page-nav.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/page-nav.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/page-nav.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/page-nav.json
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/page-nav.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/page-nav.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/page-nav.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/page-nav.json
<link rel="stylesheet" href="https://zubra-js.github.io/zubra-ui/themes/default.css">
<script type="module" src="https://zubra-js.github.io/zubra-ui/cdn/page-nav.js"></script>The compiled install writes src/components/zubra/page-nav.js and the theme, and adds @zubra/runtime to your dependencies. The one-file install writes the same path as a plain custom element that needs nothing installed (or download it and load it with a <script type="module">); it's smaller on a page with one to three components, the shared runtime with more.
Usage
<page-nav></page-nav>
<script type="module">
import './components/zubra/page-nav.js';
const element = document.querySelector('page-nav');
element.page = 6;
element.pages = 20;
element.addEventListener('pagechange', (event) => console.log('pagechange', event.detail));
</script>import './components/zubra/page-nav.js';
const page = 6;
const pages = 20;
export function PageNavExample() {
return (
<page-nav
page={page}
pages={pages}
onpagechange={(event) => console.log('pagechange', event.detail)}
></page-nav>
);
}<script setup>
import './components/zubra/page-nav.js';
const page = 6;
const pages = 20;
const onPagechange = (event) => console.log('pagechange', event.detail);
</script>
<template>
<page-nav :page.prop="page" :pages.prop="pages" @pagechange="onPagechange"></page-nav>
</template>
<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) --><script>
import './components/zubra/page-nav.js';
const page = 6;
const pages = 20;
</script>
<page-nav
{page}
{pages}
onpagechange={(event) => console.log('pagechange', event.detail)}
></page-nav>import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/page-nav.js';
@Component({
selector: 'app-page-nav-example',
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<page-nav [page]="page" [pages]="pages" (pagechange)="onPagechange($event)"></page-nav>
`,
})
export class PageNavExample {
page = 6;
pages = 20;
onPagechange(event: Event) {
console.log('pagechange', (event as CustomEvent).detail);
}
}API
| Property | Type | Default |
|---|---|---|
page | number | 1 |
pages | number | 1 |
siblings | number | 1 |
label | string | "Pages" |
| Event | When |
|---|---|
pagechange | Another page was chosen; detail is its number. |
Size
1.3 KB gzipped for the component, plus the runtime, which every Zubra component on a page shares (up to 22.1 KB, all of it). On its own, with the parts of the runtime it uses, it's 17.5 KB.