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

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