mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-26 13:00:39 +03:00
37 lines
1008 B
TypeScript
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;
|