Socket
Socket
Sign inDemoInstall

react-pagination-bar

Package Overview
Dependencies
3
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-pagination-bar

Functional page navigation bar for react


Version published
Weekly downloads
227
decreased by-17.45%
Maintainers
1
Install size
61.5 kB
Created
Weekly downloads
 

Readme

Source

RPB Logo

React Pagination Bar

Lightweight component for pagination of application pages on react

Demo

Content

Features

  • Customizing class names without using style overrides
  • Multiple pagination display modes.
  • Accessible. React Pagination Bar follow the WAI-ARIA guidelines specifications. and have the right aria-* attributes.
  • Lightweight :P

Getting started

Install the library using one of these commands:

$ npm i react-pagination-bar

# or

$ yarn add react-pagination-bar

Usage

To start using the library, add import Pagination and place the component in your code. If you are not going to customize the styles of the component, don't forget to add the default styles:

import 'react-pagination-bar/dist/index.css'

Simple usage without react-router-dom:

import { Pagination } from "react-pagination-bar"
import 'react-pagination-bar/dist/index.css'

const posts = [
  { id: 1, title: 'Post 1' },
  { id: 2, title: 'Post 2' },
  { id: 3, title: 'Post 3' },
  { id: 4, title: 'Post 4' },
  { id: 5, title: 'Post 5' },
  { id: 6, title: 'Post 6' },
  { id: 7, title: 'Post 7' },
  { id: 8, title: 'Post 8' },
  { id: 9, title: 'Post 9' },
  { id: 10, title: 'Post 10' },
  { id: 11, title: 'Post 11' },
  { id: 12, title: 'Post 12' },
];

export const App = () => {
  const [currentPage, setCurrentPage] = useState(1);
  const pagePostsLimit = 3;

  return (
    <div className="App">
      {posts
        .slice((currentPage - 1) * pagePostsLimit, currentPage * pagePostsLimit)
        .map((post) => <div key={post.id}>{post.title}</div>)}
      <Pagination
        currentPage={currentPage}
        itemsPerPage={pagePostsLimit}
        onPageChange={(pageNumber) => setCurrentPage(pageNumber)}
        totalItems={posts.length}
        pageNeighbours={2}
      />
    </div>
  );
};

Props

Prop nameTypeDefault valueDescriptionRequired
totalItemsNumberNoneTotal number of items on the server.Yes
onPageChange((pageNumber: number) => void)NoneCallback triggered on page change.Yes
currentPageNumber1Page number to be shown first. Be sure to synchronize the value with the server if you work with routing!Yes
itemsPerPageNumber10The number of items to display on your page. Be sure to synchronize the value with the server if you work with routing!Yes
startLabelString'<<'The text of the button that sends to the first page.No
endLabelString'>>'The text of the button that sends to the last page.No
prevLabelString'<'The text of the button that sends to the previous page.No
nextLabelString'>'The text of the button that sends to the next page.No
pageNeighboursNumber4The number of pages displayed next to the currently selected.No
withProgressBarBooleanfalseShows the progress bar under pagination.No
onlyPageNumbersBooleanfalseRemoves buttons and leaves only pages.No
onlyPaginationButtonsBooleanfalseRemoves pages leaves only buttons.No
withGoToInputBooleanfalseShows the input field to go to the page.No
customClassNamesObject*Take a look at the example with component customization*Replaces default class names.No

Upgrading from v1 to v2

  1. Use currentPage instead initialPage
  2. Update your onPageChange to onPageChange (fixed C letter from Cyrillic to Latin)
  3. Add itemsPerPage if you haven't already
  4. Remove withDebug if you have added it

More examples

Coming soon...

License

MIT © Ilya Sokol

Keywords

FAQs

Last updated on 04 Aug 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc