InsertCursor.tsx 958 B

1234567891011121314151617181920212223242526272829303132333435
  1. import React, { useEffect, useState } from 'react';
  2. import CursorImage from '../components/Cursor';
  3. import useStore from '../store';
  4. const InsertCursor = () => {
  5. const [{ toolState }] = useStore();
  6. const [position, setPosition] = useState({ x: 0, y: 0 });
  7. const getMousePosition = (event: any) => {
  8. setPosition({
  9. x: event.clientX,
  10. y: event.clientY,
  11. });
  12. };
  13. useEffect(() => {
  14. const viewer = document.getElementById('pdf_viewer') as HTMLDivElement;
  15. if (toolState && viewer) {
  16. viewer.addEventListener('mousemove', getMousePosition);
  17. viewer.style.cursor = 'crosshair';
  18. } else if (viewer) {
  19. viewer.removeEventListener('mousemove', getMousePosition);
  20. viewer.style.cursor = 'auto';
  21. }
  22. }, [toolState]);
  23. return ['textfield', 'checkbox', 'radio'].includes(toolState) ? (
  24. <CursorImage x={position.x} y={position.y} appearance={toolState} />
  25. ) : null;
  26. };
  27. export default InsertCursor;