import React, { useState } from 'react';
import PropTypes from 'prop-types';
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);
return x <= hoverX && y <= hoverY;
};
return (
{[0, 1, 2, 3, 4, 5, 6, 7, 8].map(index => (
{
const x = index % 3;
const y = Math.floor(index / 3);
onSelection({
numRows: y + 1,
numCols: x + 1,
});
}}
onMouseEnter={() => setHoveredIndex(index)}
onMouseLeave={() => setHoveredIndex(-1)}
>
))}
);
}
LayoutSelector.defaultProps = {
onSelection: () => {},
};
LayoutSelector.propTypes = {
onSelection: PropTypes.func.isRequired,
};
export default LayoutSelector;