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