import React, { FC, SyntheticEvent } from 'react' import { Colors, ElevationRange, FontSizes, getColor, getElevationShadow, } from '@monorail/helpers/exports' import { css } from '@monorail/helpers/styled-components' import { Button } from '@monorail/visualComponents/buttons/Button' import { ButtonDisplay } from '@monorail/visualComponents/buttons/buttonTypes' import { Icon } from '@monorail/visualComponents/icon/Icon' import { Text } from '@monorail/visualComponents/typography/Text' const NumberButton: FC<{ number: number current?: boolean handleClick: (e: SyntheticEvent) => void }> = ({ number, current = false, handleClick }) => { return current ? ( {number} ) : ( ) } const Ellipsis: FC = () => ... type PaginationButtonProps = { onClick?: (e: React.SyntheticEvent) => void disabled?: boolean } export const PaginationBackButton = ({ onClick, disabled = false, }: PaginationButtonProps) => ( ) export const PaginationNextButton = ({ onClick, disabled = false, }: PaginationButtonProps) => ( ) export const CollectionPaginationComponent: FC<{ data: Array // data gets passed as prop by ReactTable; don't care what's in it, just care abt length to get total page: number pages: number pageSize: number onPageChange: (n: number) => void }> = ({ data, page, pages, pageSize, onPageChange }) => { const min = 1 + page * pageSize const total = data.length const max = Math.min(min + pageSize - 1, total) const getSafePage = (pg: number) => { return Math.min(Math.max(pg, 0), pages - 1) } const changePage = ( e: SyntheticEvent, pg: number, ) => { const safePage = getSafePage(pg) if (page !== safePage) { onPageChange(safePage) } e.currentTarget.blur() } const linksForEveryPage = () => ( <> {Array.from(Array(pages).keys()).map((n, i) => ( changePage(e, n)} /> ))} ) const ellipsisAfterBeginning = () => ( <> changePage(e, 0)} current={page === 0} /> changePage(e, 1)} current={page === 1} /> changePage(e, 2)} current={page === 2} /> changePage(e, 3)} current={page === 3} /> changePage(e, 4)} /> changePage(e, pages - 1)} /> ) const ellipsisBeforeEnd = () => ( <> changePage(e, 0)} /> changePage(e, pages - 5)} /> changePage(e, pages - 4)} current={page === pages - 4} /> changePage(e, pages - 3)} current={page === pages - 3} /> changePage(e, pages - 2)} current={page === pages - 2} /> changePage(e, pages - 1)} current={page === pages - 1} /> ) const numbers = () => { if (pages < 8) { return linksForEveryPage() } if (page < 4) { return ellipsisAfterBeginning() } else if (page > pages - 5) { return ellipsisBeforeEnd() } else { return ( <> changePage(e, 0)} /> changePage(e, page - 1)} /> {}} /> changePage(e, page + 1)} /> changePage(e, pages - 1)} /> ) } } return (
changePage(e, page - 1)} disabled={page === 0} />
6 ? '250px' : 'auto'}; align-items: center; justify-content: space-between; flex: 1 1 0; `} > {numbers()}
changePage(e, page + 1)} disabled={page === pages - 1} />
Showing {min}-{max} of {total} Results
) }