Skip to content

Commit 47a97a9

Browse files
authored
Merge pull request #3976 from ProjectMirador/default-args-background-plugin
Use ES6 default arguments to avoid deprecated defaultProps on function components
2 parents 756da0d + 9820e05 commit 47a97a9

12 files changed

Lines changed: 56 additions & 117 deletions

.eslintrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444
}],
4545
"react/jsx-uses-react": "off",
4646
"react/react-in-jsx-scope": "off",
47-
"react/require-default-props": "off",
47+
"react/require-default-props": [2, {
48+
"functions": "defaultArguments"
49+
}],
4850
"react-hooks/exhaustive-deps": "error",
4951
"testing-library/render-result-naming-convention": "off",
5052
"testing-library/no-render-in-lifecycle": [

__tests__/src/components/ThumbnailNavigation.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function Subject({ fixture = manifestJson, ...props }) {
2828
}
2929

3030
Subject.propTypes = {
31-
fixture: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
31+
fixture: PropTypes.object, // eslint-disable-line react/forbid-prop-types
3232
};
3333

3434
jest.mock(

setupJest.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ jest.mock('react-i18next', () => ({
4444
type: '3rdParty',
4545
},
4646
// this mock makes sure any components using the translate HoC receive the t function as a prop
47-
withTranslation: () => (Component) => {
48-
Component.defaultProps = { // eslint-disable-line no-param-reassign
49-
...Component.defaultProps, t: k => k,
50-
};
51-
return Component;
47+
withTranslation: () => (WrappedComponent) => {
48+
/**
49+
*
50+
*/
51+
const I18nAwareComponent = ({ t = (k => k), ...props }) => <WrappedComponent t={t} {...props} />; // eslint-disable-line react/prop-types
52+
53+
return I18nAwareComponent;
5254
},
5355
}));

src/components/AudioViewer.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,8 @@ const StyledAudio = styled('audio')({
1313
});
1414

1515
/** */
16-
export function AudioViewer(props) {
16+
export function AudioViewer({ audioOptions = {}, audioResources = [], captions = [] }) {
1717
/* eslint-disable jsx-a11y/media-has-caption */
18-
/** */
19-
const {
20-
captions, audioOptions, audioResources,
21-
} = props;
2218

2319
return (
2420
<StyledContainer>
@@ -44,9 +40,3 @@ AudioViewer.propTypes = {
4440
audioResources: PropTypes.arrayOf(PropTypes.object), // eslint-disable-line react/forbid-prop-types
4541
captions: PropTypes.arrayOf(PropTypes.object), // eslint-disable-line react/forbid-prop-types
4642
};
47-
48-
AudioViewer.defaultProps = {
49-
audioOptions: {},
50-
audioResources: [],
51-
captions: [],
52-
};

src/components/BackgroundPluginArea.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@ import ns from '../config/css-ns';
33
import { PluginHook } from './PluginHook';
44

55
/** invisible area where background plugins can add to */
6-
export const BackgroundPluginArea = props => (
6+
export const BackgroundPluginArea = ({ PluginComponents = [], ...props }) => (
77
<div className={ns('background-plugin-area')} style={{ display: 'none' }}>
8-
<PluginHook {...props} />
8+
<PluginHook PluginComponents={PluginComponents} {...props} />
99
</div>
1010
);
1111

1212
BackgroundPluginArea.propTypes = {
1313
PluginComponents: PropTypes.array, // eslint-disable-line react/forbid-prop-types
1414
};
15-
16-
BackgroundPluginArea.defaultProps = {
17-
PluginComponents: [],
18-
};

src/components/CompanionWindow.js

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,18 @@ const StyledCloseButton = styled(MiradorMenuButton, { name: 'CompanionWindow', s
2323
/**
2424
* CompanionWindow
2525
*/
26-
export function CompanionWindow(props) {
26+
export function CompanionWindow(props) { // eslint-disable-line react/require-default-props
27+
const {
28+
ariaLabel = undefined, classes = {}, direction, paperClassName = '', onCloseClick = () => {}, updateCompanionWindow = undefined, isDisplayed = false,
29+
position = null, t = key => key, title = null, children = undefined, titleControls = null, size = {},
30+
defaultSidebarPanelWidth = 235, defaultSidebarPanelHeight = 201, innerRef = undefined,
31+
} = props;
32+
2733
/** */
28-
const openInNewStyle = () => {
29-
const { direction } = props;
30-
if (direction === 'rtl') return { transform: 'scale(-1, 1)' };
31-
return {};
32-
};
34+
const openInNewStyle = direction === 'rtl' ? { transform: 'scale(-1, 1)' } : {};
3335

3436
/** */
35-
const resizeHandles = () => {
36-
const { direction, position } = props;
37+
const resizeHandles = (() => {
3738
const positions = {
3839
ltr: {
3940
default: 'left',
@@ -69,12 +70,7 @@ export function CompanionWindow(props) {
6970
}
7071

7172
return base;
72-
};
73-
const {
74-
ariaLabel, classes, paperClassName, onCloseClick, updateCompanionWindow, isDisplayed,
75-
position, t, title, children, titleControls, size,
76-
defaultSidebarPanelWidth, defaultSidebarPanelHeight, innerRef,
77-
} = props;
73+
})();
7874

7975
const isBottom = (position === 'bottom' || position === 'far-bottom');
8076

@@ -111,7 +107,7 @@ export function CompanionWindow(props) {
111107
width: isBottom ? 'auto' : defaultSidebarPanelWidth,
112108
}}
113109
disableDragging
114-
enableResizing={resizeHandles()}
110+
enableResizing={resizeHandles}
115111
minHeight={50}
116112
minWidth={position === 'left' ? 235 : 100}
117113
>
@@ -130,7 +126,7 @@ export function CompanionWindow(props) {
130126
aria-label={t('openInCompanionWindow')}
131127
onClick={() => { updateCompanionWindow({ position: 'right' }); }}
132128
>
133-
<OpenInNewIcon style={openInNewStyle()} />
129+
<OpenInNewIcon style={openInNewStyle} />
134130
</MiradorMenuButton>
135131
)
136132
: (
@@ -208,21 +204,3 @@ CompanionWindow.propTypes = {
208204
titleControls: PropTypes.node,
209205
updateCompanionWindow: PropTypes.func,
210206
};
211-
212-
CompanionWindow.defaultProps = {
213-
ariaLabel: undefined,
214-
children: undefined,
215-
classes: {},
216-
defaultSidebarPanelHeight: 201,
217-
defaultSidebarPanelWidth: 235,
218-
innerRef: undefined,
219-
isDisplayed: false,
220-
onCloseClick: () => { },
221-
paperClassName: '',
222-
position: null,
223-
size: {},
224-
t: key => key,
225-
title: null,
226-
titleControls: null,
227-
updateCompanionWindow: undefined,
228-
};

src/components/IIIFIFrameCommunication.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
import { useEffect } from 'react';
22
import PropTypes from 'prop-types';
33

4+
const IIIFIFrameCommunicationDefaultProps = {
5+
'aria-hidden': true,
6+
frameBorder: 0,
7+
height: 1,
8+
name: undefined,
9+
scrolling: undefined,
10+
style: { visibility: 'hidden' },
11+
width: 1,
12+
};
13+
414
/**
515
* Handle IIIF Auth token validation using iframe message events
616
*/
7-
export function IIIFIFrameCommunication({ handleReceiveMessage, ...props }) {
17+
export function IIIFIFrameCommunication({ handleReceiveMessage = undefined, ...props }) {
818
// Attaches the 'message' event listener to the window.
919
useEffect(() => {
1020
if (!handleReceiveMessage) return undefined;
@@ -19,6 +29,7 @@ export function IIIFIFrameCommunication({ handleReceiveMessage, ...props }) {
1929
// iframe "title" attribute is passed in via props for accessibility
2030
// eslint-disable-next-line jsx-a11y/iframe-has-title
2131
<iframe
32+
{...IIIFIFrameCommunicationDefaultProps}
2233
{...props}
2334
/>
2435
);
@@ -35,14 +46,3 @@ IIIFIFrameCommunication.propTypes = {
3546
style: PropTypes.shape({}),
3647
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
3748
};
38-
39-
IIIFIFrameCommunication.defaultProps = {
40-
'aria-hidden': true,
41-
frameBorder: 0,
42-
handleReceiveMessage: undefined,
43-
height: 1,
44-
name: undefined,
45-
scrolling: undefined,
46-
style: { visibility: 'hidden' },
47-
width: 1,
48-
};

src/components/IIIFThumbnail.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ const Image = styled('img', { name: 'IIIFThumbnail', slot: 'image' })(() => ({
2222
* try to load the image (or even calculate that the image url/height/width are)
2323
*/
2424
const LazyLoadedImage = ({
25-
border, placeholder, style = {}, thumbnail, resource, maxHeight, maxWidth, thumbnailsConfig, ...props
25+
border = false, placeholder, style = {}, thumbnail = null,
26+
resource, maxHeight, maxWidth, thumbnailsConfig = {}, ...props
2627
}) => {
2728
const { ref, inView } = useInView();
2829
const [loaded, setLoaded] = useState(false);
@@ -129,13 +130,6 @@ LazyLoadedImage.propTypes = {
129130
thumbnailsConfig: PropTypes.object, // eslint-disable-line react/forbid-prop-types
130131
};
131132

132-
LazyLoadedImage.defaultProps = {
133-
border: false,
134-
style: {},
135-
thumbnail: null,
136-
thumbnailsConfig: {},
137-
};
138-
139133
/**
140134
* Uses InteractionObserver to "lazy" load canvas thumbnails that are in view.
141135
*/

src/components/MiradorMenuButton.js

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,22 @@ const Root = styled(IconButton, { name: 'MiradorMenuButton', slot: 'root' })(({
1616
* This shares the passed in aria-label w/ the Tooltip (as title) and the IconButton
1717
* All props besides icon are spread to the IconButton component
1818
*/
19-
export function MiradorMenuButton(props) {
20-
const { 'aria-label': ariaLabel } = props;
21-
const {
22-
badge,
23-
children,
24-
container,
25-
dispatch,
26-
selected,
27-
BadgeProps,
28-
TooltipProps,
29-
sx,
30-
...iconButtonProps
31-
} = props;
32-
19+
export function MiradorMenuButton({
20+
'aria-label': ariaLabel,
21+
badge = false,
22+
children,
23+
container = null,
24+
dispatch = () => {},
25+
selected = false,
26+
BadgeProps = {},
27+
TooltipProps = {},
28+
sx = {},
29+
...iconButtonProps
30+
}) {
3331
const button = (
3432
<Root
3533
selected={selected}
34+
aria-label={ariaLabel}
3635
{...iconButtonProps}
3736
sx={sx}
3837
size="large"
@@ -76,13 +75,3 @@ MiradorMenuButton.propTypes = {
7675
sx: PropTypes.object, // eslint-disable-line react/forbid-prop-types
7776
TooltipProps: PropTypes.object, // eslint-disable-line react/forbid-prop-types
7877
};
79-
80-
MiradorMenuButton.defaultProps = {
81-
badge: false,
82-
BadgeProps: {},
83-
container: null,
84-
dispatch: () => {},
85-
selected: false,
86-
sx: {},
87-
TooltipProps: {},
88-
};

src/components/MosaicRenderPreview.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import MinimalWindow from '../containers/MinimalWindow';
77
export function MosaicRenderPreview({
88
t = k => k,
99
title = '',
10-
windowId = '',
10+
windowId,
1111
}) {
1212
return (
1313
<MinimalWindow

0 commit comments

Comments
 (0)