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

@tdcerhverv/pagination

v2.3.1

Published

Pagination component

Downloads

3

Readme

Pagination component

This component displays pagination numbers and icons. Typically used and placed in the bottom right corner of a table.

State

  • Test coverage: --%
  • Known bugs: --
  • Storybook: https://storybook.knet.lqd.dk/?path=/story/pagination--all-props
  • Zeroheight: --

Usage

Import like this:

import { Pagination, usePaginationState } from '@tdcerhverv/pagination';

Use like this:

const [paginationState, dispatch] = usePaginationState(totalEntries, pageSize);

<Pagination
  paginationState={paginationState}
  dispatch={dispatch}
  separator="af"
/>;

Notes:

  • pageSize is optional and defaults to 20.
  • separator is the word/symbol in the range text, e.g. 1–20 af 80.

Usage details

The Pagination component is a controlled component having state externally. This is a benefit when working with requests and fetching data from API endpoints.

The usePaginationState hook is basically a reducer, that takes arguments and returns a state object and a dispatch handler.

Props

Interface for usePaginationState:

usePaginationState(
  totalEntries: number,
  pageSize?: number // default: 20
);

Interface for Pagination:

interface IPagination {
  paginationState: TPaginationState;
  dispatch: TPaginationDispatch;
  separator?: string;
  children?: ReactNode;
}

The paginationState prop accepts the following state object:

export type TPaginationState = {
  currentPage: number,
  totalPages: number,
  totalEntries: number,
  skip: number,
  pageSize: number,
  hasPrev: boolean,
  hasNext: boolean,
};

Property skip is the number of entries skipped before the first entry on the current page.

The dispatch action takes the following types:

type TPaginationDispatch = {
  goToFirst: () => void,
  goToPrev: () => void,
  goToNext: () => void,
  goToLast: () => void,
  goToPage: (page: number) => void,
  pagesize: () => void,
  refresh: (totalEntries: number, pageSize: number) => void,
};

Normally it is not required to dispatch any actions. The dispatch actions is handled in the pagination component when changing page.

Input changes to totalEntries and pageSize is handled by the usePaginationState reducer.

Tags

pagination, table