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 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import useBoundsEvents from 'hooks/useBoundsEvents'
  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. }): JSX.Element {
  13. const events = useBoundsEvents(corner)
  14. const isTop = corner === Corner.TopLeft || corner === Corner.TopRight
  15. const isLeft = corner === Corner.TopLeft || corner === Corner.BottomLeft
  16. return (
  17. <g>
  18. <StyledCorner
  19. corner={corner}
  20. x={(isLeft ? -1 : bounds.width + 1) - size}
  21. y={(isTop ? -1 : bounds.height + 1) - size}
  22. width={size * 2}
  23. height={size * 2}
  24. {...events}
  25. />
  26. <StyledCornerInner
  27. x={(isLeft ? -1 : bounds.width + 1) - size / 2}
  28. y={(isTop ? -1 : bounds.height + 1) - size / 2}
  29. width={size}
  30. height={size}
  31. pointerEvents="none"
  32. />
  33. </g>
  34. )
  35. }
  36. const StyledCorner = styled('rect', {
  37. stroke: 'none',
  38. fill: 'transparent',
  39. variants: {
  40. corner: {
  41. [Corner.TopLeft]: { cursor: 'nwse-resize' },
  42. [Corner.TopRight]: { cursor: 'nesw-resize' },
  43. [Corner.BottomRight]: { cursor: 'nwse-resize' },
  44. [Corner.BottomLeft]: { cursor: 'nesw-resize' },
  45. },
  46. },
  47. })
  48. const StyledCornerInner = styled('rect', {
  49. stroke: '$bounds',
  50. fill: '$panel',
  51. zStrokeWidth: 1.5,
  52. })