import styles from "./styles.module.scss"; import { useRef, useState } from "react"; import { Document, DocumentProps, Page } from "react-pdf"; import Loader, { LoaderColor } from "../Loader"; import { Pagination } from "@mui/material"; interface IPDFViewerProps { width?: number; file?: DocumentProps["file"]; } const pagesOfPaginationPageLength = 1; function PDFViewer(props: IPDFViewerProps & DocumentProps = {}) { const { width = 496, file, className = "" } = props; const [numPages, setNumPages] = useState(0); const containerRef = useRef(null); const [isLoadingDocument, setIsLoadingDocument] = useState(true); const [paginationPage, setPaginationPage] = useState(1); const [isLoadingPage, setIsLoadingPage] = useState(true); const handleChange = (_event: React.ChangeEvent, value: number) => { setIsLoadingPage(true); setPaginationPage(value); }; function onDocumentLoadSuccess({ numPages }: { numPages: number }): void { setNumPages(numPages); setIsLoadingDocument(false); } return ( <>
{isLoadingDocument && ( )} } file={file} onLoadSuccess={onDocumentLoadSuccess} className={className} > {Array.from({ length: pagesOfPaginationPageLength }, (_, i) => { return ( } key={i} pageNumber={ i + pagesOfPaginationPageLength * (paginationPage - 1) + 1 } width={width} className={styles["pdf-page"]} onRenderSuccess={() => { setIsLoadingPage(false); }} > {isLoadingPage && ( )} ); })}
{!isLoadingDocument && ( )} ); } export default PDFViewer;