import React from 'react'; import { Flex, IconButton, Icon, Text, IconButtonProps } from '@chakra-ui/react'; import { useTranslation } from 'react-i18next'; import { TbChevronLeft, TbChevronRight, TbChevronsLeft, TbChevronsRight } from 'react-icons/tb'; export interface IProps { currentIndex: number maxIndex: number setIndex(index: number): void setPrevious():void setNext():void } const Paginator: React.FC = (props) => { const { currentIndex, maxIndex, setIndex, setPrevious, setNext } = props const { t } = useTranslation() return ( } mr={1} display={{ base: 'none', md: 'inline-flex' }} onClick={() => setIndex(0)} disabled={currentIndex == 0} /> } mr={1} onClick={() => setPrevious()} disabled={currentIndex == 0} /> { Array.from(Array(maxIndex).keys()).map((pageIndex) => { const title = t('table.page', { page: pageIndex + 1 }); const disabled = currentIndex === pageIndex; const style: Partial = disabled ? { colorScheme: 'blue' } : {}; return ( {pageIndex + 1}} mr={1} onClick={() => setIndex(pageIndex)} disabled={disabled} {...style} /> ); }) } } mr={{ base: 0, md: 1 }} onClick={() => setNext()} disabled={currentIndex + 1 == maxIndex} /> } display={{ base: 'none', md: 'inline-flex' }} onClick={() => setIndex(maxIndex - 1)} disabled={currentIndex + 1 == maxIndex} /> ); }; export default Paginator;