Chakra paginator
Version
Installation
npm
npm i chakra-paginator
Yarn
yarn add chakra-paginator
Demo
Usage
import React, { FC, useState } from "react";
import { ButtonProps, Button, Flex, ChakraProvider } from "@chakra-ui/react";
import {
Paginator,
Previous,
Next,
PageGroup,
Container,
} from "chakra-paginator";
const Demo: FC = () => {
const [isPaginatorDisabled, setIsPaginatorDisabled] = useState<boolean>(
false
);
const pagesQuantity: Number = 20;
const outerLimit: Number = 2;
const innerLimit: Number = 2;
const baseStyles: ButtonProps = {
w: 7,
fontSize: "sm",
};
const normalStyles: ButtonProps = {
...baseStyles,
bg: "red.300",
};
const activeStyles: ButtonProps = {
...baseStyles,
bg: "green.300",
};
const separatorStyles: ButtonProps = {
w: 7,
bg: "green.200",
};
const handlePageChange = (currentPage: number) => {
console.log(currentPage);
};
const handleDisableClick = () =>
setIsPaginatorDisabled((oldState) => !oldState);
return (
<ChakraProvider>
<Paginator
isDisabled={isPaginatorDisabled}
activeStyles={activeStyles}
innerLimit={innerLimit}
outerLimit={outerLimit}
normalStyles={normalStyles}
separatorStyles={separatorStyles}
pagesQuantity={pagesQuantity}
onPageChange={handlePageChange}
>
<Container align="center" justify="space-between" w="full" p={4}>
<Previous bg="green.300">
Previous
{/* Or an icon from `react-icons` */}
</Previous>
<PageGroup isInline align="center" />
<Next bg="green.300">
Next
{/* Or an icon from `react-icons` */}
</Next>
</Container>
</Paginator>
<Flex w="full" justify="center" align="center">
<Button ml={4} onClick={handleDisableClick}>
Disable ON / OFF
</Button>
</Flex>
</ChakraProvider>
);
};
export default Demo;
Components API
Paginator
Prop | Description | Type | Default | Required |
---|
pagesQuantity | The total number of pages, calculated based on Backend data | number | 0 | yes |
onPageChange | On change handler which returns the last selected page | (currentPage: number) => void | | yes |
isDisabled | Disables all of the pagination components. You can always disable each individual component via the isDisabled prop, as the components render HTML buttons | boolean | false | no |
activeStyles | The styles of the active page button | ButtonProps | {} | no |
normalStyles | The styles of the inactive page buttons | ButtonProps | {} | no |
separatorStyles | The styles of the separator wrapper | ButtonProps | {} | no |
outerLimit | The amount of pages to show at the start and at the end | number | 0 | no |
innerLimit | The amount of pages to show from the currentPage backwards and forward | number | 0 | no |
Container
- Container is a Flex component, so any FlexProps are accpeted
PageGroup
- PageGroup is a Stack component, so any StackProps are accepted
Previous
- Previous is a Button component, so any ButtonProps are accepted
Next
- Next is a Button component, so any ButtonProps are accepted