import React from 'react'; import styled, { css } from 'styled-components'; import { PaginationInterface } from './interface'; import { dim } from '@utils/dim'; import * as tokens from '@tokens'; const PaginationSection = styled.section` text-align: center; margin: 30px auto; `; const PaginationNumber = styled.a` color: ${tokens.colorBlack}; margin: 0 ${dim(1)}; &:hover { cursor: pointer; } ${({ isCurrentPage }: { isCurrentPage: boolean }) => isCurrentPage ? css` text-decoration: none; &:hover { color: ${tokens.colorBlack}; } ` : css` text-decoration: underline; &:hover { color: ${tokens.colorPink}; } `} `; const PaginationArrow = styled.button<{ previous?: boolean; disabled?: boolean }>` align-items: center; background-color: ${tokens.colorWhite}; background-size: 100% 100%; border: none; width: ${dim(3)}; height: ${dim(3)}; cursor: ${({ disabled }) => (disabled ? 'not-allowed' : 'pointer')}; display: inline-flex; justify-content: center; ${({ previous }) => previous ? css` background-image: url('/icons/carousel-arrow-prev.svg'); margin-right: ${dim(1)}; ` : css` background-image: url('/icons/carousel-arrow-next.svg'); margin-left: ${dim(1)}; `}; :not([disabled]):hover { ${({ previous }) => previous ? css` background-image: url('/icons/carousel-arrow-prev-hover.svg'); ` : css` background-image: url('/icons/carousel-arrow-next-hover.svg'); `}; } span { display: flex; } .category-svg { height: 12px; width: 8px; > svg { height: 100%; width: 100%; } } `; const Pagination: React.FC = ({ handlePaginationClick = () => {}, pageCount = 1, currentPage = 1 }) => { const handleClick = (newPage: number) => handlePaginationClick(newPage); if (pageCount <= 1) return null; const pageToInt = typeof currentPage === 'string' ? parseInt(currentPage) : currentPage; return ( handleClick(pageToInt - 1)} previous={true} /> {Array.from({ length: pageCount }, (_, ind) => { return ( handleClick(ind + 1)} > {ind + 1} ); })} = pageCount} onClick={() => handleClick(pageToInt + 1)} /> ); }; export default Pagination;