import React, { useRef } from 'react'; import { Rect, Group, Transformer } from 'react-konva'; export function Tile({ initialX, initialY, scale, meterWidth = 1.6, meterHeight = 1.6, color = "rgba(16, 185, 129, 0.6)", stroke = "#10b981", isSelected, onSelect, type, rotation = 0, onChange }) { const shapeRef = useRef(); const trRef = useRef(); const pixelWidth = meterWidth * scale; const pixelHeight = meterHeight * scale; // Sync up transformer when selected React.useEffect(() => { if (isSelected && trRef.current && shapeRef.current) { trRef.current.nodes([shapeRef.current]); trRef.current.getLayer().batchDraw(); } }, [isSelected]); const isLight = type === 'light'; return ( { onSelect(); // visually pop out e.target.moveToTop(); }} onDragEnd={(e) => { onChange && onChange({ x: e.target.x(), y: e.target.y() }); }} onTransformEnd={() => { const node = shapeRef.current; node.scaleX(1); node.scaleY(1); onChange && onChange({ x: node.x(), y: node.y(), rotation: node.rotation() }); }} /> {isSelected && ( )} ); }