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.

cursor.tsx 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import React, { useEffect, useRef } from 'react'
  2. import styled from 'styles'
  3. export default function Cursor(): JSX.Element {
  4. const rCursor = useRef<SVGSVGElement>(null)
  5. useEffect(() => {
  6. function updatePosition(e: PointerEvent) {
  7. const cursor = rCursor.current
  8. cursor.setAttribute(
  9. 'transform',
  10. `translate(${e.clientX - 12} ${e.clientY - 10})`
  11. )
  12. }
  13. document.body.addEventListener('pointermove', updatePosition)
  14. return () => {
  15. document.body.removeEventListener('pointermove', updatePosition)
  16. }
  17. }, [])
  18. return (
  19. <StyledCursor
  20. ref={rCursor}
  21. width="35px"
  22. height="35px"
  23. viewBox="0 0 35 35"
  24. version="1.1"
  25. pointerEvents="none"
  26. xmlns="http://www.w3.org/2000/svg"
  27. xmlnsXlink="http://www.w3.org/1999/xlink"
  28. >
  29. <path
  30. d="M12,24.4219 L12,8.4069 L23.591,20.0259 L16.81,20.0259 L16.399,20.1499 L12,24.4219 Z"
  31. id="point-border"
  32. fill="#FFFFFF"
  33. />
  34. <path
  35. d="M21.0845,25.0962 L17.4795,26.6312 L12.7975,15.5422 L16.4835,13.9892 L21.0845,25.0962 Z"
  36. id="stem-border"
  37. fill="#FFFFFF"
  38. />
  39. <path
  40. d="M19.751,24.4155 L17.907,25.1895 L14.807,17.8155 L16.648,17.0405 L19.751,24.4155 Z"
  41. id="stem"
  42. fill="#000000"
  43. />
  44. <path
  45. d="M13,10.814 L13,22.002 L15.969,19.136 L16.397,18.997 L21.165,18.997 L13,10.814 Z"
  46. id="point"
  47. fill="#000000"
  48. />
  49. </StyledCursor>
  50. )
  51. }
  52. const StyledCursor = styled('g', {
  53. position: 'absolute',
  54. zIndex: 1000,
  55. top: 0,
  56. left: 0,
  57. })