ConceptPortal-public/rsconcept/frontend/src/components/ui/PDFViewer/PDFViewer.tsx
Ivan 609752a9d6
Some checks failed
Frontend CI / build (22.x) (push) Has been cancelled
R: Remove unused useMemo and useCallback
2024-12-13 21:31:09 +03:00

37 lines
1008 B
TypeScript

'use client';
import { useConceptOptions } from '@/context/ConceptOptionsContext';
import useWindowSize from '@/hooks/useWindowSize';
/** Maximum width of the viewer. */
const MAXIMUM_WIDTH = 1600;
/** Minimum width of the viewer. */
const MINIMUM_WIDTH = 300;
interface PDFViewerProps {
/** PDF file to display. */
file?: string;
/** Offset from the left side of the window. */
offsetXpx?: number;
/** Minimum width of the viewer. */
minWidth?: number;
}
/**
* Displays a PDF file using an embedded viewer.
*/
function PDFViewer({ file, offsetXpx, minWidth = MINIMUM_WIDTH }: PDFViewerProps) {
const windowSize = useWindowSize();
const { calculateHeight } = useConceptOptions();
const pageWidth = Math.max(minWidth, Math.min((windowSize?.width ?? 0) - (offsetXpx ?? 0) - 10, MAXIMUM_WIDTH));
const pageHeight = calculateHeight('1rem');
return <embed src={`${file}#toolbar=0`} className='p-3' style={{ width: pageWidth, height: pageHeight }} />;
}
export default PDFViewer;