@8x8/oxygen-pagination
v3.0.0
Published
Oxygen - Pagination
Keywords
Readme
8x8 Oxygen - Pagination
Instalation
$ yarn add @8x8/oxygen-pagination$ npm install @8x8/oxygen-paginationExternal Props
size:PaginationSize | undefined- style size of the paginationrowsPerPageOptions:number[] | undefined- array of rows per page optionstranslations:Translations- object of translations strings for labelsonPaginationChange:(pagination: PaginationState) => void;- callback function for pagination changeisDisabled?:boolean- tell whenPaginationcomponent is disabled.testId?:string- test id of pagination component
Internal props (can be extracted from usePagination Hook)
pageNumber:number- page number of the paginationnumberOfPages:number- total number of pagescanGoBack:boolean- determines if previous button is disabled or enabledcanGoNext:boolean- determines if next button is disabled or enabledrowsPerPage:number- default rows per page dropdown value
Types
const PAGINATION_SIZE = {
small: 'small',
default: 'default'
}
type PaginationSize = keyof typeof PAGINATION_SIZE; interface PaginationState {
pageNumber: number;
rowsPerPage: number;
} interface Translations {
paginationTitle: string;
rowsPerPage: string;
prevPage: string;
numberOfPages: string;
nextPage: string;
}Usage
import React, { useState } from 'react';
import Pagination, {
usePagination,
PaginationState,
} from '@8x8/oxygen-pagination';
const [pagination, setPagination] = useState<PaginationState>({
pageNumber: 1,
rowsPerPage: 10,
});
const { canGoBack, canGoNext, numberOfPages, pageNumber, rowsPerPage } =
usePagination(pagination, totalRecords);
return (
<Pagination
canGoBack={canGoBack}
canGoNext={canGoNext}
numberOfPages={numberOfPages}
onPaginationChange={setPagination}
pageNumber={pageNumber}
rowsPerPage={rowsPerPage}
translations={{
rowsPerPage: 'Rows per page:',
prevPage: 'Prev',
numberOfPages: `of ${numberOfPages} pages`,
nextPage: 'Next',
}}
/>
)