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

react-paginatify

v2.0.0

Published

Simple, configurable, truncatable pagination for React.

Downloads

12

Readme

react-paginatify

Simple, configurable, truncatable pagination for React.

npm Travis Codecov David David npm npm

Paginatify generates pagination links with automatic, customizable truncation to prevent the list from becoming too large. All it requires is the total number of pages and the current page in order to function, but to actually be useful, you'll want to pass in a callback function so the component can inform your app when the page has changed.

In this way, the current page can either be tracked internally through state, or externally by modifying the component's props when the current page changes.

This library is provided in several forms:

  • As an ES2015 module in the esm directory.

    import Paginatify from 'react-paginatify/esm/react-paginatify';
  • Transpiled to CommonJS/ES5 in the src directory. This is the default import.

    import Paginatify from 'react-paginatify';
  • Pre-compiled as a UMD module. When loaded using <script> tags, it creates a global variable called Paginatify.

    <script src="react-paginatify.min.js"></script>

Paginatify must be used with React 0.13 or higher, including 15.

Props

page

Number, Default: 1, required

The initial current page. Internally, Paginatify will keep track of the current page in its state. However, if a new page is passed in through this prop, the internal state will be updated to match it. The onChange function will not be called if the current page changes due to a prop change.

pages

Number, Default: 1, required

The total number of pages, inclusive.

className

String, Default: null

This class will be added to the main surrounding div alongside the Paginatify class.

id

String, Default: null

This class will be added to the main surrounding div.

onChange

Function, Default: null

A function that will be called whenever the user clicks on one of the pagination links. It will pass along the current page number, the new page number, and the button type that was clicked. Possible button values are previous, next, and page.

(newPage, oldPage, button) => {
  ...
}

innerPadding

Number, Default: 1

Determines the minimum number of additional page numbers that should remain on either side of the current page number without being hidden by truncation.

outerPadding

Number, Default: 1

Determines the minimum number of additional page numbers that should remain before and after the last and first pages, respectively, without being hidden by truncation.

nextLabel

String, Default: '>'

The string to show for the next page link. Will not show if there is only one page.

prevLabel

String, Default: '<'

The string to show for the previous page link. Will not show if there is only one page.

truncateChar

String, Default: '…'

The character used to indicate that a truncation has occurred.

truncateShort

Boolean, Default: false

In situations where the total number of pages is below a certain threshold (based on the inner and outer padding), Paginatify will not perform any truncation in order to prevent too few links from showing up. If you want truncation to occur even in this situation, set truncateShort to true.

truncateNever

Boolean, Default: false

If true, truncation will never be applied. This supersedes truncateShort.

Styling

There is no styling applied by default. You may provide a custom class name for the parent element, and several classes are provided on the child elements to allow for styling.

Some example themes are included in the css directory, with SCSS versions found in scss. You can view and play around with them on Codepen.

paginatify

The class of the surrounding parent div element.

paginatify__link

Applied to every page link, as well as the next and previous links. These elements are a tags. These are several types of links:

paginatify__link--page

A direct link to a page.

paginatify__link--previous

A link to the previous page.

paginatify__link--next

A link to the next page.

paginatify__link--current

Applied to the current page. While it is still a clickable a tag, no action is performed when it is clicked.

paginatify__link--disabled

Applied to a page that is not clickable (but not the current page). This is applied to the previous and next links when the current page is the first or last page, respectively.

paginatify__truncation

This is the string that indicates that a truncation has occurred. These elements are span tags and are not clickable.