Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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