Cleanup @ohif/ui ViewportGrid API
This commit is contained in:
parent
26450644ab
commit
f319092b84
@ -1,46 +1,33 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import classnames from 'classnames';
|
|
||||||
|
|
||||||
const ViewportGrid = ({ rows, cols, viewportContents }) => {
|
function ViewportGrid({ numRows, numCols, children }) {
|
||||||
const ViewportPanes = viewportContents.map((viewportContent, index) => {
|
const rowSize = 100 / numRows;
|
||||||
const isActive = index === activeViewportIndex;
|
const colSize = 100 / numCols;
|
||||||
return (
|
|
||||||
<div
|
|
||||||
key={index}
|
|
||||||
className={classnames(
|
|
||||||
'rounded-lg hover:border-primary-light transition duration-300 outline-none overflow-hidden',
|
|
||||||
{
|
|
||||||
'border-2 border-primary-light -m-px': isActive,
|
|
||||||
'border border-secondary-light': !isActive,
|
|
||||||
}
|
|
||||||
)}
|
|
||||||
onClick={() => {
|
|
||||||
setActiveViewportIndex(index);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{viewportContent}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={classnames(
|
data-cy="viewport-grid"
|
||||||
'h-full w-full grid gap-2',
|
style={{
|
||||||
`grid-cols-${cols}`,
|
display: 'grid',
|
||||||
`grid-rows-${rows}`
|
gridTemplateRows: `repeat(${numRows}, ${rowSize}%)`,
|
||||||
)}
|
gridTemplateColumns: `repeat(${numCols}, ${colSize}%)`,
|
||||||
|
height: '100%',
|
||||||
|
width: '100%',
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{ViewportPanes}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
ViewportGrid.propTypes = {
|
ViewportGrid.propTypes = {
|
||||||
rows: PropTypes.number.isRequired,
|
/** Number of columns */
|
||||||
cols: PropTypes.number.isRequired,
|
numRows: PropTypes.number.isRequired,
|
||||||
viewportContents: PropTypes.arrayOf(PropTypes.node),
|
/** Number of rows */
|
||||||
|
numCols: PropTypes.number.isRequired,
|
||||||
|
/** Array of React Components to render within grid */
|
||||||
|
children: PropTypes.arrayOf(PropTypes.node).isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ViewportGrid;
|
export default ViewportGrid;
|
||||||
|
|||||||
@ -21,18 +21,14 @@ import { ViewportGrid } from '@ohif/ui';
|
|||||||
|
|
||||||
<Playground>
|
<Playground>
|
||||||
<div className="p-4 h-56">
|
<div className="p-4 h-56">
|
||||||
<ViewportGrid
|
<ViewportGrid numRows={1} numCols={2}>
|
||||||
rows={1}
|
<div className="flex items-center justify-center h-full text-white">
|
||||||
cols={2}
|
Viewport1
|
||||||
viewportContents={[
|
</div>
|
||||||
<div className="flex items-center justify-center h-full text-white">
|
<div className="flex items-center justify-center h-full text-white">
|
||||||
Viewport1
|
Viewport2
|
||||||
</div>,
|
</div>
|
||||||
<div className="flex items-center justify-center h-full text-white">
|
</ViewportGrid>
|
||||||
Viewport2
|
|
||||||
</div>,
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</Playground>
|
</Playground>
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user