npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ngochuytu/react-pagination

v1.0.1

Published

ReactJS component to render a pagination

Downloads

6

Readme

React-pagination

NPM

ReactJS component to render a pagination.

Install and customize your own pagination component

Styling example here

Installation

Install @ngochuytu/react-pagination with npm

$ npm install @ngochuytu/react-pagination

Usage

PaginationExample.js

import React, { useState } from 'react';
import { Pagination } from '@ngochuytu/react-pagination';

const LoadingSpinner = (props) => {
  return (
    <div className="spinner-container">
      <div className="spinner"></div>
    </div>
  );
};

const PaginationExample = (props) => {
  const [isLoading, setIsLoading] = useState(false);
  const [currentPage, setCurrentPage] = useState(1);
  const dataPerPage = 10;

  const listData = new Array(dataPerPage).fill(0).map((_, index) => {
    const rowNumber = index + (currentPage - 1) * dataPerPage;
    return (
      <div key={rowNumber}>
        <p>This is row number {rowNumber}</p>
      </div>
    );
  });

  const onPageChange = (activePage) => {
    //Fetch api here
    setIsLoading(true);
    setTimeout(() => {
      setIsLoading(false);
      setCurrentPage(activePage);
    }, 1000);
  };

  return (
    <div className="pagination-example-container">
      <h1>This is page number {currentPage}</h1>
      {listData}
      <Pagination
        totalPages={100}
        activePage={1}
        breakButtonStep={2}
        pageRange={9}
        onPageChange={onPageChange}
        navigateToFirstPageButtonLabel="&#171;"
        navigateToLastPageButtonLabel="&#187;"
      />
      {isLoading && <LoadingSpinner />}
    </div>
  );
};

PaginationExample.style.css (This is only for spinner, you can skip this part)

/*Spinner Ref: https://codepen.io/hannibalza/pen/MWVvoJw*/
.spinner-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 99999;
  text-align: center;
  background-color: rgba(0, 0, 0, 0.3);
}

.spinner {
  margin: auto;
  border: 2px solid #dbf2ff;
  width: 32px;
  height: 32px;
  display: inline-block;
  position: absolute;
  top: 45%;
  border-radius: 50%;
  border-right: 2px solid #018df7;
  text-align: center;
  animation-name: spin;
  animation-duration: 900ms;
  animation-iteration-count: infinite;
  animation-timing-function: cubic-bezier(0.53, 0.21, 0.29, 0.67);
}
@-webkit-keyframes spin {
  0% {
    -webkit-transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(360deg);
  }
}
@keyframes spin {
  0% {
    -webkit-transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(360deg);
  }
}

.pagination-example-container {
  position: relative;
}

Test it on CodeSandbox.

Props

| Name | Type | Default | Description | | ------------------------------------ | :-------: | :-----: | -------------------------------------------------------------------------------------------------------------------------------------------------------- | | totalPages | number | | (Required) The total number of pages | | activePage | number | | (Optional) The initial active page. The default value is 1. This value is uncontrolled, activePage then will be controlled by component's state | | pageRange | number | 7 | (Optional) (Min: 5) Range of pages displayed, exclude 2 navigation button to first and last page. | | breakButtonStep | number | 1 | (Optional) Step of break button. | | disableNavigationButtons | boolean | false | (Optional) Disable 2 navigation buttons. | | disableInitialOnPageChangeCall | boolean | false | (Optional) Disable initial onPageChange call. You might have to turn off Strict mode in development mode. | | containerClassName | string | | (Optional) ClassName of pagination's container | | pageButtonClassName | string | | (Optional) ClassName of each page button | | activePageButtonClassName | string | | (Optional) ClassName of active page button | | navigateToFirstPageButtonClassName | string | | (Optional) ClassName of navigate to first page button | | navigateToLastPageButtonClassName | string | | (Optional) ClassName of navigate to last page button | | breakButtonClassName | string | | (Optional) ClassName of break button | | navigateToFirstPageButtonLabel | ReactNode | "<<" | (Optional) Label for the navigate to first page button | | navigateToLastPageButtonLabel | ReactNode | ">>" | (Optional) Label for the navigate to last page button | | breakButtonLabel | ReactNode | "..." | (Optional) Label for the break button | | onPageChange | Function | | (Optional) Page change handler, receive activePage as an argument |