Pagination
Navigation component for dividing content across multiple pages with intuitive controls for users to navigate through large datasets efficiently.
Features
- Page navigation - Previous, next, and direct page access
- Flexible display - Show/hide page numbers based on space
- Size indicators - Items per page and total count
- Keyboard accessible - Full keyboard navigation support
- Responsive design - Adapts to different screen sizes
Installation
pnpm add @helgadigitals/vera-uinpm install @helgadigitals/vera-uiyarn add @helgadigitals/vera-uiUsage
Basic Pagination
Showing 21-30 of 100 items
import { Pagination } from "@helgadigitals/vera-ui";import { useState } from "react";function BasicPaginationExample() { const [currentPage, setCurrentPage] = useState(3); const [pageSize, setPageSize] = useState(10); const totalItems = 100; return ( <div className="space-y-4"> <div className="text-sm text-muted-foreground"> Current page: {currentPage} of {Math.ceil(totalItems / pageSize)} </div> <Pagination currentPage={currentPage} totalPages={Math.ceil(totalItems / pageSize)} onPageChange={setCurrentPage} totalItems={totalItems} pageSize={pageSize} onPageSizeChange={setPageSize} /> </div> );}Simple Pagination
Showing 1-10 of 50 items
import { Pagination } from "@helgadigitals/vera-ui";import { useState } from "react";function SimplePaginationExample() { const [currentPage, setCurrentPage] = useState(1); const [pageSize, setPageSize] = useState(10); const totalItems = 50; return ( <Pagination currentPage={currentPage} totalPages={Math.ceil(totalItems / pageSize)} onPageChange={setCurrentPage} totalItems={totalItems} pageSize={pageSize} onPageSizeChange={setPageSize} showFirstLast={false} /> );}Large Dataset Pagination
Showing 481-500 of 1000 items
import { Pagination } from "@helgadigitals/vera-ui";import { useState } from "react";function LargePaginationExample() { const [currentPage, setCurrentPage] = useState(25); const [pageSize, setPageSize] = useState(20); const totalItems = 1000; return ( <div className="space-y-4"> <div className="text-sm text-muted-foreground"> Large dataset example - {totalItems} total items </div> <Pagination currentPage={currentPage} totalPages={Math.ceil(totalItems / pageSize)} onPageChange={setCurrentPage} totalItems={totalItems} pageSize={pageSize} onPageSizeChange={setPageSize} pageSizeOptions={[10, 20, 50, 100]} /> </div> );}Interactive Pagination with Data
Sample Data
Showing 1-5 of 250 items
import { Pagination } from "@helgadigitals/vera-ui";import { useState } from "react";function InteractivePaginationExample() { const [currentPage, setCurrentPage] = useState(1); const [pageSize, setPageSize] = useState(5); const [isLoading, setIsLoading] = useState(false); const totalItems = mockData.length; const handlePageChange = (page: number) => { setIsLoading(true); setTimeout(() => { setCurrentPage(page); setIsLoading(false); }, 500); // Simulate loading }; const handlePageSizeChange = (size: number) => { setIsLoading(true); setTimeout(() => { setPageSize(size); setCurrentPage(1); // Reset to first page setIsLoading(false); }, 300); }; // Get current page data const startIndex = (currentPage - 1) * pageSize; const currentData = mockData.slice(startIndex, startIndex + pageSize); return ( <div className="space-y-4"> {/* Data Display */} <div className="border rounded-lg"> <div className="p-4 border-b bg-muted/50"> <h4 className="font-semibold">Sample Data</h4> </div> <div className="p-4"> {isLoading ? ( <div className="flex items-center justify-center py-8"> <div className="flex items-center gap-2 text-muted-foreground"> <div className="animate-spin rounded-full h-4 w-4 border-2 border-primary border-t-transparent"></div> <span>Loading...</span> </div> </div> ) : ( <div className="grid gap-3"> {currentData.map((item) => ( <div key={item.id} className="flex justify-between items-center p-2 border rounded"> <div> <span className="font-medium">{item.name}</span> <span className="text-muted-foreground ml-2">({item.category})</span> </div> <span className="font-semibold">${item.price}</span> </div> ))} </div> )} </div> </div> {/* Pagination */} <Pagination currentPage={currentPage} totalPages={Math.ceil(totalItems / pageSize)} onPageChange={handlePageChange} totalItems={totalItems} pageSize={pageSize} onPageSizeChange={handlePageSizeChange} pageSizeOptions={[5, 10, 20]} isFetching={isLoading} /> </div> );}Custom Page Sizes
Showing 1-25 of 500 items
import { Pagination } from "@helgadigitals/vera-ui";import { useState } from "react";function CustomSizesPaginationExample() { const [currentPage, setCurrentPage] = useState(1); const [pageSize, setPageSize] = useState(25); const totalItems = 500; return ( <div className="space-y-4"> <div className="text-sm text-muted-foreground"> Custom page size options for different use cases </div> <Pagination currentPage={currentPage} totalPages={Math.ceil(totalItems / pageSize)} onPageChange={setCurrentPage} totalItems={totalItems} pageSize={pageSize} onPageSizeChange={(size) => { setPageSize(size); setCurrentPage(1); // Reset to first page when changing size }} pageSizeOptions={[25, 50, 100, 200]} siblingsCount={2} // Show more page numbers /> </div> );}Minimal Pagination
Showing 1-10 of 30 items
import { Pagination } from "@helgadigitals/vera-ui";import { useState } from "react";function MinimalPaginationExample() { const [currentPage, setCurrentPage] = useState(1); const [pageSize, setPageSize] = useState(10); const totalItems = 30; return ( <div className="space-y-4"> <div className="text-sm text-muted-foreground"> Minimal pagination for small datasets </div> <Pagination currentPage={currentPage} totalPages={Math.ceil(totalItems / pageSize)} onPageChange={setCurrentPage} totalItems={totalItems} pageSize={pageSize} onPageSizeChange={setPageSize} showFirstLast={false} siblingsCount={0} // Only show current page pageSizeOptions={[5, 10, 15]} /> </div> );}API Reference
Pagination
Main pagination component with navigation controls.
Prop
Type
Use Cases
Data Tables
- Search results - Navigate through search results
- User lists - Browse user directories
- Product catalogs - Browse product listings
- Report data - Navigate through report entries
Content Lists
- Blog posts - Navigate through article archives
- News articles - Browse news content
- Gallery images - Navigate image collections
- Comment threads - Browse comment pages
Admin Panels
- Management interfaces - Navigate administrative data
- Analytics dashboards - Browse metric pages
- Content management - Navigate content lists
- User administration - Browse user accounts
E-commerce
- Product listings - Navigate product categories
- Order history - Browse past orders
- Inventory management - Navigate stock items
- Customer lists - Browse customer data
Accessibility
The Pagination component follows accessibility best practices:
- Keyboard navigation - Arrow keys and Tab navigation
- Screen reader support - Proper ARIA labels and descriptions
- Focus management - Clear focus indicators
- Semantic markup - Uses appropriate HTML elements
Best Practices
- Show context - Display current page and total pages
- Provide page size options - Let users control how much they see
- Maintain state - Remember user's page and size preferences
- Handle loading states - Show loading indicators during navigation
- Responsive design - Adapt to different screen sizes
Related Components
DataTable
A feature-rich data table component that provides advanced functionality for displaying and interacting with tabular data. Includes built-in support for sorting, filtering, pagination, row selection, custom actions, and responsive design.
Progress
A visual progress indicator component for showing completion percentage, loading states, and task progress. Built on Radix UI with smooth animations and accessibility features.