Reticle@etched/reticle 0.0.0

Pagination

Moves through the pages of a long list. Shows which items are on screen and the current page.

Kumo source
26–50 of 284
import { useState } from "react";
import { Pagination } from "@etched/reticle/pagination";

export function Preview() {
  const [page, setPage] = useState(2);

  return <Pagination aria-label="Runs pages" page={page} setPage={setPage} controls="simple" totalCount={284} />;
}

Installation

import { Pagination } from "@etched/reticle/pagination";

Examples

First page

1–25 of 284
import { useState } from "react";
import { Pagination } from "@etched/reticle/pagination";

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

  return <Pagination aria-label="Runs pages" page={page} setPage={setPage} totalCount={284} />;
}

Middle page

126–150 of 284
import { useState } from "react";
import { Pagination } from "@etched/reticle/pagination";

export function MiddlePage() {
  const [page, setPage] = useState(6);

  return <Pagination aria-label="Lots pages" page={page} setPage={setPage} totalCount={284} />;
}

Last page

276–284 of 284
import { useState } from "react";
import { Pagination } from "@etched/reticle/pagination";

export function LastPage() {
  const [page, setPage] = useState(12);

  return <Pagination aria-label="Benches pages" page={page} setPage={setPage} totalCount={284} />;
}

Single page

1–18 of 18
import { useState } from "react";
import { Pagination } from "@etched/reticle/pagination";

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

  return <Pagination aria-label="Sites pages" page={page} setPage={setPage} totalCount={18} />;
}

No results

0 results
import { useState } from "react";
import { Pagination } from "@etched/reticle/pagination";

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

  return <Pagination aria-label="Alerts pages" page={page} setPage={setPage} totalCount={0} />;
}

Page size

When the page size changes, go back to page 1.

1–25 of 1,284
Per page
import { useState } from "react";
import { Pagination } from "@etched/reticle/pagination";

export function PageSize() {
  const [page, setPage] = useState(1);
  const [perPage, setPerPage] = useState(25);

  return (
    <Pagination
      aria-label="Chips pages"
      page={page}
      setPage={setPage}
      perPage={perPage}
      totalCount={1284}
      setPerPage={(size) => {
        setPerPage(size);
        setPage(1);
      }}
    />
  );
}

Simple controls

26–50 of 140
import { useState } from "react";
import { Pagination } from "@etched/reticle/pagination";

export function SimpleControls() {
  const [page, setPage] = useState(2);

  return <Pagination aria-label="Owners pages" page={page} setPage={setPage} controls="simple" totalCount={140} />;
}

Unknown total

When the API gives no total, set hasNextPage. The controls are then always simple.

import { useState } from "react";
import { Pagination } from "@etched/reticle/pagination";

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

  return <Pagination aria-label="Events pages" page={page} setPage={setPage} hasNextPage={page < 3} />;
}

Disabled while loading

51–75 of 284
import { useState } from "react";
import { Pagination } from "@etched/reticle/pagination";

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

  return <Pagination aria-label="Probes pages" page={page} setPage={setPage} totalCount={284} disabled />;
}

API reference

PropTypeDefaultDescription
page *number–The current page, from 1.
setPage *(page: number) => void–Called with the page to show.
perPagenumber25Items on each page.
totalCountnumber–Items on all pages. When the API does not give a total, leave it out and set hasNextPage.
hasNextPagebooleanfalseWhether a next page exists. Used only without totalCount.
controls"full" | "simple""full"Without totalCount, controls are always "simple".
setPerPage(perPage: number) => void–Shows a page size select and is called with the new size. Usually also go back to page 1.
perPageOptionsreadonly number[][25, 50, 100, 250]Sizes in the page size select.
infoReactNode–Replaces the "26–50 of 284" text. null hides it.
disabledboolean–Disables every control, for example while a page loads.
aria-labelstring"Pagination"Name of the navigation landmark. Give each one on a screen its own name.
classNamestring–Class on the root, for layout.