Files
ohif-viewer/extensions/default/src/Toolbar/ToolbarLayoutSelector.jsx
T

65 lines
1.4 KiB
React
Raw Normal View History

2020-06-14 23:42:44 -04:00
import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
2020-06-15 23:38:48 -04:00
import {
LayoutSelector as OHIFLayoutSelector,
ToolbarButton,
useViewportGrid,
} from '@ohif/ui';
2020-06-14 23:42:44 -04:00
2020-06-15 23:38:48 -04:00
function LayoutSelector({ onSelection }) {
2020-06-14 23:42:44 -04:00
const [isOpen, setIsOpen] = useState(false);
2020-06-15 23:38:48 -04:00
const [viewportGridState, dispatch] = useViewportGrid();
2020-06-14 23:42:44 -04:00
useEffect(() => {
function LayoutSelector() {
2020-06-14 23:42:44 -04:00
if (isOpen) {
setIsOpen(false);
}
}
window.addEventListener('click', LayoutSelector);
2020-06-14 23:42:44 -04:00
return () => {
window.removeEventListener('click', LayoutSelector);
2020-06-14 23:42:44 -04:00
};
}, [isOpen]);
2020-06-15 23:38:48 -04:00
const DropdownContent = isOpen ? OHIFLayoutSelector : null;
2020-06-14 23:42:44 -04:00
return (
<ToolbarButton
id="Layout"
label="Grid Layout"
icon="tool-layout"
2020-06-14 23:42:44 -04:00
onClick={() => {
setIsOpen(!isOpen);
}}
2020-06-15 23:38:48 -04:00
dropdownContent={
<DropdownContent
onSelection={({ numRows, numCols }) => {
dispatch({
type: 'SET_LAYOUT',
payload: {
numCols,
numRows,
},
});
}}
/>
}
2020-06-14 23:42:44 -04:00
isActive={isOpen}
type="primary"
/>
);
}
LayoutSelector.propTypes = {
2020-06-15 23:38:48 -04:00
/* Callback for grid selection */
onSelection: PropTypes.func.isRequired,
};
LayoutSelector.defaultProps = {
onSelection: () => {
console.warn('layoutSelector missing `onSelection` prop');
},
2020-06-14 23:42:44 -04:00
};
export default LayoutSelector;