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

@justinc/pagination-component

v1.5.8

Published

React component for pagination see https://github.com/dibenso/pagination-component

Downloads

3

Readme

NOTE

This package has been forked from here.

This fork is temporary to publish the package properly (see issue).

To install: npm i -S @justinc/pagination-component

Original README.md follows:


pagination-component

Travis npm package

A React component that provides pagination.

Installation

npm install pagination-component --save

or

yarn add pagination-component

Demo

To build and run the demo:

  • Clone this repository:
git clone https://github.com/dibenso/pagination-component.git
  • Install dependencies:
npm install

or

yarn install
  • Start demo server:
npm start

Then check http://localhost:3000

Usage

The component accepts 5 required props:

  • currentPage (type: int)
    Indicates the current page of pagination. It is zero based, so the first page is indicated by 0.

  • pageCount (type: int)
    Indicates how many pages to paginate through. For example if the current page is 0 and pageCount is 50. The result of the pagination will show:
    first 1 2 3 4 5 6 7 8 9 10 ... next last
    Clicking the "last" link will callback with 49 (page 50) in the onPageClick prop.

  • pageLinkClassName (type: string | object)
    If this prop is a string, then the prop indicates the className of the css to use for all links in pagination. Example style:

.pageLink {
  margin: 2px;
  display: inline-block;
  padding: 2px;
  -webkit-border-radius: 20px;
  -moz-border-radius: 20px;
  border-radius: 20px;
}

Then import this css into js:

import styles from './styles.css';

Then pass styles.pageLink in for this prop to use these styles.
If this prop is a object, then the prop indicates the style to use. This is useful for CSS in JS libraries like glamor. Example using glamor:

import { css } from 'glamor';

const pageLink = css({
  margin: '2px',
  display: 'inline-block',
  padding: '2px',
  WebkitBorderRadius: '20px',
  MozBorderRadius: '20px',
  borderRadius: '20px'
})

Then pass the pageLink object in for this prop.

  • currentLinkClassName (type: string | object)
    This works the same way as pageLinkClassName except its styling is for the page link for the current page. Use this prop to make a visual difference between the current page link and the others. Example style:
.currentLink {
  background-color: #0074c2;
  color: #FFFFFF;
}

.currentLink a:link { color: #FFFFFF; }
.currentLink a:visited { color: #FFFFFF; }
.currentLink a:active { color: #FFFFFF; }

Pass this prop to the component in the same was as pageLinkClassName.

  • onPageClick (type: function)
    This is called everytime a page link is clicked. This callback accepts the page that was clicked. Remember, the page is zero based. So when a user clicks on a page link that is displayed as 15, the value passed to this callback will be 14. Here's how one might use this prop with the history API and perhaps react-router:
function handlePageClick(page) {
  console.log(`Link to page ${page} was clicked.`);
  history.push(`/?page=${page}`);
}

Full example (using glamor for styles):

import React from 'react'
import {render} from 'react-dom'
import Pagination from 'pagination-component';
import { css } from 'glamor';

const pageLink = css({
  margin: '2px',
  display: 'inline-block',
  padding: '2px',
  WebkitBorderRadius: '20px',
  MozBorderRadius: '20px',
  borderRadius: '20px'
})

const currentLink = css({
  backgroundColor: '#0074c2',
  display: 'inline-block',
  color: '#FFFFFF',
  'a:link': { color: '#FFFFFF' },
  'a:visited': { color: '#FFFFFF' },
  'a:active': { color: '#FFFFFF' }
})

let Example = React.createClass({
  render() {
    return <div>
      <h1>react-paginator Demo</h1>
      <Pagination currentPage={0}
                 pageCount={50}
                 pageLinkClassName={pageLink}
                 currentLinkClassName={currentLink}
                 onPageClick={i => {
                  console.log(`Link to page ${i} was clicked.`);
                 }} />
    </div>
  }
})

render(<Example />, document.querySelector('#root'))

Tests

To run the tests:

  • Install dependencies from package.json
npm install

or

yarn install
  • Then:
yarn test

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D