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.

circle.tsx 1.0KB

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