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.

hovered-shape.tsx 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { memo } from 'react'
  2. import tld from 'utils/tld'
  3. import { getShapeUtils } from 'state/shape-utils'
  4. import vec from 'utils/vec'
  5. import styled from 'styles'
  6. import { useSelector } from 'state'
  7. import { getShapeStyle } from 'state/shape-styles'
  8. function HoveredShape({ id }: { id: string }) {
  9. const transform = useSelector((s) => {
  10. const shape = tld.getShape(s.data, id)
  11. const center = getShapeUtils(shape).getCenter(shape)
  12. const rotation = shape.rotation * (180 / Math.PI)
  13. const parentPoint = tld.getShape(s.data, shape.parentId)?.point || [0, 0]
  14. return `
  15. translate(${vec.neg(parentPoint)})
  16. rotate(${rotation}, ${center})
  17. translate(${shape.point})
  18. `
  19. })
  20. const strokeWidth = useSelector((s) => {
  21. const shape = tld.getShape(s.data, id)
  22. const style = getShapeStyle(shape.style, s.data.settings.isDarkMode)
  23. return +style.strokeWidth
  24. })
  25. return (
  26. <StyledHoverShape
  27. href={'#' + id}
  28. transform={transform}
  29. strokeWidth={strokeWidth + 8}
  30. />
  31. )
  32. }
  33. const StyledHoverShape = styled('use', {
  34. stroke: '$selected',
  35. opacity: 0.1,
  36. })
  37. export default memo(HoveredShape)