You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rectangle.tsx 849B

12345678910111213141516171819202122232425262728293031323334
  1. import { useSelector } from "state"
  2. import { RectangleShape, ShapeProps } from "types"
  3. import ShapeGroup from "./shape-g"
  4. function BaseRectangle({
  5. size,
  6. fill = "#999",
  7. stroke = "none",
  8. strokeWidth = 0,
  9. }: ShapeProps<RectangleShape>) {
  10. return (
  11. <rect
  12. x={strokeWidth}
  13. y={strokeWidth}
  14. width={size[0] - strokeWidth * 2}
  15. height={size[1] - strokeWidth * 2}
  16. fill={fill}
  17. stroke={stroke}
  18. strokeWidth={strokeWidth}
  19. />
  20. )
  21. }
  22. export default function Rectangle({ id, point, size }: RectangleShape) {
  23. const isSelected = useSelector((state) => state.values.selectedIds.has(id))
  24. return (
  25. <ShapeGroup id={id} point={point}>
  26. <BaseRectangle size={size} />
  27. {isSelected && (
  28. <BaseRectangle size={size} fill="none" stroke="blue" strokeWidth={1} />
  29. )}
  30. </ShapeGroup>
  31. )
  32. }