Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/PDFPreviewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type Props = {
renderPasswordForm?: ({isPasswordInvalid, onSubmit, onPasswordChange}: Omit<PDFPasswordFormProps, 'onPasswordFieldFocus'>) => ReactNode | null;
LoadingComponent?: ReactNode;
ErrorComponent?: ReactNode;
shouldShowErrorComponent?: boolean;
onLoadError?: () => void;
containerStyle?: CSSProperties;
contentContainerStyle?: CSSProperties;
};
Expand All @@ -43,6 +45,8 @@ const propTypes = {
renderPasswordForm: PropTypes.func,
LoadingComponent: PropTypes.node,
ErrorComponent: PropTypes.node,
shouldShowErrorComponent: PropTypes.bool,
onLoadError: PropTypes.func,
// eslint-disable-next-line react/forbid-prop-types
containerStyle: PropTypes.object,
// eslint-disable-next-line react/forbid-prop-types
Expand All @@ -56,8 +60,10 @@ const defaultProps = {
renderPasswordForm: null,
LoadingComponent: <p>Loading...</p>,
ErrorComponent: <p>Failed to load the PDF file :(</p>,
shouldShowErrorComponent: true,
containerStyle: {},
contentContainerStyle: {},
onLoadError: () => {},
};

pdfjs.GlobalWorkerOptions.workerSrc = URL.createObjectURL(new Blob([pdfWorkerSource], {type: 'text/javascript'}));
Expand All @@ -74,6 +80,8 @@ function PDFPreviewer({
renderPasswordForm,
containerStyle,
contentContainerStyle,
shouldShowErrorComponent,
onLoadError,
}: Props) {
const [pageViewports, setPageViewports] = useState<PageViewport[]>([]);
const [numPages, setNumPages] = useState(0);
Expand Down Expand Up @@ -237,7 +245,8 @@ function PDFPreviewer({
file={file}
options={DEFAULT_DOCUMENT_OPTIONS}
externalLinkTarget={DEFAULT_EXTERNAL_LINK_TARGET}
error={ErrorComponent}
error={shouldShowErrorComponent ? ErrorComponent : null}
onLoadError={onLoadError}
loading={LoadingComponent}
onLoadSuccess={onDocumentLoadSuccess}
onPassword={initiatePasswordChallenge}
Expand Down