tldraw/components/canvas/bounds-bg.tsx

34 lines
822 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}
2021-05-14 22:56:41 +00:00
width={Math.max(1, width)}
height={Math.max(1, height)}
2021-05-12 22:08:53 +00:00
onPointerDown={(e) => {
if (e.buttons !== 1) return
e.stopPropagation()
2021-05-13 06:44:52 +00:00
rBounds.current.setPointerCapture(e.pointerId)
state.send("POINTED_BOUNDS", inputs.pointerDown(e, "bounds"))
2021-05-12 22:08:53 +00:00
}}
/>
)
}
const StyledBoundsBg = styled("rect", {
fill: "$boundsBg",
})