Files
ohif-viewer/platform/ui/src/components/LayoutSelector/LayoutSelector.tsx
T

67 lines
1.7 KiB
TypeScript
Raw Normal View History

2020-06-15 23:38:48 -04:00
import React, { useState } from 'react';
import PropTypes from 'prop-types';
function LayoutSelector({ onSelection, rows, columns }) {
2020-06-15 23:38:48 -04:00
const [hoveredIndex, setHoveredIndex] = useState();
const hoverX = hoveredIndex % columns;
const hoverY = Math.floor(hoveredIndex / columns);
2020-06-15 23:38:48 -04:00
const isHovered = index => {
const x = index % columns;
const y = Math.floor(index / columns);
2020-06-15 23:38:48 -04:00
return x <= hoverX && y <= hoverY;
};
const gridSize = '20px ';
return (
2020-06-15 23:38:48 -04:00
<div
style={{
display: 'grid',
gridTemplateColumns: gridSize.repeat(columns),
gridTemplateRows: gridSize.repeat(rows),
2020-06-15 23:38:48 -04:00
backgroundColor: '#090c29', // primary-dark
}}
className="p-2"
>
{Array.apply(null, Array(rows * columns))
.map(function(_, i) {
return i;
})
.map(index => (
<div
key={index}
style={{
border: '1px solid white',
backgroundColor: isHovered(index) ? '#5acce6' : '#0b1a42',
}}
className="cursor-pointer"
onClick={() => {
const x = index % columns;
const y = Math.floor(index / columns);
2020-06-15 23:38:48 -04:00
onSelection({
numRows: y + 1,
numCols: x + 1,
});
}}
onMouseEnter={() => setHoveredIndex(index)}
onMouseLeave={() => setHoveredIndex(-1)}
></div>
))}
2020-06-15 23:38:48 -04:00
</div>
);
}
2020-06-15 23:38:48 -04:00
LayoutSelector.defaultProps = {
onSelection: () => {},
columns: 3,
rows: 3,
2020-06-15 23:38:48 -04:00
};
LayoutSelector.propTypes = {
onSelection: PropTypes.func.isRequired,
columns: PropTypes.number.isRequired,
rows: PropTypes.number.isRequired,
2020-06-15 23:38:48 -04:00
};
export default LayoutSelector;