@@ -4,7 +4,6 @@ import pdfWorkerSource from 'pdfjs-dist/legacy/build/pdf.worker.mjs';
4
4
import React , { memo , useCallback , useLayoutEffect , useRef , useState } from 'react' ;
5
5
import type { CSSProperties , ReactNode } from 'react' ;
6
6
import times from 'lodash/times' ;
7
- import PropTypes from 'prop-types' ;
8
7
import { VariableSizeList as List } from 'react-window' ;
9
8
import { Document , pdfjs } from 'react-pdf' ;
10
9
import 'react-pdf/dist/Page/AnnotationLayer.css' ;
@@ -21,9 +20,9 @@ type Props = {
21
20
file : string ;
22
21
pageMaxWidth : number ;
23
22
isSmallScreen : boolean ;
24
- maxCanvasWidth : number | null ;
25
- maxCanvasHeight : number | null ;
26
- maxCanvasArea : number | null ;
23
+ maxCanvasWidth ? : number ;
24
+ maxCanvasHeight ? : number ;
25
+ maxCanvasArea ? : number ;
27
26
renderPasswordForm ?: ( { isPasswordInvalid, onSubmit, onPasswordChange} : Omit < PDFPasswordFormProps , 'onPasswordFieldFocus' > ) => ReactNode | null ;
28
27
LoadingComponent ?: ReactNode ;
29
28
ErrorComponent ?: ReactNode ;
@@ -35,52 +34,24 @@ type Props = {
35
34
36
35
type OnPasswordCallback = ( password : string | null ) => void ;
37
36
38
- const propTypes = {
39
- file : PropTypes . string . isRequired ,
40
- pageMaxWidth : PropTypes . number . isRequired ,
41
- isSmallScreen : PropTypes . bool . isRequired ,
42
- maxCanvasWidth : PropTypes . number ,
43
- maxCanvasHeight : PropTypes . number ,
44
- maxCanvasArea : PropTypes . number ,
45
- renderPasswordForm : PropTypes . func ,
46
- LoadingComponent : PropTypes . node ,
47
- ErrorComponent : PropTypes . node ,
48
- shouldShowErrorComponent : PropTypes . bool ,
49
- onLoadError : PropTypes . func ,
50
- // eslint-disable-next-line react/forbid-prop-types
51
- containerStyle : PropTypes . object ,
52
- // eslint-disable-next-line react/forbid-prop-types
53
- contentContainerStyle : PropTypes . object ,
54
- } ;
55
-
56
- const defaultProps = {
57
- maxCanvasWidth : null ,
58
- maxCanvasHeight : null ,
59
- maxCanvasArea : null ,
60
- renderPasswordForm : null ,
61
- LoadingComponent : < p > Loading...</ p > ,
62
- ErrorComponent : < p > Failed to load the PDF file :(</ p > ,
63
- shouldShowErrorComponent : true ,
64
- containerStyle : { } ,
65
- contentContainerStyle : { } ,
66
- onLoadError : ( ) => { } ,
67
- } ;
68
-
69
37
pdfjs . GlobalWorkerOptions . workerSrc = URL . createObjectURL ( new Blob ( [ pdfWorkerSource ] , { type : 'text/javascript' } ) ) ;
70
38
39
+ const DefaultLoadingComponent = < p > Loading...</ p > ;
40
+ const DefaultErrorComponent = < p > Failed to load the PDF file :(</ p > ;
41
+
71
42
function PDFPreviewer ( {
72
43
file,
73
44
pageMaxWidth,
74
45
isSmallScreen,
75
46
maxCanvasWidth,
76
47
maxCanvasHeight,
77
48
maxCanvasArea,
78
- LoadingComponent,
79
- ErrorComponent,
49
+ LoadingComponent = DefaultLoadingComponent ,
50
+ ErrorComponent = DefaultErrorComponent ,
80
51
renderPasswordForm,
81
52
containerStyle,
82
53
contentContainerStyle,
83
- shouldShowErrorComponent,
54
+ shouldShowErrorComponent = true ,
84
55
onLoadError,
85
56
} : Props ) {
86
57
const [ pageViewports , setPageViewports ] = useState < PageViewport [ ] > ( [ ] ) ;
@@ -285,7 +256,5 @@ function PDFPreviewer({
285
256
}
286
257
287
258
PDFPasswordForm . displayName = 'PDFPreviewer' ;
288
- PDFPreviewer . propTypes = propTypes ;
289
- PDFPreviewer . defaultProps = defaultProps ;
290
259
291
260
export default memo ( PDFPreviewer ) ;
0 commit comments