2.0.1 • Published 8 months ago

react-pagination-with-dots v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

react-pagination-with-dots

\"react-pagination-with-dots\" is a highly customizable and responsive pagination library designed for React applications. This package enables easy integration of pagination in your projects, allowing you to create dynamic and paginated lists with minimal effort. Whether you're dealing with large datasets or creating a simple paginated data grid, this React Pagination Package offers flexibility and simplicity.

With full control over pagination navigation, customizable labels, and support for React Hooks, this pagination UI component allows you to seamlessly paginate and manage data in any React-based application. Ideal for developers looking to build responsive pagination components that adapt to various layouts and devices.

Use this library to add powerful and intuitive pagination features to your React project, enhancing the user experience and improving data accessibility with easy React pagination.

Demo

DEMO

Installation

Install my-project with npm

npm i react-pagination-with-dots

Usage/Examples Pagination using API

import "react-pagination-with-dots/dist/index.css";
import Pagination  from "react-pagination-with-dots";
function App() {
  const [currentPage, setCurrentPage] = useState<number>(1);
  return (
    <Pagination
      totalPages={20} // from api
      currentPage={currentPage}
      setCurrentPage={setCurrentPage}
      paginationStyleType={"box"} // box or default
      breakLabel={"..."}
    />
  );
}

export default App;

// if api don't send totalPages then use this

import "react-pagination-with-dots/dist/index.css";
import Pagination  from "react-pagination-with-dots";
function App() {
  const [currentPage, setCurrentPage] = useState<number>(1);
  return (
    <Pagination
      totalData={pass data length} //form api
      limit={32}
      currentPage={currentPage}
      setCurrentPage={setCurrentPage}
      paginationStyleType={"box"} // box or default
        breakLabel={"..."}
    />
  );
}

export default App;

Usage/Examples Pagination using list of data

import "react-pagination-with-dots/dist/index.css";
import Pagination from "react-pagination-with-dots";

const books = [
  { id: 1, title: "Book 1" },
  { id: 2, title: "Book 2" },
  { id: 3, title: "Book 3" },
  { id: 4, title: "Book 4" },
  { id: 5, title: "Book 5" },
  { id: 6, title: "Book 6" },
  { id: 7, title: "Book 7" },
  { id: 8, title: "Book 8" },
  { id: 9, title: "Book 9" },
  { id: 10, title: "Book 10" },
  // Add more books here as needed
];
function App() {
  const [currentPage, setCurrentPage] = useState(1);
  const [data, setData] = useState(books);
  return (
    <div>
      <h1>Books</h1>
      <ul>
        {data.map((book) => (
          <li key={book.id}>{book.title}</li>
        ))}
      </ul>
      <Pagination
        data={books}
        setData={setData}
        limit={5}
        currentPage={currentPage}
        setCurrentPage={setCurrentPage}
        paginationStyleType={"box"} // box or default
          breakLabel={"..."}
      />
    </div>
  );
}

export default App;

Package Customization

Property nameTypeDefaultDescription
currentPagevariablecurrentPagePass useState variable to control the current page
setCurrentPagefunctionfunctionPass useState function to update the current page
totalPagesvariable0Required if using API data; must be a number
totalDatavariable0Use this if the API doesn't provide totalPages
breakLabelstring...Pass any string as the break label
dataarray[]Pass an array of data if using local/demo data
setDatafunctionfunctionPass useState function to update the data
activeClassstringactiveClassCSS class for the active page item
paginationClassstringpaginationClassCSS class for the pagination container
paginationItemClassstringpaginationItemClassCSS class for individual pagination items
disabledClassstringdisabledClassCSS class for disabled pagination buttons
breakLabelClassstringbreakLabelClassCSS class for the pagination break label
buttonClassstringbuttonClassCSS class for pagination buttons
prevClassstringprevClassCSS class for the previous button
nextClassstringnextClassCSS class for the next button
prevstring or React componentprevCustomize the content of the previous button
nextstring or React componentnextCustomize the content of the next button
limitnumber10Number of items per page if using local/demo data
paginationStyleTypestringdefaultPagination style, either "default" or "box"

Hi, I'm Rayan Hossain! 👋

🚀 About Me

Passionate MERN Stack Developer || Building Innovative Web Solutions with MongoDB || Express JS || React JS || Next JS || Node.js || Mentor

🔗 Links

github linkedin

License

This software is free to use under the MIT license. See the LICENSE file for license text and copyright information.