fix null dropdowncontent
This commit is contained in:
parent
f2b77d2a4a
commit
33cee9e898
@ -1,24 +1,23 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import {
|
import {
|
||||||
LayoutSelector as OHIFLayoutSelector,
|
LayoutSelector as OHIFLayoutSelector,
|
||||||
ToolbarButton,
|
ToolbarButton,
|
||||||
useViewportGrid,
|
useViewportGrid,
|
||||||
} from '@ohif/ui';
|
} from '@ohif/ui';
|
||||||
|
|
||||||
function LayoutSelector({ onSelection }) {
|
function LayoutSelector() {
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const [viewportGridState, dispatch] = useViewportGrid();
|
const [viewportGridState, dispatch] = useViewportGrid();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
function LayoutSelector() {
|
function closeOnOutsideClick() {
|
||||||
if (isOpen) {
|
if (isOpen) {
|
||||||
setIsOpen(false);
|
setIsOpen(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
window.addEventListener('click', LayoutSelector);
|
window.addEventListener('click', closeOnOutsideClick);
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener('click', LayoutSelector);
|
window.removeEventListener('click', closeOnOutsideClick);
|
||||||
};
|
};
|
||||||
}, [isOpen]);
|
}, [isOpen]);
|
||||||
|
|
||||||
@ -33,17 +32,19 @@ function LayoutSelector({ onSelection }) {
|
|||||||
setIsOpen(!isOpen);
|
setIsOpen(!isOpen);
|
||||||
}}
|
}}
|
||||||
dropdownContent={
|
dropdownContent={
|
||||||
<DropdownContent
|
DropdownContent !== null && (
|
||||||
onSelection={({ numRows, numCols }) => {
|
<DropdownContent
|
||||||
dispatch({
|
onSelection={({ numRows, numCols }) => {
|
||||||
type: 'SET_LAYOUT',
|
dispatch({
|
||||||
payload: {
|
type: 'SET_LAYOUT',
|
||||||
numCols,
|
payload: {
|
||||||
numRows,
|
numCols,
|
||||||
},
|
numRows,
|
||||||
});
|
},
|
||||||
}}
|
});
|
||||||
/>
|
}}
|
||||||
|
/>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
isActive={isOpen}
|
isActive={isOpen}
|
||||||
type="primary"
|
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;
|
export default LayoutSelector;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user