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

@traverse-data/pagination

v1.0.3

Published

JSX component for pagination, compatible with React, Preact or vhtml

Downloads

64

Readme

Pagination

JSX component for pagination, compatible with React, Preact or vhtml.

  • Zero Deps
  • Unopionionated: Each DOM element is left up to you.
  • Compatible: Plays nicely with Reactstrap, React Router v4.
  • BYOF: (Bring Your Own Framework) Pure JSX, not tied to React.

Installation

Yarn:

$ yarn install --save @traverse-data/pagination

npm:

$ npm install --save @traverse-data/pagination

Determine the build to import based on which framework(s) you use:

  • @traverse-data/pagination/react/Pagination
  • @traverse-data/pagination/react/PaginationReactstrap
  • @traverse-data/pagination/react/PaginationReactRouter
  • @traverse-data/pagination/preact/Pagination
  • @traverse-data/pagination/vhtml/Pagination

Include with a module bundler like rollup or webpack:

// using ES6 modules
import Pagination from '@traverse-data/pagination/react/Pagination'

// using CommonJS modules
var Pagination = require('@traverse-data/pagination/react/Pagination')

Documentation

React/Preact/vhtml

At the lowest level, each DOM element is specified by functions passed as props to the component. The resulting output of each element is layed out below. Most functions receive a page parameter, which can be used to generate URLs. Be sure to include key props in the returned components, since each one will be a child of <wrapper></wrapper>.

If the current page (<item active />) should be rendered differently, a second parameter active is passed to the item() function.

import Pagination from '@traverse-data/pagination/react/Pagination'

<Pagination
    page={6}
    perPage={10}
    count={115}
    context={1}
    previous={page => <Component key={'previous'} />}
    next={page => <Component key={'next'} />}
    item={(page, active) => <Component key={page} />}
    spacer={key => <Component key={key} />}
    wrapper={props => <Component>{props.children}</Component>}
/>
                        context={1}
                       +-----------+ <spacer />
                       |           | |
+------------------------------------v------------------+
| Previous | 1 | 2 |...| 5 | 6 | 7 |...| 10 | 11 | Next |
+^---------------^-----------^---------------------^----+
 |               |           |                     |
 <previous />    <item />    <item active />       <next />

Props:

  • page: Number. Current page.
  • perPage: Number. How many items are paginated per page.
  • count: Number. Total count of items (determines the last page).
  • context: Number. How many pages to show on both sides of the current page.
  • previous: Function. Component for the Previous button.
  • next: Function => Component for the Next button.
  • item: Function => Component for each Page button.
  • spacer: Function => Component for each contracted space.
  • wrapper: Function => Component to wrap all children in.

Reactstrap

If you're using Reactstrap, there's already a nice Pagination component. Pagination plays nicely with it. URLs still have to be generated though with the href() function, which receives a page number and returns a string.

Additional props are passed through, so className, size, tag, etc. are supported.

import Pagination from '@traverse-data/pagination/react/PaginationReactstrap'

<Pagination
    page={6}
    perPage={10}
    count={115}
    href={page => `/my-url?page=${page}`}
/>

Props:

  • page: Number. Current page.
  • perPage: Number. How many items are paginated per page.
  • count: Number. Total count of items (determines the last page).
  • context: Number. Default: 2. How many pages to show on both sides of the current page.
  • href: Function => String to use for the href of each element.

React Router v4

If you're using Reactstrap AND React Router v4, Pagination also plays nicely by automatically creating <Link />'s, which update the page= URL query parameter. Existing query parameters are respected.

import Pagination from '@traverse-data/pagination/react/PaginationReactRouter'

<Pagination
    page={6}
    perPage={10}
    count={115}
/>

Props:

  • page: Number. Current page.
  • perPage: Number. How many items are paginated per page.
  • count: Number. Total count of items (determines the last page).
  • context: Number. Default: 2. How many pages to show on both sides of the current page.

License

MIT