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 974B

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