2.0.0 • Published 6 years ago

react-library-paginator v2.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

react-library-paginator

A React bootstrap-oriented customizable paginator component written in typescript.

NPM JavaScript Style Guide

Features included:

  • Paging functionality - tested and proven to work, will make those pages appear on the screen,
  • Includes built-in styles - default styling, for the lazy ones,
  • Boostrap-friendly - compatible with Boostrap 4, for the conservative ones,
  • Customizable styles - allows to customize styles via css classes or inline styles, for the love-to-customize-things ones,
  • Customizable navigation - allows to customize paginator navigation elements.

Demo

Check out demo showing a few common use-cases.

Install

npm install --save react-library-paginator

Usage

import React, { Component } from 'react';

import Paginator from 'react-library-paginator';

export default class BasicPaginator extends Component {
  state = { page: 1, totalItems: 120 };
  handlePageChange = page => {
    this.setState({ page });
  };
  render() {
    const { page, totalItems } = this.state;
    return (
      <Paginator
        totalItems={totalItems}
        currentPage={page}
        onPageChange={this.handlePageChange}
        classes={{
          container: 'paginator-container',
          list: 'paginator-list',
          pageItem: 'paginator-item',
          pageLink: 'paginator-link',
          pageLinkActive: 'paginator-link--active',
          pageLinkDisabled: 'paginator-link--disabled'
        }}
      />
    );
  }
}

API

NameTypeDefaultDescription
totalItemsnumberRequiredTotal number of items that will be paginated.
onPageChangefunctionRequiredEvent that is triggered when the page changes. The new page number is passed into the event handler function.
currentPagenumber1Number of the current page.
itemsPerPagenumber10How many items are displayed per one page.
maxPagesToShownumber3How many page numbers should be visible in the paginator between previous and next navigation symbols.
useBootstrapClassesboolfalseIndicates whether to apply bootstrap 4 pagination classes (e.g. pagination, page-item etc) to the paging elements.
stylesobject{}Object defining class names for the paging elements (see below).
classesobject{}Object defining inline styles for the paging elements (see below).
navigationobject{}Object customizing visibility and texts for paginator navigation elements (see below).

Classes and styles

Object keyType (classes/styles)Description
containerstring/objectClass name/style object for the outer container (nav).
liststring/objectClass name/style object for the paginator list (ul).
pageItemstring/objectClass name/style object for the paginator list item (li).
pageLinkstring/objectClass name/style object for the link inside the list item (a).
pageLinkActivestring/objectClass name/style object for the link of currently selected page.
pageLinkDisabledstring/objectClass name/style object for the link of non-selectable pages/navigation symbols.

Navigation

Object keyTypeDescription
firstPageTextstringText displayed inside navigation element for the first page .
prevPageTextstringText displayed inside navigation element for the previous page.
nextPageTextstringText displayed inside navigation element for the next page .
lastPageTextstringText displayed inside navigation element for the last page .
hideFirstPageNavbooleanIndicates whether to hide navigation element for the first page.
hidePrevPageNavbooleanIndicates whether to hide navigation element for the previous page.
hideNextPageNavbooleanIndicates whether to hide navigation element for the next page .
hideLastPageNavbooleanIndicates whether to hide navigation element for the last page .

Contributing

Contributions are welcome, bug reports, pull requests, feature requests are highly appreciated and rewarded with lightning fast responses and developing!

License

MIT © MargaretKrutikova