@dt-dds/react-pagination
v1.0.0-beta.38
Published
The Pagination component enables the user to select a specific page from a range of pages.
Downloads
1,551
Readme
Pagination Package
The Pagination component enables the user to select a specific page from a range of pages.
Pagination Usage
import { Pagination, PaginationInput, usePagination } from '@dt-dds/react';
const totalPages = 10;
const { currentPage, handleChange, handleUserInput } = usePagination();
return (
<Pagination>
<Pagination.PreviousItem
disabled={currentPage <= 1 || currentPage > totalPages}
onClick={() => handleChange(currentPage - 1)}
/>
<PaginationInput
value={currentPage}
totalPages={totalPages}
onHandleKeyDown={handleUserInput}
onChange={handleChange}
/>
<Pagination.Content
totalPages={totalPages}
onClick={() => handleChange(totalPages)}
/>
<Pagination.NextItem
disabled={currentPage >= totalPages || currentPage < 1}
onClick={() => handleChange(currentPage + 1)}
/>
</Pagination>
);Properties
Pagination
| Property | Type | Default | Description |
| ------------ | ----------- | ------------------ | ------------------------------- |
| children | ReactNode | - | Child components to be rendered |
| dataTestId | string | pagination-wrapper | Customizable test identifier |
Pagination.PreviousItem
| Property | Type | Default | Description |
| ---------- | ---------- | ------- | ------------------------------------------------- |
| onClick | function | - | The triggered function when clicked on the button |
| disabled | boolean | false | Determines the disabled state of the button |
Pagination.NextItem
| Property | Type | Default | Description |
| ---------- | ---------- | ------- | ------------------------------------------------- |
| onClick | function | - | The triggered function when clicked on the button |
| disabled | boolean | false | Determines the disabled state of the button |
Pagination.Content
| Property | Type | Default | Description |
| ------------ | ---------- | ------- | ------------------------------------------------- |
| onClick | function | - | The triggered function when clicked on the button |
| totalPages | number | - | It will be the number displayed on the button |
PaginationInput
| Property | Type | Default | Description |
| ----------------- | ---------- | ------- | ---------------------------------------------------- |
| totalPages | number | - | Total number of pages |
| onChange | function | - | Function to be executed when debounced value changes |
| onHandleKeyDown | function | - | Event fired when a key is pressed |
| value | number | - | Value to be displayed on the input |
Stack
- TypeScript for static type checking
- React — JavaScript library for user interfaces
- Emotion — for writing css styles with JavaScript
- Storybook — UI component environment powered by Vite
- Jest - JavaScript Testing Framework
- React Testing Library - to test UI components in a user-centric way
- ESLint for code linting
- Prettier for code formatting
- Tsup — TypeScript bundler powered by esbuild
- Yarn from managing packages
Commands
yarn build- Build the packageyarn dev- Run the package locallyyarn lint- Lint all files within this packageyarn test- Run all unit testsyarn test:report- Open the test coverage reportyarn test:update:snapshot- Run all unit tests and update the snapshot
Compilation
Running yarn build from the root of the package will use tsup to compile the raw TypeScript and React code to plain JavaScript.
The /dist folder contains the compiled output.
pagination
└── dist
├── index.d.ts <-- Types
├── index.js <-- CommonJS version
└── index.mjs <-- ES Modules version
...Versioning
Follows semantic versioning
© License
Licensed under MIT License
