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-headless-pagination

v1.1.6

Published

Headless ReactJS component for pagination. Built using hooks and tested with Jest.

Downloads

32,061

Readme

React Headless Pagination

Do you want to design your own pagination component, but do not want to worry about the logic of pagination? Then this tiny, performant and a11y proof package is for you. react-headless-pagination is ideal if you are working with a utility-based css framework like TailwindCSS. react-headless-pagination offers plenty of customization and is also fully typed.

npm Jest unit tests issues stargazers

Install

yarn add react-headless-pagination

Demo: Unstyled & TailwindCSS

Storybook

Usage

import { Pagination } from "react-headless-pagination";


...
const [page, setPage] = React.useState<number>(0);

const handlePageChange = (page: number) => {
  setPage(page);
};

return (
  <>
    Current page: {page + 1}
    <Pagination
      {...args}
      currentPage={page}
      setCurrentPage={handlePageChange}
      className=""
      truncableText="..."
      truncableClassName=""
    >
      <Pagination.PrevButton className="">Previous</Pagination.PrevButton>

      <nav className="flex justify-center flex-grow">
        <ul className="flex items-center">
          <Pagination.PageButton
            activeClassName=""
            inactiveClassName=""
            className=""
          />
        </ul>
      </nav>

      <Pagination.NextButton className="">Next</Pagination.NextButton>
    </Pagination>
  </>
);

An example of a styled version can be found in stories/PaginationTailwind.stories.tsx.

Pagination props

currentPage

Type: number

The value of current page. Required.

setCurrentPage

Type: (page: number) => void

Callback function once a page is updated. Can be directly used with a setState (see example above).

totalPages

Type: number

The number pages. Required.

edgePageCount

Type: number

The items size of one side of the edge of pagination. Default: 2

middlePagesSiblingCount

Type: number

The items size of one side of the middle of pagination. Default: 2

className

Type: string

Styles for the pagination container.

truncableText

Type: string

Text to render if a one or more pages are truncated.

truncableClassName

Type: string

Styles which can be applied to the TruncableElement.

Pagination.PrevButton props

children

Type: string | React.ReactNode

Content for the previous button.

className

Type: string

Styles for the previous button.

Pagination.NextButton props

children

Type: string | React.ReactNode

Content for the next button.

className

Type: string

Styles for the next button.

Pagination.PageButton props

as

Type: React.ReactElement Default:

Provide a custom React Element, such as a next/link component.

className

Type: string

dataTestIdActive

Type: string

data-testid in case the page button is active.

dataTestIdInactive

Type: string

data-testid in case the page button is active.

activeClassName

Type: string

Styles in case the page button is active.

inactiveClassName

Type: string

Styles in case the page button is inactive.

Authors

Taken inspiration from @makotot/paginated.

Contributing

PR's are always welcomed.

  • Clone

To contribute to this project, start by cloning the repository to your local machine.

  • Installation with Yarn

Before getting started, ensure that you have Yarn installed on your system. If not, you can install it by following the instructions on the official Yarn website.

  • Run storybook: yarn storybook

To visualize and test components, run Storybook using the following command:

  • Build tailwind: yarn watch:css

For styling, the project uses Tailwind CSS. To build Tailwind, run the following command: This command will watch for changes in your CSS files and rebuild Tailwind accordingly. Make sure to run this during development to keep styles up-to-date.