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.

corner-handle.tsx 1011B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import useHandleEvents from "hooks/useBoundsHandleEvents"
  2. import styled from "styles"
  3. import { Corner, Bounds } from "types"
  4. export default function CornerHandle({
  5. size,
  6. corner,
  7. bounds,
  8. }: {
  9. size: number
  10. bounds: Bounds
  11. corner: Corner
  12. }) {
  13. const events = useHandleEvents(corner)
  14. const isTop = corner === Corner.TopLeft || corner === Corner.TopRight
  15. const isLeft = corner === Corner.TopLeft || corner === Corner.BottomLeft
  16. return (
  17. <StyledCorner
  18. corner={corner}
  19. x={(isLeft ? 0 : bounds.width) - size / 2}
  20. y={(isTop ? 0 : bounds.height) - size / 2}
  21. width={size}
  22. height={size}
  23. {...events}
  24. />
  25. )
  26. }
  27. const StyledCorner = styled("rect", {
  28. stroke: "$bounds",
  29. fill: "#fff",
  30. zStrokeWidth: 2,
  31. variants: {
  32. corner: {
  33. [Corner.TopLeft]: { cursor: "nwse-resize" },
  34. [Corner.TopRight]: { cursor: "nesw-resize" },
  35. [Corner.BottomRight]: { cursor: "nwse-resize" },
  36. [Corner.BottomLeft]: { cursor: "nesw-resize" },
  37. },
  38. },
  39. })