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.

bounding-box.tsx 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import * as React from 'react'
  2. import { Edge, Corner } from 'types'
  3. import { useSelector } from 'state'
  4. import { getSelectedShapes, isMobile } from 'utils/utils'
  5. import CenterHandle from './center-handle'
  6. import CornerHandle from './corner-handle'
  7. import EdgeHandle from './edge-handle'
  8. import RotateHandle from './rotate-handle'
  9. import Selected from '../selected'
  10. export default function Bounds() {
  11. const isBrushing = useSelector((s) => s.isIn('brushSelecting'))
  12. const isSelecting = useSelector((s) => s.isIn('selecting'))
  13. const zoom = useSelector((s) => s.data.camera.zoom)
  14. const bounds = useSelector((s) => s.values.selectedBounds)
  15. const rotation = useSelector(({ data }) =>
  16. data.selectedIds.size === 1 ? getSelectedShapes(data)[0].rotation : 0
  17. )
  18. if (!bounds) return null
  19. if (!isSelecting) return null
  20. const size = (isMobile().any ? 12 : 8) / zoom // Touch target size
  21. return (
  22. <g
  23. pointerEvents={isBrushing ? 'none' : 'all'}
  24. transform={`
  25. rotate(${rotation * (180 / Math.PI)},
  26. ${(bounds.minX + bounds.maxX) / 2},
  27. ${(bounds.minY + bounds.maxY) / 2})
  28. translate(${bounds.minX},${bounds.minY})`}
  29. >
  30. <Selected bounds={bounds} />
  31. <CenterHandle bounds={bounds} />
  32. <EdgeHandle size={size} bounds={bounds} edge={Edge.Top} />
  33. <EdgeHandle size={size} bounds={bounds} edge={Edge.Right} />
  34. <EdgeHandle size={size} bounds={bounds} edge={Edge.Bottom} />
  35. <EdgeHandle size={size} bounds={bounds} edge={Edge.Left} />
  36. <CornerHandle size={size} bounds={bounds} corner={Corner.TopLeft} />
  37. <CornerHandle size={size} bounds={bounds} corner={Corner.TopRight} />
  38. <CornerHandle size={size} bounds={bounds} corner={Corner.BottomRight} />
  39. <CornerHandle size={size} bounds={bounds} corner={Corner.BottomLeft} />
  40. <RotateHandle size={size} bounds={bounds} />
  41. </g>
  42. )
  43. }