import React from 'react'; import { TableCheckbox } from '@/components/admin/AdminCheckbox'; import Spinner from '@/components/elements/Spinner'; import styled from 'styled-components/macro'; import tw from 'twin.macro'; import { PaginatedResult } from '@/api/http'; export const TableHead = ({ children }: { children: React.ReactNode }) => { return ( {children} ); }; export const TableHeader = ({ name }: { name: string }) => { return ( {name}
); }; export const TableBody = ({ children }: { children: React.ReactNode }) => { return ( {children} ); }; export const TableRow = ({ children }: { children: React.ReactNode }) => { return ( {children} ); }; interface Props { data: PaginatedResult; onPageSelect: (page: number) => void; children: React.ReactNode; } const PaginationButton = styled.button<{ active?: boolean }>` ${tw`relative items-center px-3 py-1 -ml-px text-sm font-normal leading-5 transition duration-150 ease-in-out border border-neutral-500 focus:z-10 focus:outline-none focus:border-primary-300 inline-flex`}; ${props => props.active ? tw`bg-neutral-500 text-neutral-50` : tw`bg-neutral-600 text-neutral-200 hover:text-neutral-50`}; `; const PaginationArrow = styled.button` ${tw`relative inline-flex items-center px-1 py-1 text-sm font-medium leading-5 transition duration-150 ease-in-out border border-neutral-500 bg-neutral-600 text-neutral-400 hover:text-neutral-50 focus:z-10 focus:outline-none focus:border-primary-300`}; &:disabled { ${tw`bg-neutral-700`} } &:hover:disabled { ${tw`text-neutral-400 cursor-default`}; } `; export function Pagination ({ data: { pagination }, onPageSelect, children }: Props) { const setPage = (page: number) => { if (page < 1 || page > pagination.totalPages) { return; } onPageSelect(page); }; const isFirstPage = pagination.currentPage === 1; const isLastPage = pagination.currentPage >= pagination.totalPages; const pages = []; if (pagination.totalPages < 7) { for (let i = 1; i <= pagination.totalPages; i++) { pages.push(i); } } else { // Don't ask me how this works, all I know is that this code will always have 7 items in the pagination, // and keeps the current page centered if it is not too close to the start or end. let start = Math.max(pagination.currentPage - 3, 1); const end = Math.min(pagination.totalPages, pagination.currentPage + ((pagination.currentPage < 4) ? 7 - pagination.currentPage : 3)); while (start !== 1 && end - start !== 6) { start--; } for (let i = start; i <= end; i++) { pages.push(i); } } return ( <> {children}

Showing {((pagination.currentPage - 1) * pagination.perPage) + 1} to {((pagination.currentPage - 1) * pagination.perPage) + pagination.count} of {pagination.total} results

{ isFirstPage && isLastPage ? null :
}
); } export const Loading = () => { return (
); }; export const NoItems = () => { return (
{'No

No items could be found, it's almost like they are hiding.

); }; interface Params { checked: boolean; onSelectAllClick: (e: React.ChangeEvent) => void; children: React.ReactNode; } export const ContentWrapper = ({ checked, onSelectAllClick, children }: Params) => { return ( <>
{children} ); }; export default ({ children }: { children: React.ReactNode }) => { return (
{children}
); };