1.0.5 • Published 1 year ago

replace-js-pagination v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

replace-js-pagination

A ReactJS component to render a pagination.

The component comes with no built-in styles. HTML layout compatible with Bootstrap 3 pagination stylesheets.

If you would like it to work for Bootstrap 4, you will need to define your own css styling or to add 2 additional props when using this component:

itemClass="page-item"
linkClass="page-link"
  • NOTE: This component was derived from react-js-pagination, which apparently is no longer maintained for longer than 2 years and has a high risk vulnerability as reported by "npm audit" related to tar dependency. This dependency has been removed in this "replace-js-pagination"

Installation

Install replace-js-pagination with npm:

$ npm install replace-js-pagination

Usage

Very easy to use. Just provide props with total amount of things that you want to display on the page.

import 'bootstrap/dist/css/bootstrap.min.css';

import React, { useState } from "react";

import { Row, Container } from "react-bootstrap";
import Pagination from "replace-js-pagination";

const App = () => {
    const [activePage, setActivePage] = useState(16);

    const handlePageChange = (pageNumber) => {
        setActivePage(pageNumber);
    };
    return (
        <>
            <Container>
                <Row>
                    <h1>Testing pagination: Page: {activePage} </h1>
                </Row>
                <Row>
                    <Pagination
                        itemClass="page-item"
                        linkClass="page-link"
                        activePage={activePage}
                        itemsCountPerPage={10}
                        totalItemsCount={450}
                        pageRangeDisplayed={5}
                        onChange={handlePageChange}
                    />
                </Row>
            </Container>
        </>
    );
};

export default App;

A small example is provided here: https://codesandbox.io/s/replace-js-pagination-276mpq?file=/src/App.js

Example

Params

NameTypeDefaultDescription
totalItemsCountNumberRequired. Total count of items which you are going to display
onChangeFunctionRequired. Page change handler. Receive pageNumber as arg
activePageNumber1Required. Active page
itemsCountPerPageNumber10Count of items per page
pageRangeDisplayedNumber5Range of pages in paginator, exclude navigation blocks (prev, next, first, last pages)
prevPageTextString / ReactElementText of prev page navigation button
firstPageTextString / ReactElement«Text of first page navigation button
lastPageTextString / ReactElement»Text of last page navigation button
nextPageTextString / ReactElementText of next page navigation button
getPageUrlFunctionGenerate href attribute for page
innerClassStringpaginationClass name of <ul> tag
activeClassStringactiveClass name of active <li> tag
activeLinkClassStringClass name of active <a> tag
itemClassStringDefault class of the <li> tag
itemClassFirstStringClass of the first <li> tag
itemClassPrevStringClass of the previous <li> tag
itemClassNextStringClass of the next <li> tag
itemClassLastStringClass of the last <li> tag
disabledClassStringdisabledClass name of the first, previous, next and last <li> tags when disabled
hideDisabledBooleanfalseHide navigation buttons (prev, next, first, last) if they are disabled.
hideNavigationBooleanfalseHide navigation buttons (prev page, next page)
hideFirstLastPagesBooleanfalseHide first/last navigation buttons
linkClassStringDefault class of the <a> tag
linkClassFirstStringClass of the first <a> tag
linkClassPrevStringClass of the previous <a> tag
linkClassNextStringClass of the next <a> tag
linkClassLastStringClass of the last <a> tag