1.2.4 • Published 12 months ago

react-listing-pagination v1.2.4

Weekly downloads
-
License
ISC
Repository
github
Last release
12 months ago

React Listing and Paginating

NPM  

NPM version NPM downloads Issues need help

Live demo

✨ Features

  • 📦 flixible to customize and injecting components.
  • 🛡 Written in TypeScript with predictable static types.
  • ⚙️ loader and content loading.
  • 🎨 simple and easy styles that can be overwritten.
  • ♊ RTL support.

🖥 Environment Support

  • Modern browsers and Internet Explorer 11
IE / EdgeFirefoxChromeSafari
IE11, Edgelast 2 versionslast 2 versionslast 2 versions

📦 Install

npm install --save react-listing-pagination
yarn add react-listing-pagination

🔨 Usage

using items displayer which works with flexbox (rows, cols) along with paginator

import { useState } from 'react';
import { Listing, Pagination } from 'react-listing-pagination';

const CustomComponent = () => {
  const [totalPages, setTotalPages] = useState(1000);
  const [currentPage, setCurrentPage] = useState(1);
  const itemsPerPage = 20;
  const [items, setItems] = useState<any>([]);

  return (
    <>
      <Listing
        items={items}
        display={'Grid'}
        numberOfItemsPerRow={2}
        isLoading={false}
        loader={'ContentLoader'}
        styles={{
          itemClass: 'd-flex justify-content-center',
        }}
      >
          <Pagination
            totalItems={totalPages}
            itemsPerPage={itemsPerPage}
            currentPage={parseInt(currentPage.toString())}
            displayedNumbersCount={6}
            onPageChange={(pageNumber: number) => {
              console.log(pageNumber);
            }}
            OnPreBtnClick={(pageNumber: number) => {
              console.log(pageNumber);
            }}
            OnNextBtnClick={(pageNumber: number) => {
              console.log(pageNumber);
            }}
            previousBtnContent={
              <div className='d-flex font-gull-grey mt-0'>
                <BsArrowLeft
                  size={20}
                  className={'arrow-pagination arrow-icon'}
                />
                <div>
                  {intl.formatMessage({ id: 'global.pagination.previous' })}
                </div>
              </div>
            }
            nextBtnContent={
              <div className='d-flex font-gull-grey mt-0'>
                <div>
                  {intl.formatMessage({ id: 'global.pagination.next' })}
                </div>
                <BsArrowRight
                  size={20}
                  className={'arrow-pagination arrow-icon'}
                />
              </div>
            }
            styles={{
              position: 'center',
              numberBtnClass: `px-3 ${BtnStyles['button-light']} mx-1`,
              activeBtnClass: `${'active-button'} mx-1`,
            }}
          />
      </Listing>
    </>
  );
};

or you can only use the paggination logic

import { useState } from 'react';
import { Pagination } from 'react-listing-pagination';

const CustomComponent = () => {
  return (
    <>
      <Pagination
        totalPages={200}
        currentPage={1}
        displayedNumbersCount={6}
        onPageChange={(pageNumber: number) => {
          console.log("current page is " + pageNumber);
        }}
        firstBtnContent={"first"}
        firstBtnProps={{
          title: "First page",
        }}
        lastBtnContent={"last"}
        lastBtnProps={{
          title: "Last page",
        }}
        previousBtnContent={"previous"}
        previousBtnProps={{
          title: "Previous page",
        }}
        nextBtnContent={"next"}
        nextBtnProps={{
          title: "Next page",
        }}
        styles={{
          position: "center",
          numberBtnClass: "btn-primary",
        }}
      />
    </>
  );
};

RTL suport

simply by adding dir prop to html tag the package with switch to rtl.

<html dir="rtl">
<Pagination/>
</html>
<html dir="ltr">
<Pagination/>
</html>

TypeScript

this package is written in TypeScript, check Use in TypeScript to get started.

listing Props

PropTypeRequiredDescription
childrenReact Nodefalseshould be paginating component as a child.
itemsArray of React Nodetruean array of components to be displayed.
numberOfItemsPerRowNumberfalsenumber of items each row it only available in display Grid.
displayGrid , Rowsfalseitems displaying style / default Grid.
isLoadingBooleanfalseused for loading time / default false.
loaderReact Node , 'ContentLoader'falseplaceholder for items (ContentLoader for prebuilt loader).
headerReact Nodefalseheader.
footerLeftActionsReact Nodefalseleft section next to children.
footerRightActionsReact Nodefalseright section next to children.
stylesObjectfalsecontains classes for styling different sections.

listing Styles Object

PropTypeRequiredDescription
containerClass'start' , 'center' , 'end'falsepositioning buttons horizontally.
headerClassstringfalsebuttons wrapper css class.
itemClassstringfalsenext button css class.
footerClassstringfalseprevious button css class.

Paginating Props

PropTypeRequiredDescription
currentPageNumbertruecurrent page number.
totalPagesNumbertrue (if totalItems & itemsPerPage are not assigned)number of total pages.
totalItemsNumbertrue (if totalPages is not assigned)number of total items.
itemsPerPageNumbertrue (if totalPages is not assigned)number of displayed items per page.
displayedNumbersCountNumberfalsenumber of displayed pagination buttons to be shown. /default 6 (important!! this number doesn't include gap property buttons count)
previousBtnContentstring or React Nodefalsecontent for previous button.
nextBtnContentstring or React Nodefalsecontent for next button.
firstBtnContentstring or React Nodefalsecontent for first button.
lastBtnContentstring or React Nodefalsecontent for last button.
numbersGapBtnContentstring or React Nodefalsecontent for gap button whether to display numbers gap (...) to shortcut to first/last page or not.
numberBtnPropsHTML Button native propsdefaultsnative props of page number button.
previousBtnPropsHTML Button native propsdefaultsnative props of previous page button.
nextBtnPropsHTML Button native propsdefaultsnative props of next page button.
firstBtnPropsHTML Button native propsdefaultsnative props of first page button.
lastBtnPropsHTML Button native propsdefaultsnative props of last page button.
onPageChange(pageNumber) => voidfalseinvoked after current page changed.
onNumberBtnClick(pageNumber, event?) => voidfalseinvoked after clicking on a paginating number.
OnPreBtnClick(pageNumber, event?) => voidfalseinvoked after clicking on a paginating previous button.
OnNextBtnClick(pageNumber, event?) => voidfalseinvoked after clicking on a paginating next button.
OnFirstBtnClick(pageNumber, event?) => voidfalseinvoked after clicking on a paginating first button.
OnLastBtnClick(pageNumber, event?) => voidfalseinvoked after clicking on a paginating last button.
stylesObjectfalsecontains classes for styling different sections.

Paginating Styles Object

PropTypeRequiredDescription
position'start' , 'center' , 'end'falsepositioning buttons horizontally.
containerClassstringfalsebuttons wrapper css class.
numberBtnClassstringfalsepage number button css class.
nextBtnClassstringfalsenext button css class.
previousBtnClassstringfalseprevious button css class.
firstBtnClassstringfalsefirst button css class.
lastBtnClassstringfalselast button css class.
activeBtnClassstringfalseactive button css class.

🔗 Links