2.0.0 • Published 11 months ago

@vtaits/react-paginator v2.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
11 months ago

NPM dependencies status Types

@vtaits/react-paginator

Simple customizable pagination component for react applications.

Abilities

  • Styling and replacing components like in react-select.
  • Simple usage in default theme without connecting extra styles. Only css-in-js.

Sandbox examples

Installation

npm install @vtaits/react-paginator styled-components --save

or

yarn add @vtaits/react-paginator styled-components

Usage

import { useState } from 'react';

import { Paginator } from '@vtaits/react-paginator';

function Example() {
  const [page, setPage] = useState(1);

  return (
    <Paginator
      page={page}
      pageCount={15}
      onPageChange={setPage}
    />
  );
}

Props

NameTypeDescriptionDefault value
pagenumberRequired. Current page number. Starts from 1.
pageCountnumberRequired. The total number of pages.
onPageChange(nextPage: number) => voidCallback of current page change.
pageRangeDisplayednumberThe range of pages displayed.5
marginPagesDisplayednumberThe number of pages to display for margins.2
previousLabelreact nodeLabel for the previous button.'prev'
nextLabelreact nodeLabel for the next button.'next'
breakLabelreact nodeLabel for break between buttons.'...'
hrefBuilder(page: number) => stringThe method is called to generate the href attribute value on tag a of each page element.undefined
componentsObjectCustom componentsundefined
stylesObjectCustom styles{}
payloadgenericAdditional prop for custom components and stylesundefined

Styling

With custom styles

Redefining like in react-select.

import { useState } from 'react';

import { Paginator } from '@vtaits/react-paginator';

const styles = {
  container: (baseStyle, props) => ({
    ...baseStyle,
    backgroundColor: '#EEE',
    padding: 10,
  }),

  pageLink: (baseStyle, props) => ({
    ...baseStyle,
    borderWidth: 0,
    marginLeft: 0,
  }),
};

function Example() {
  const [page, setPage] = useState(1);

  return (
    <Paginator
      page={page}
      pageCount={15}
      onPageChange={setPage}
      styles={styles}
    />
  );
}

Style keys

  • break
  • container
  • nextLink
  • pageLink
  • pageLinkGroup
  • pages
  • previousLink

With custom components

Redefining like in react-select.

import { useState } from 'react';

import { Paginator } from '@vtaits/react-paginator';

function PageLink({
  page,
  isCurrent,
  rootProps,
}) {
  return (
    <label
      style={{
        textAlign: 'center',
        padding: '0 4px',
      }}
    >
      <div>
        {page}
      </div>

      <div>
        <input
          type="radio"
          onChange={() => {
            rootProps.onPageChange(page);
          }}
          checked={isCurrent}
        />
      </div>
    </label>
  );
}

const components = {
  PageLink,
};

function Example() {
  const [page, setPage] = useState(1);

  return (
    <Paginator
      page={page}
      pageCount={15}
      onPageChange={setPage}
      components={components}
    />
  );
}

Components keys

  • Break
  • Container
  • Link
  • NextLink
  • PageLink
  • PageLinkGroup
  • Pages
  • PreviousLink
2.0.0

11 months ago

1.0.1

1 year ago

1.0.0

1 year ago

0.2.1

2 years ago

0.2.0

3 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago