Updated
Pagination
NewCustomize
Total24
Siblings1
Boundaries1
Medium
Duration0.35s
Installation
npx shadcn@latest add https://uibrik.com/r/pagination.jsonInstall the packages
npm install @tabler/icons-react motionAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/pagination/pagination.tsx"use client"; import { useLayoutEffect, useRef, useState, type KeyboardEvent } from "react"; import { AnimatePresence, MotionConfig, motion } from "motion/react"; import { IconChevronLeft, IconChevronRight, IconDots } from "@tabler/icons-react"; import { cn } from "@/lib/utils"; // Pagination. The bar always shows the same number of slots, so it never // changes width as you move. The current-page pill slides from slot to slot, // and when the window of pages shifts, each slot's number rolls to its new // value digit by digit like an odometer, up when you go forward and down // when you go back, so you can see which way you moved. // // An ellipsis opens into a small field: type a page and press Enter to jump. // In a narrow container the slots give way to a rolling "3 / 20". export type PaginationProps = { /** Number of pages. */ total: number; /** Current page, from 1 (controlled). Pair with `onPageChange`. */ page?: number; /** Page on mount (uncontrolled). */ defaultPage?: number; onPageChange?: (page: number) => void;
Adds the files to
components/uibrik/pagination and installs @tabler/icons-react and motion. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/pagination.Usage
import { Pagination } from "@/components/uibrik/pagination/pagination";<Pagination total={24} siblings={1} boundaries={1} jump size="md" duration={0.35} defaultPage={6} label="Pagination" // page={0} // onPageChange={(page) => {}}/>Where to use Pagination
Tables and search results
Pagination that never changes width keeps buttons under the pointer as pages change.
Pairs with Data Table
Blog and product listings
Numbers rolling like an odometer when the window shifts make long ranges clear.
Large admin lists
An ellipsis opening into a jump-to-page field reaches page 40 without clicking 40 times.
Props
Pagination- total
- Type number
- 24
- Number of pages.
- siblings
- Type number
- 1
- Pages shown either side of the current one.
- boundaries
- Type number
- 1
- Pages always shown at each end.
- jump
- Type boolean
- true
- An ellipsis opens a field to type a page into.
- size
- Type "sm" | "md" | "lg"
- "md"
- Height and text size.
- duration
- Type number
- 0.35
- How long the pill and the numbers take to move.
- page / onPageChange
- Type number / (page) => void
- –
- Controlled current page, from 1.
- defaultPage
- Type number
- 1
- Page on mount when uncontrolled.
- label
- Type string
- "Pagination"
- Names the navigation for screen readers.
- className
- Type string
- –
- Classes for the nav. It fills its container and switches to a compact "3 / 20" below 352px.