Zubra UI
Code for
GitHub

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

Compiled (any project)
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
One file, no dependencies (3.3 KB gzipped)
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
.zb source (to edit it with Zubra)
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
No build: a script tag, straight from this site
HTML
<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

index.html
<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>
Example.jsx
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>
  );
}
Example.vue
<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('-') } } }) -->
Example.svelte
<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>
example.component.ts
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

Properties (each is also an HTML attribute of the same name, unless marked)
PropertyTypeDefault
pagenumber1
pagesnumber1
siblingsnumber1
labelstring"Pages"
Events
EventWhen
pagechangeAnother 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.

Theme

Every component reads shadcn/ui's CSS variables, so any shadcn theme works. Pick a look or a colour, or paste a theme's CSS.

Look: colours, fonts, corners and motion

Accent colour