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

55 lines
1.2 KiB
React
Raw Normal View History

2020-06-14 23:42:44 -04:00
import React, { useEffect, useState } from 'react';
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-16 00:43:16 -04:00
function LayoutSelector() {
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(() => {
2020-06-16 00:43:16 -04:00
function closeOnOutsideClick() {
2020-06-14 23:42:44 -04:00
if (isOpen) {
setIsOpen(false);
}
}
2020-06-16 00:43:16 -04:00
window.addEventListener('click', closeOnOutsideClick);
2020-06-14 23:42:44 -04:00
return () => {
2020-06-16 00:43:16 -04:00
window.removeEventListener('click', closeOnOutsideClick);
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={
2020-06-16 00:43:16 -04:00
DropdownContent !== null && (
<DropdownContent
onSelection={({ numRows, numCols }) => {
dispatch({
type: 'SET_LAYOUT',
payload: {
numCols,
numRows,
},
});
}}
/>
)
2020-06-15 23:38:48 -04:00
}
2020-06-14 23:42:44 -04:00
isActive={isOpen}
type="primary"
/>
);
}
export default LayoutSelector;