tldraw/components/canvas/defs.tsx

44 lines
857 B
TypeScript
Raw Normal View History

import React from 'react'
2021-05-28 16:25:43 +00:00
import { useSelector } from 'state'
2021-06-29 12:00:59 +00:00
import tld from 'utils/tld'
2021-06-05 06:36:39 +00:00
import { DotCircle, Handle } from './misc'
2021-06-29 14:54:46 +00:00
import styled from 'styles'
2021-05-28 13:08:51 +00:00
2021-06-21 21:35:28 +00:00
export default function Defs(): JSX.Element {
2021-05-28 13:08:51 +00:00
return (
<defs>
2021-06-05 06:36:39 +00:00
<DotCircle id="dot" r={4} />
<Handle id="handle" r={4} />
<ExpandDef />
2021-07-09 16:15:27 +00:00
<HoverDef />
2021-05-28 13:08:51 +00:00
</defs>
)
}
function ExpandDef() {
2021-06-29 12:00:59 +00:00
const zoom = useSelector((s) => tld.getCurrentCamera(s.data).zoom)
return (
<filter id="expand">
2021-07-09 16:15:27 +00:00
<feMorphology operator="dilate" radius={1 / zoom} />
</filter>
)
}
2021-06-29 14:54:46 +00:00
2021-07-09 16:15:27 +00:00
function HoverDef() {
2021-06-29 14:54:46 +00:00
return (
<filter id="hover">
2021-07-09 16:15:27 +00:00
<StyledShadow
dx="2"
dy="2"
stdDeviation="0.5"
floodOpacity="1"
floodColor="blue"
/>
2021-06-29 14:54:46 +00:00
</filter>
)
}
const StyledShadow = styled('feDropShadow', {
floodColor: '$selected',
})