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.

selected.tsx 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import styled from 'styles'
  2. import { useSelector } from 'state'
  3. import { deepCompareArrays, getPage } from 'utils'
  4. import { getShapeUtils } from 'state/shape-utils'
  5. import { memo } from 'react'
  6. export default function Selected(): JSX.Element {
  7. const currentSelectedShapeIds = useSelector(
  8. (s) => s.values.selectedIds,
  9. deepCompareArrays
  10. )
  11. const isSelecting = useSelector((s) => s.isIn('selecting'))
  12. if (!isSelecting) return null
  13. return (
  14. <g>
  15. {currentSelectedShapeIds.map((id) => (
  16. <ShapeOutline key={id} id={id} />
  17. ))}
  18. </g>
  19. )
  20. }
  21. export const ShapeOutline = memo(function ShapeOutline({ id }: { id: string }) {
  22. // const rIndicator = useRef<SVGUseElement>(null)
  23. const shape = useSelector((s) => getPage(s.data).shapes[id])
  24. // const events = useShapeEvents(id, shape?.type === ShapeType.Group, rIndicator)
  25. if (!shape) return null
  26. // This needs computation from state, similar to bounds, in order
  27. // to handle parent rotation.
  28. const center = getShapeUtils(shape).getCenter(shape)
  29. const transform = `
  30. rotate(${shape.rotation * (180 / Math.PI)}, ${center})
  31. translate(${shape.point})
  32. `
  33. return (
  34. <SelectIndicator
  35. // ref={rIndicator}
  36. as="use"
  37. href={'#' + id}
  38. transform={transform}
  39. isLocked={shape.isLocked}
  40. // {...events}
  41. />
  42. )
  43. })
  44. const SelectIndicator = styled('path', {
  45. // zStrokeWidth: 2,
  46. strokeLineCap: 'round',
  47. strokeLinejoin: 'round',
  48. stroke: 'red',
  49. strokeWidth: '10',
  50. pointerEvents: 'none',
  51. fill: 'red',
  52. variants: {
  53. isLocked: {
  54. true: {
  55. zDash: 2,
  56. },
  57. false: {},
  58. },
  59. variant: {},
  60. },
  61. })