2021-06-28 12:13:34 +00:00
|
|
|
import { memo } from 'react'
|
2021-06-29 12:00:59 +00:00
|
|
|
import tld from 'utils/tld'
|
2021-06-28 12:13:34 +00:00
|
|
|
import { getShapeUtils } from 'state/shape-utils'
|
|
|
|
import vec from 'utils/vec'
|
|
|
|
import styled from 'styles'
|
|
|
|
import { useSelector } from 'state'
|
|
|
|
import { getShapeStyle } from 'state/shape-styles'
|
|
|
|
|
|
|
|
function HoveredShape({ id }: { id: string }) {
|
|
|
|
const transform = useSelector((s) => {
|
2021-06-29 12:00:59 +00:00
|
|
|
const shape = tld.getShape(s.data, id)
|
2021-06-28 12:13:34 +00:00
|
|
|
const center = getShapeUtils(shape).getCenter(shape)
|
|
|
|
const rotation = shape.rotation * (180 / Math.PI)
|
2021-06-29 12:00:59 +00:00
|
|
|
const parentPoint = tld.getShape(s.data, shape.parentId)?.point || [0, 0]
|
2021-06-28 12:13:34 +00:00
|
|
|
|
|
|
|
return `
|
|
|
|
translate(${vec.neg(parentPoint)})
|
|
|
|
rotate(${rotation}, ${center})
|
|
|
|
translate(${shape.point})
|
|
|
|
`
|
|
|
|
})
|
|
|
|
|
|
|
|
const strokeWidth = useSelector((s) => {
|
2021-06-29 12:00:59 +00:00
|
|
|
const shape = tld.getShape(s.data, id)
|
2021-07-10 20:39:29 +00:00
|
|
|
const style = getShapeStyle(shape.style, s.data.settings.isDarkMode)
|
2021-06-28 12:13:34 +00:00
|
|
|
return +style.strokeWidth
|
|
|
|
})
|
|
|
|
|
|
|
|
return (
|
2021-06-28 13:01:49 +00:00
|
|
|
<StyledHoverShape
|
|
|
|
href={'#' + id}
|
|
|
|
transform={transform}
|
|
|
|
strokeWidth={strokeWidth + 8}
|
|
|
|
/>
|
2021-06-28 12:13:34 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const StyledHoverShape = styled('use', {
|
|
|
|
stroke: '$selected',
|
|
|
|
opacity: 0.1,
|
|
|
|
})
|
|
|
|
|
|
|
|
export default memo(HoveredShape)
|