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

58 lines
1.4 KiB
React
Raw Normal View History

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