import { IconButton, Text } from "@fluentui/react"; import * as React from "react"; import "./Pager.css"; export interface PagerProps { startIndex: number; totalCount: number; pageSize: number; onLoadPage: (startIndex: number, pageSize: number) => void; disabled?: boolean; showFirstLast?: boolean; showItemCount?: boolean; className?: string; } const iconButtonStyles = { root: { backgroundColor: "transparent", }, rootHovered: { backgroundColor: "transparent", }, rootPressed: { backgroundColor: "transparent", }, rootDisabled: { backgroundColor: "transparent", }, rootFocused: { backgroundColor: "transparent", outline: "none", }, }; const textStyle: React.CSSProperties = { color: "var(--colorNeutralForeground1)" }; const Pager: React.FC = ({ startIndex, totalCount, pageSize, onLoadPage, disabled = false, showFirstLast = true, showItemCount = true, className, }) => { // Calculate current page and total pages from startIndex const currentPage = Math.floor(startIndex / pageSize) + 1; const totalPages = Math.ceil(totalCount / pageSize); const endIndex = Math.min(startIndex + pageSize, totalCount); const handleFirstPage = () => onLoadPage(0, pageSize); const handlePreviousPage = () => onLoadPage(startIndex - pageSize, pageSize); const handleNextPage = () => onLoadPage(startIndex + pageSize, pageSize); const handleLastPage = () => onLoadPage((totalPages - 1) * pageSize, pageSize); if (totalCount === 0) { return null; } return (
{showItemCount && ( Showing {startIndex + 1} - {endIndex} of {totalCount} items )}
{showFirstLast && ( )} Page {currentPage} of {totalPages} {showFirstLast && ( )}
); }; export default Pager;