1.6.4 • Published 2 years ago

ts-paginator v1.6.4

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

ts-paginator

ts-paginator

ts-paginator is a TypeScript pagination hook for React or NextJS

Args

Instantiate the useTsPaginator hook with the following arguments:

ArgsDescription
totalRecordCount: numberThe total count of records
currentPage: numberThe current page selection (zero indexed)
rowsPerPage: 10 (default 10)The current rows per page selection

UI/UX Functions

FunctionDescriptionArgsReturn TypeExample Returns
determinePaginationMessageCalculates the pagination messageoptions?: { verb: 'Showing' OR 'Displaying', noun?: string, hideMessageOnZeroRecords: boolean }stringDisplaying 1 to 10 of 20 records
determineRowsPerPageOptionsCalculates the rows per page optionsnumber[][10]
determinePaginationPagesCalculates the pagination pages and uses 0 as a range placeholder for page ranges greater than threenumber[][1, 2]
determinePaginationDisabledStateCan be used to disable the previous page or next page buttonbooleantrue

State Altering Functions

FunctionDescriptionArgsReturn Type
handleChangeTotalRecordCountChanges the total record countnewTotalRecordCount: numbervoid
handleChangeRowsPerPageChanges the rows per pagenewRowsPerPage: numbervoid
handleChangePageChanges the current pagenewPage: numbervoid

Extra Functions

Not required to build working pagination, but might be useful. Coming soon.

Usage

npm i --save ts-paginator

import useTsPaginator from 'ts-paginator';

function MyComponent() {
  const {
    totalRecordCount,
    rowsPerPage,
    currentPage,
    _determinePaginationMessage,
    _determinePaginationDisabledState,
    _determinePaginationPages,
    _determineRowsPerPageOptions,
    _handleChangeTotalRecordCount,
    _handleChangeRowsPerPage,
    _handleChangePage,
  } = useTsPaginator(20, 0);

  const message = _determinePaginationMessage({ verb: 'Showing', noun: 'entries' }); // Showing 1 to 10 of 20 entries

  return <p>{message}</p>;
}

Release Notes

1.6.0

  • Adressed a shortcoming in _determinePaginationMessage not properly handling a totalRecordCount of 0
  • Added an optional noun key to the _determinePaginationMessage options parameter
  • Added an optional hideMessageOnZeroRecords key to the _determinePaginationMessage options parameter which, if set, returns the message as an empty string

Example

https://github.com/WNortier/ts-paginator-example

ts-paginator-example

1.6.4

2 years ago

1.6.3

2 years ago

1.6.2

2 years ago

1.6.1

2 years ago

1.6.0

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.4.9

2 years ago

1.4.8

2 years ago

1.4.7

2 years ago

1.4.6

2 years ago

1.4.5

2 years ago

1.4.4

2 years ago

1.4.3

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.19

2 years ago

1.3.18

2 years ago

1.12.18

2 years ago

1.12.17

2 years ago

1.2.16

2 years ago

1.2.15

2 years ago

1.2.14

2 years ago

1.2.13

2 years ago

1.2.12

2 years ago

1.2.11

2 years ago

1.2.10

2 years ago

1.1.10

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago