tldraw/components/canvas/bounds-bg.tsx

33 lines
758 B
TypeScript
Raw Normal View History

2021-05-13 06:44:52 +00:00
import { useRef } from "react"
2021-05-12 22:08:53 +00:00
import state, { useSelector } from "state"
2021-05-13 06:44:52 +00:00
import inputs from "state/inputs"
2021-05-12 22:08:53 +00:00
import styled from "styles"
export default function BoundsBg() {
2021-05-13 06:44:52 +00:00
const rBounds = useRef<SVGRectElement>(null)
2021-05-12 22:08:53 +00:00
const bounds = useSelector((state) => state.values.selectedBounds)
if (!bounds) return null
const { minX, minY, width, height } = bounds
return (
<StyledBoundsBg
2021-05-13 06:44:52 +00:00
ref={rBounds}
2021-05-12 22:08:53 +00:00
x={minX}
y={minY}
width={width}
height={height}
onPointerDown={(e) => {
if (e.buttons !== 1) return
2021-05-13 06:44:52 +00:00
rBounds.current.setPointerCapture(e.pointerId)
state.send("POINTED_BOUNDS", inputs.pointerDown(e))
2021-05-12 22:08:53 +00:00
}}
/>
)
}
const StyledBoundsBg = styled("rect", {
fill: "$boundsBg",
})