ShakibDShy

Pagination

A versatile pagination component that provides both controlled and uncontrolled modes with extensive customization options.

Features

  • 🎨 Fully customizable styling with Tailwind CSS
  • 🔄 Controlled and uncontrolled modes
  • 📱 Responsive design
  • ♿ Accessible by default
  • 🔧 Extensive configuration options
  • 🔄 Server-side pagination support
  • 🔁 Loop mode for infinite navigation
  • 🎯 Custom boundaries and siblings

Usage

import { Pagination } from '@shakibdshy/react-pagination-pro';
 
function App() {
  return (
    <Pagination
      totalItems={100}
      defaultPageSize={10}
      onChange={({ currentPage, pageSize }) => {
        // Handle page change
      }}
    />
  );
}

Examples

Basic Usage

Basic Pagination

Simple pagination with default settings

Current Items: 10

function BasicExample() {
  const [currentItems, setCurrentItems] = useState(ITEMS.slice(0, 10));
 
  return (
    <Pagination
      totalItems={100}
      defaultPageSize={10}
      onChange={({ currentPage, pageSize }) => {
        const start = (currentPage - 1) * pageSize;
        const end = start + pageSize;
        setCurrentItems(ITEMS.slice(start, end));
      }}
    />
  );
}

API Reference

Props

PropTypeDefaultDescription
totalItemsnumberRequiredTotal number of items to paginate
defaultPageSizenumber10Number of items per page
currentPagenumber-Current page number (controlled mode)
defaultCurrentPagenumber1Initial page number (uncontrolled mode)
pageSizenumber-Items per page (controlled mode)
onChange(info: PaginationInfo) => void-Callback when page or size changes
mode'client' | 'server''client'Pagination mode
isDisabledbooleanfalseDisable all pagination controls
isDisabledPreviousbooleanfalseDisable previous button
isDisabledNextbooleanfalseDisable next button
isLoadingbooleanfalseShow loading state
isLoopbooleanfalseEnable infinite loop navigation
boundariesnumber1Number of boundary pages
siblingCountnumber1Number of sibling pages
size'sm' | 'md' | 'lg''md'Button size
variant'solid' | 'outline''solid'Button variant
color'primary' | 'secondary''primary'Button color
rounded'sm' | 'md' | 'lg' | 'full''md'Button border radius
previousIconReactNode<ChevronLeft />Custom previous button icon
nextIconReactNode<ChevronRight />Custom next button icon
dotsReactNode | string...Custom dots/ellipsis

Types

interface PaginationInfo {
  currentPage: number;
  pageSize: number;
  totalItems: number;
  totalPages: number;
  startIndex: number;
  endIndex: number;
  hasNextPage: boolean;
  hasPreviousPage: boolean;
}
 
interface PaginationProps extends React.ComponentProps<'div'> {
  // ... all props listed above
}

Last updated on

On this page