fix null dropdowncontent

This commit is contained in:
dannyrb 2020-06-16 00:43:16 -04:00
parent f2b77d2a4a
commit 33cee9e898

View File

@ -1,24 +1,23 @@
import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import {
LayoutSelector as OHIFLayoutSelector,
ToolbarButton,
useViewportGrid,
} from '@ohif/ui';
function LayoutSelector({ onSelection }) {
function LayoutSelector() {
const [isOpen, setIsOpen] = useState(false);
const [viewportGridState, dispatch] = useViewportGrid();
useEffect(() => {
function LayoutSelector() {
function closeOnOutsideClick() {
if (isOpen) {
setIsOpen(false);
}
}
window.addEventListener('click', LayoutSelector);
window.addEventListener('click', closeOnOutsideClick);
return () => {
window.removeEventListener('click', LayoutSelector);
window.removeEventListener('click', closeOnOutsideClick);
};
}, [isOpen]);
@ -33,17 +32,19 @@ function LayoutSelector({ onSelection }) {
setIsOpen(!isOpen);
}}
dropdownContent={
<DropdownContent
onSelection={({ numRows, numCols }) => {
dispatch({
type: 'SET_LAYOUT',
payload: {
numCols,
numRows,
},
});
}}
/>
DropdownContent !== null && (
<DropdownContent
onSelection={({ numRows, numCols }) => {
dispatch({
type: 'SET_LAYOUT',
payload: {
numCols,
numRows,
},
});
}}
/>
)
}
isActive={isOpen}
type="primary"
@ -51,15 +52,4 @@ function LayoutSelector({ onSelection }) {
);
}
LayoutSelector.propTypes = {
/* Callback for grid selection */
onSelection: PropTypes.func.isRequired,
};
LayoutSelector.defaultProps = {
onSelection: () => {
console.warn('layoutSelector missing `onSelection` prop');
},
};
export default LayoutSelector;