Skip to content

Commit 4d97e3d

Browse files

6 files changed

+19
-96
lines changed

.eslintrc.json

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
}
2323
],
2424
"no-invalid-this": "error",
25+
"react/require-default-props": "off",
2526
"react/function-component-definition": [
2627
"error",
2728
{

package-lock.json

+9-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
},
3535
"peerDependencies": {
3636
"lodash": "4.x",
37-
"prop-types": "15.x",
3837
"pdfjs-dist": "4.x",
3938
"react": "18.x",
4039
"react-dom": "18.x"

src/PDFPasswordForm.tsx

-24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, {useState, useRef, useMemo, type ChangeEvent, type FormEventHandler} from 'react';
2-
import PropTypes from 'prop-types';
32

43
import {pdfPasswordFormStyles as styles} from './styles';
54
import {isSafari} from './helpers';
@@ -11,27 +10,6 @@ type Props = {
1110
onPasswordFieldFocus?: (isFocused: boolean) => void;
1211
};
1312

14-
const propTypes = {
15-
/** If the submitted password is invalid (show an error message) */
16-
isPasswordInvalid: PropTypes.bool,
17-
18-
/** Notify parent that the password form has been submitted */
19-
onSubmit: PropTypes.func,
20-
21-
/** Notify parent that the password has been updated/edited */
22-
onPasswordChange: PropTypes.func,
23-
24-
/** Notify parent that a text field has been focused or blurred */
25-
onPasswordFieldFocus: PropTypes.func,
26-
};
27-
28-
const defaultProps = {
29-
isPasswordInvalid: false,
30-
onSubmit: () => {},
31-
onPasswordChange: () => {},
32-
onPasswordFieldFocus: () => {},
33-
};
34-
3513
function PDFPasswordForm({isPasswordInvalid, onSubmit, onPasswordChange, onPasswordFieldFocus}: Props) {
3614
const [password, setPassword] = useState('');
3715
const [validationErrorText, setValidationErrorText] = useState('');
@@ -151,8 +129,6 @@ function PDFPasswordForm({isPasswordInvalid, onSubmit, onPasswordChange, onPassw
151129
);
152130
}
153131

154-
PDFPasswordForm.propTypes = propTypes;
155-
PDFPasswordForm.defaultProps = defaultProps;
156132
PDFPasswordForm.displayName = 'PDFPasswordForm';
157133

158134
export type {Props as PDFPasswordFormProps};

src/PDFPreviewer.tsx

+9-40
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import pdfWorkerSource from 'pdfjs-dist/legacy/build/pdf.worker.mjs';
44
import React, {memo, useCallback, useLayoutEffect, useRef, useState} from 'react';
55
import type {CSSProperties, ReactNode} from 'react';
66
import times from 'lodash/times';
7-
import PropTypes from 'prop-types';
87
import {VariableSizeList as List} from 'react-window';
98
import {Document, pdfjs} from 'react-pdf';
109
import 'react-pdf/dist/Page/AnnotationLayer.css';
@@ -21,9 +20,9 @@ type Props = {
2120
file: string;
2221
pageMaxWidth: number;
2322
isSmallScreen: boolean;
24-
maxCanvasWidth: number | null;
25-
maxCanvasHeight: number | null;
26-
maxCanvasArea: number | null;
23+
maxCanvasWidth?: number;
24+
maxCanvasHeight?: number;
25+
maxCanvasArea?: number;
2726
renderPasswordForm?: ({isPasswordInvalid, onSubmit, onPasswordChange}: Omit<PDFPasswordFormProps, 'onPasswordFieldFocus'>) => ReactNode | null;
2827
LoadingComponent?: ReactNode;
2928
ErrorComponent?: ReactNode;
@@ -35,52 +34,24 @@ type Props = {
3534

3635
type OnPasswordCallback = (password: string | null) => void;
3736

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-
6937
pdfjs.GlobalWorkerOptions.workerSrc = URL.createObjectURL(new Blob([pdfWorkerSource], {type: 'text/javascript'}));
7038

39+
const DefaultLoadingComponent = <p>Loading...</p>;
40+
const DefaultErrorComponent = <p>Failed to load the PDF file :(</p>;
41+
7142
function PDFPreviewer({
7243
file,
7344
pageMaxWidth,
7445
isSmallScreen,
7546
maxCanvasWidth,
7647
maxCanvasHeight,
7748
maxCanvasArea,
78-
LoadingComponent,
79-
ErrorComponent,
49+
LoadingComponent = DefaultLoadingComponent,
50+
ErrorComponent = DefaultErrorComponent,
8051
renderPasswordForm,
8152
containerStyle,
8253
contentContainerStyle,
83-
shouldShowErrorComponent,
54+
shouldShowErrorComponent = true,
8455
onLoadError,
8556
}: Props) {
8657
const [pageViewports, setPageViewports] = useState<PageViewport[]>([]);
@@ -285,7 +256,5 @@ function PDFPreviewer({
285256
}
286257

287258
PDFPasswordForm.displayName = 'PDFPreviewer';
288-
PDFPreviewer.propTypes = propTypes;
289-
PDFPreviewer.defaultProps = defaultProps;
290259

291260
export default memo(PDFPreviewer);

src/PageRenderer.tsx

-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, {memo, type CSSProperties} from 'react';
2-
import PropTypes from 'prop-types';
32
import {Page} from 'react-pdf';
43
import {pdfPreviewerStyles as styles} from './styles';
54
import {PAGE_BORDER} from './constants';
@@ -17,31 +16,6 @@ type Props = {
1716
};
1817
};
1918

20-
const propTypes = {
21-
/** Index of the PDF page to be displayed passed by VariableSizeList */
22-
index: PropTypes.number.isRequired,
23-
24-
/** Page extra data passed by VariableSizeList's data prop */
25-
data: PropTypes.shape({
26-
/** Width of a single page in the document */
27-
pageWidth: PropTypes.number.isRequired,
28-
/** The estimated height of a single page in the document */
29-
estimatedPageHeight: PropTypes.number.isRequired,
30-
/** Function that calculates the height of a page given its index */
31-
calculatePageHeight: PropTypes.func.isRequired,
32-
/** Function that calculates the pixel ratio for a page given its calculated width and height */
33-
getDevicePixelRatio: PropTypes.func.isRequired,
34-
/** The number of pages in the document */
35-
numPages: PropTypes.number.isRequired,
36-
/** The height of the container view */
37-
containerHeight: PropTypes.number.isRequired,
38-
}).isRequired,
39-
40-
/** Additional style props passed by VariableSizeList */
41-
// eslint-disable-next-line react/forbid-prop-types
42-
style: PropTypes.object.isRequired,
43-
};
44-
4519
function PageRenderer({index, style, data}: Props) {
4620
const {pageWidth, estimatedPageHeight, calculatePageHeight, getDevicePixelRatio, numPages, containerHeight} = data;
4721
/**
@@ -70,6 +44,5 @@ function PageRenderer({index, style, data}: Props) {
7044
}
7145

7246
PageRenderer.displayName = 'PageRenderer';
73-
PageRenderer.propTypes = propTypes;
7447

7548
export default memo(PageRenderer);

0 commit comments

Comments
 (0)