import React, { ReactElement } from 'react' import { Link } from 'gatsby' import { PageContext } from '../../@types/Post' import Icon from '../atoms/Icon' import * as styles from './Pagination.module.css' function PageNumber({ i, slug, current }: { i: number slug: string current?: boolean }): JSX.Element { const classes = current ? styles.current : styles.number const link = i === 0 ? slug : `${slug}page/${i + 1}` return ( {i + 1} ) } function PrevNext({ prevPagePath, nextPagePath }: { prevPagePath?: string nextPagePath?: string }): JSX.Element { const link = prevPagePath || nextPagePath const rel = prevPagePath ? 'prev' : 'next' const title = prevPagePath ? 'Newer Posts' : 'Older Posts' return ( {prevPagePath ? ( ) : ( )} ) } export default function Pagination({ pageContext }: { pageContext: PageContext }): ReactElement { const { slug, currentPageNumber, numPages, prevPagePath, nextPagePath } = pageContext const isFirst = currentPageNumber === 1 const isLast = currentPageNumber === numPages return (
{!isFirst && } {Array.from({ length: numPages }, (_, i) => ( ))} {!isLast && }
) }