1.7.7 • Published 1 year ago

listing-pagination v1.7.7

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year 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 listing-pagination
yarn add listing-pagination

🔨 Usage

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

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

const CustomComponent = () => {
  const [totalPages, setTotalPages] = useState(1000);
  const [items, setItems] = useState<any>([]);

  return (
    <>
      <ListPagination
        items={items}
        display={'Grid'}
        numberOfItemsPerRow={2}
        isLoading={false}
        loader={'ContentLoader'}
        styles={{
          itemClass: 'd-flex justify-content-center',
        }}
      >
        <Pagination
          totalPages={totalPages}
          onChangePage={(pageNumber: number, event: any) => { console.log('current page is ' + pageNumber)}}
          currentPage={1}
          itemsPerPage={20}
          displayedNumbersCount={6}
          hasFirstLast={true}
          hasNextPrevious={true}
          firstBtnProps={{
            title: 'First page',
          }}
          lastBtnProps={{
            title: 'Last page',
          }}
          previousBtnProps={{
            title: 'Previous page',
          }}
          nextBtnProps={{
            title: 'Next page',
          }}
          styles={{
            position:'center',
            numberBtnClass: 'btn-primary',
          }}
        />
      </ListPagination>
    </>
  );
};

or you can only use the paggination logic

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

const CustomComponent = () => {
  const [totalPages, setTotalPages] = useState(1000);

  return (
    <>
        <Pagination
          totalPages={totalPages}
          onChangePage={(pageNumber: number, event: any) => { console.log('current page is ' + pageNumber)}}
          currentPage={1}
          itemsPerPage={20}
          displayedNumbersCount={6}
          hasFirstLast={true}
          hasNextPrevious={true}
          firstBtnProps={{
            title: 'First page',
          }}
          lastBtnProps={{
            title: 'Last page',
          }}
          previousBtnProps={{
            title: 'Previous page',
          }}
          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.
stylesObjectundefinedcontains 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 no totalItems)number of total pages.
totalItemsNumbertrue (if no totalPages)number of total items.
itemsPerPageNumbertruenumber of displayed items per page.
displayedNumbersCount1,2,3,4,5,6,7,8falsenumber of displayed pagination buttons to be shown. /default 6
hasNextPreviousBooleanfalsewhether to display previous/next buttons or not.
previousBtnContentstring | React Nodefalsecontent for previous button.
nextBtnContentstring | React Nodefalsecontent for next button.
hasFirstLastBooleanfalsewhether to display first/last buttons or not.
firstBtnContentstring | React Nodefalsecontent for first button.
lastBtnContentstring | React Nodefalsecontent for last button.
hasNumbersGapBooleanfalsewhether to display numbers gap (...) to shortcut to first/last page or not.
numbersGapBtnContentstring | React Nodefalsecontent for gap button.
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.
onChangePage(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.
stylesObjectundefinedcontains 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