InsertCursor.tsx 850 B

123456789101112131415161718192021222324252627282930313233
  1. import React, { useEffect } from 'react';
  2. import Cursor from '../components/Cursor';
  3. import useCursorPosition from '../hooks/useCursorPosition';
  4. import useStore from '../store';
  5. const InsertCursor = () => {
  6. const [{ toolState }] = useStore();
  7. const [cursorPosition, setRef] = useCursorPosition(25);
  8. useEffect(() => {
  9. const viewer = document.getElementById('pdf_viewer') as HTMLDivElement;
  10. if (toolState && viewer) {
  11. setRef(viewer);
  12. viewer.style.cursor = 'crosshair';
  13. } else if (viewer) {
  14. setRef(null);
  15. viewer.style.cursor = 'auto';
  16. }
  17. }, [toolState]);
  18. return ['textfield', 'checkbox', 'radio'].includes(toolState) ? (
  19. <Cursor
  20. x={cursorPosition.clientX || -1000}
  21. y={cursorPosition.clientY || -1000}
  22. appearance={toolState}
  23. />
  24. ) : null;
  25. };
  26. export default InsertCursor;