Skip to content

Commit ea9dd1e

Browse files
committed
client/modules/App/components/Overlay: update to types & to named export
1 parent 27ed512 commit ea9dd1e

10 files changed

Lines changed: 48 additions & 36 deletions

File tree

client/modules/App/components/Overlay.tsx

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
1-
import PropTypes from 'prop-types';
21
import React, { useCallback, useRef } from 'react';
32
import MediaQuery from 'react-responsive';
43
import { useSelector } from 'react-redux';
54
import { useHistory } from 'react-router-dom';
65
import { useTranslation } from 'react-i18next';
76
import { useModalClose } from '../../../common/useModalClose';
7+
import type { RootState } from '../../../reducers';
88

99
import ExitIcon from '../../../images/exit.svg';
1010

11-
const Overlay = ({
11+
type OverlayProps = {
12+
children?: React.ReactElement;
13+
actions?: React.ReactElement;
14+
closeOverlay?: () => void;
15+
title?: string;
16+
ariaLabel?: string;
17+
isFixedHeight?: boolean;
18+
};
19+
20+
export const Overlay = ({
1221
actions,
13-
ariaLabel,
22+
ariaLabel = 'modal',
1423
children,
1524
closeOverlay,
16-
isFixedHeight,
17-
title
18-
}) => {
25+
isFixedHeight = false,
26+
title = 'Modal'
27+
}: OverlayProps) => {
1928
const { t } = useTranslation();
2029

21-
const previousPath = useSelector((state) => state.ide.previousPath);
30+
const previousPath = useSelector(
31+
(state: RootState) => state.ide.previousPath
32+
);
2233

23-
const ref = useRef(null);
34+
const ref = useRef<HTMLElement>(null);
2435

2536
const browserHistory = useHistory();
2637

@@ -29,7 +40,7 @@ const Overlay = ({
2940
if (!node) return;
3041
// Only close if it is the last (and therefore the topmost overlay)
3142
const overlays = document.getElementsByClassName('overlay');
32-
if (node.parentElement.parentElement !== overlays[overlays.length - 1])
43+
if (node.parentElement?.parentElement !== overlays[overlays.length - 1])
3344
return;
3445

3546
if (!closeOverlay) {
@@ -76,23 +87,3 @@ const Overlay = ({
7687
</div>
7788
);
7889
};
79-
80-
Overlay.propTypes = {
81-
children: PropTypes.element,
82-
actions: PropTypes.element,
83-
closeOverlay: PropTypes.func,
84-
title: PropTypes.string,
85-
ariaLabel: PropTypes.string,
86-
isFixedHeight: PropTypes.bool
87-
};
88-
89-
Overlay.defaultProps = {
90-
children: null,
91-
actions: null,
92-
title: 'Modal',
93-
closeOverlay: null,
94-
ariaLabel: 'modal',
95-
isFixedHeight: false
96-
};
97-
98-
export default Overlay;

client/modules/IDE/components/CollectionList/CollectionList.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import * as ToastActions from '../../actions/toast';
1313
import * as SortingActions from '../../actions/sorting';
1414
import getSortedCollections from '../../selectors/collections';
1515
import { Loader } from '../../../App/components/Loader';
16-
import Overlay from '../../../App/components/Overlay';
16+
import { Overlay } from '../../../App/components/Overlay';
1717
import AddToCollectionSketchList from '../AddToCollectionSketchList';
1818
import { SketchSearchbar } from '../Searchbar';
1919

client/modules/IDE/components/Header/MobileNav.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { selectSketchPath } from '../../selectors/project';
3232
import { availableLanguages, languageKeyToLabel } from '../../../../i18n';
3333
import { showToast } from '../../actions/toast';
3434
import { setLanguage } from '../../actions/preferences';
35-
import Overlay from '../../../App/components/Overlay';
35+
import { Overlay } from '../../../App/components/Overlay';
3636
import ProjectName from './ProjectName';
3737
import CollectionCreate from '../../../User/components/CollectionCreate';
3838

client/modules/IDE/components/IDEOverlays.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { useTranslation } from 'react-i18next';
33
import { useDispatch, useSelector } from 'react-redux';
44
import { useLocation, useParams } from 'react-router-dom';
5-
import Overlay from '../../App/components/Overlay';
5+
import { Overlay } from '../../App/components/Overlay';
66
import {
77
closeKeyboardShortcutModal,
88
closePreferences,

client/modules/IDE/components/SketchList.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import * as ToastActions from '../actions/toast';
1212
import * as SortingActions from '../actions/sorting';
1313
import getSortedSketches from '../selectors/projects';
1414
import { Loader } from '../../App/components/Loader';
15-
import Overlay from '../../App/components/Overlay';
15+
import { Overlay } from '../../App/components/Overlay';
1616
import AddToCollectionList from './AddToCollectionList';
1717
import ArrowUpIcon from '../../../images/sort-arrow-up.svg';
1818
import ArrowDownIcon from '../../../images/sort-arrow-down.svg';

client/modules/User/components/CollectionMetadata.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next';
55
import { useDispatch, useSelector } from 'react-redux';
66
import { Link } from 'react-router-dom';
77
import { Button } from '../../../common/Button';
8-
import Overlay from '../../App/components/Overlay';
8+
import { Overlay } from '../../App/components/Overlay';
99
import { editCollection } from '../../IDE/actions/collections';
1010
import AddToCollectionSketchList from '../../IDE/components/AddToCollectionSketchList';
1111
import EditableInput from '../../IDE/components/EditableInput';

client/modules/User/pages/AccountView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { APIKeyForm } from '../components/APIKeyForm';
1414
import Nav from '../../IDE/components/Header/Nav';
1515
import ErrorModal from '../../IDE/components/ErrorModal';
1616
import { hideErrorModal } from '../../IDE/actions/ide';
17-
import Overlay from '../../App/components/Overlay';
17+
import { Overlay } from '../../App/components/Overlay';
1818
import Toast from '../../IDE/components/Toast';
1919
import { RootState } from '../../../reducers';
2020

client/modules/User/pages/DashboardView.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next';
55

66
import { Button } from '../../../common/Button';
77
import Nav from '../../IDE/components/Header/Nav';
8-
import Overlay from '../../App/components/Overlay';
8+
import { Overlay } from '../../App/components/Overlay';
99
import AssetList from '../../IDE/components/AssetList';
1010
import AssetSize from '../../IDE/components/AssetSize';
1111
import CollectionList from '../../IDE/components/CollectionList';

package-lock.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
"@types/react": "^16.14.0",
149149
"@types/react-dom": "^16.9.25",
150150
"@types/react-helmet": "^6.1.11",
151+
"@types/react-responsive": "^8.0.8",
151152
"@types/react-router-dom": "^5.3.3",
152153
"@types/react-tabs": "^2.3.1",
153154
"@types/react-transition-group": "^4.4.12",

0 commit comments

Comments
 (0)