Command Palette

Search for a command to run...

Docs
Sliding Pagination

Sliding Pagination

Pagination component with sliding underline indicator and smart page grouping

Loading...

Installation

Usage

import SlidingPagination from "@/components/ruixen/sliding-pagination";
import { useState } from "react";
 
export default function App() {
  const [page, setPage] = useState(1);
 
  return (
    <SlidingPagination
      totalPages={120}
      currentPage={page}
      onPageChange={setPage}
      maxVisiblePages={9}
    />
  );
}

Props

PropTypeDefaultDescription
totalPagesnumber-Total number of pages
currentPagenumber-Current active page
onPageChangefunction-Callback when page changes
maxVisiblePagesnumber7Maximum page buttons before adding ellipsis
classNamestring""Additional CSS classes

Features

  • Sliding Underline: Animated underline follows active page
  • Smart Ellipsis: Shows "..." when there are gaps in page numbers
  • Responsive Layout: Adjusts visible pages based on current position
  • Spring Animation: Smooth underline movement with spring physics
  • Auto-measuring: Automatically measures button positions

Page Generation Logic

  • Shows first and last page when possible
  • Centers visible pages around current page
  • Adds ellipsis (...) when there are gaps
  • Maintains consistent spacing and alignment