Synertech Web/ui v0.57.5 Site Storybook

Documentation / Navigation & actions

Pagination

Client@synertech/uiOpen in Storybook

Navigation between the pages of a list: previous / next, page numbers with ellipses when there are too many, and optionally first / last, the total number of items and a choice of rows per page.

The component is always controlled: it receives page and totalPages and reports changes through onPageChange (never called for the page that is already active, nor out of bounds). siblings and boundaries set how many numbers stay visible around the current page and at both ends. The active page carries aria-current="page"; the arrows’ accessible labels are translated through labels. A client component ("use client").

Examples

Basic usage

The current page lives in the application state; the component only offers it.

Open in a tab
import { useState } from "react";
import { Pagination } from "@synertech/ui";

const frenchLabels = {
  first: "Première page",
  previous: "Page précédente",
  next: "Page suivante",
  last: "Dernière page",
};

export function Basic() {
  const [page, setPage] = useState(1);

  return <Pagination page={page} totalPages={10} onPageChange={setPage} labels={frenchLabels} />;
}

Many pages

showFirstLast adds jumps to both ends; siblings widens the window around the page.

Open in a tab
import { useState } from "react";
import { Pagination } from "@synertech/ui";

const frenchLabels = {
  first: "Première page",
  previous: "Page précédente",
  next: "Page suivante",
  last: "Dernière page",
};

export function ManyPages() {
  const [page, setPage] = useState(24);

  return (
    <Pagination
      page={page}
      totalPages={50}
      onPageChange={setPage}
      showFirstLast
      siblings={2}
      labels={frenchLabels}
    />
  );
}

Sizes and styles

size sets the button size; variant switches to outlined or minimal.

Open in a tab
import { useState } from "react";
import { Pagination } from "@synertech/ui";

const frenchLabels = {
  first: "Première page",
  previous: "Page précédente",
  next: "Page suivante",
  last: "Dernière page",
};

export function Variants() {
  const [page, setPage] = useState(3);

  return (
    <div className="space-y-4">
      <Pagination
        page={page}
        totalPages={8}
        onPageChange={setPage}
        size="sm"
        variant="minimal"
        labels={frenchLabels}
      />
      <Pagination
        page={page}
        totalPages={8}
        onPageChange={setPage}
        variant="outlined"
        labels={frenchLabels}
      />
      <Pagination
        page={page}
        totalPages={8}
        onPageChange={setPage}
        size="lg"
        labels={frenchLabels}
      />
    </div>
  );
}

Below a table

totalItems and pageSize show the visible range; pageSizeOptions lets the reader change it.

Open in a tab
import { useState } from "react";
import { Pagination } from "@synertech/ui";

const frenchLabels = {
  first: "Première page",
  previous: "Page précédente",
  next: "Page suivante",
  last: "Dernière page",
};

export function WithPageSize() {
  const totalItems = 237;
  const [page, setPage] = useState(1);
  const [pageSize, setPageSize] = useState(25);
  const totalPages = Math.ceil(totalItems / pageSize);

  return (
    <Pagination
      page={page}
      totalPages={totalPages}
      onPageChange={setPage}
      totalItems={totalItems}
      pageSize={pageSize}
      pageSizeOptions={[10, 25, 50, 100]}
      onPageSizeChange={(size) => {
        setPageSize(size);
        setPage(1);
      }}
      labels={frenchLabels}
    />
  );
}

While loading

disabled freezes all navigation until the requested page arrives.

Open in a tab
import { useState } from "react";
import { Pagination } from "@synertech/ui";

const frenchLabels = {
  first: "Première page",
  previous: "Page précédente",
  next: "Page suivante",
  last: "Dernière page",
};

export function WhileLoading() {
  const [page, setPage] = useState(2);
  const [loading, setLoading] = useState(false);

  const changePage = (next: number) => {
    setLoading(true);
    setTimeout(() => {
      setPage(next);
      setLoading(false);
    }, 800);
  };

  return (
    <Pagination
      page={page}
      totalPages={12}
      onPageChange={changePage}
      disabled={loading}
      labels={frenchLabels}
    />
  );
}

API reference

Components

Pagination

ComponentClient
import { Pagination } from "@synertech/ui";

Props — PaginationProps

PropTypeDefaultDescription
onPageChange• (page: number) => void —
page• number —
totalPages• number —
boundaries number 1
disabled boolean false
labels { first?: string; previous?: string; next?: string; last?: string; } & UILabelsOf<"pagination"> —

The strings the pagination writes itself, for this instance. first, previous, next and last name the four navigation buttons; any pagination… key of UILabels is taken too. Wins over UILabelsProvider.

onPageSizeChange (size: number) => void —
pageSize number —
pageSizeOptions number[] —
showFirstLast boolean false
siblings number 1
size "sm" | "md" | "lg" "md"
totalItems number —
variant "default" | "outlined" | "minimal" "default"

+ 278 inherited native attributes from HTMLAttributes, AriaAttributes, DOMAttributes (className, id, aria-*, event handlers…).