Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chakra-paginator

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chakra-paginator

## Version

  • 0.6.1
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Chakra paginator

Version

npm version


Installation

npm

npm i chakra-paginator

Yarn

yarn add chakra-paginator

Demo

Check it out in this Sandbox


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 = () => {
  // react hooks
  const [isPaginatorDisabled, setIsPaginatorDisabled] = useState<boolean>(
    false
  );

  // constants
  const pagesQuantity: Number = 20; // -> calculated or obtained from Backend
  const outerLimit: Number = 2;
  const innerLimit: Number = 2;

  // styles
  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",
  };

  // handlers
  const handlePageChange = (nextPage: number) => {
    // -> request new data using the page number
    console.log(nextPage);
  };

  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

PropDescriptionTypeDefaultRequired
pagesQuantityThe total number of pages, calculated based on Backend datanumber0yes
onPageChangeOn change handler which returns the last selected page(nextPage: number) => voidyes
isDisabledDisables all of the pagination components. You can always disable each individual component via the isDisabled prop, as the components render HTML buttonsbooleanfalseno
activeStylesThe styles of the active page buttonButtonProps{}no
normalStylesThe styles of the inactive page buttonsButtonProps{}no
separatorStylesThe styles of the separator wrapperButtonProps{}no
outerLimitThe amount of pages to show at the start and at the endnumber0no
innerLimitThe amount of pages to show from the currentPage backwards and forwardnumber0no
currentPageManually set the currentPage of the paginationnumber1no

Container

  • Container is a Flex component, so any FlexProps are accepted

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

Keywords

FAQs

Package last updated on 24 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc