瀏覽代碼

fix(component): cursor position not display image

RoyLiu 4 年之前
父節點
當前提交
3230a372b0
共有 3 個文件被更改,包括 58 次插入11 次删除
  1. 1 0
      components/DeleteDialog/styled.ts
  2. 13 11
      containers/InsertCursor.tsx
  3. 44 0
      public/icons/check-mark.svg

+ 1 - 0
components/DeleteDialog/styled.ts

@@ -3,6 +3,7 @@ import styled from 'styled-components';
 export const TextWrapper = styled.div`
   width: 324px;
   margin-bottom: 16px;
+  font-size: 1.25rem;
 `;
 
 export const BtnWrapper = styled.div`

+ 13 - 11
containers/InsertCursor.tsx

@@ -1,32 +1,34 @@
-import React, { useEffect } from 'react';
+import React, { useEffect, useState } from 'react';
 
-import Cursor from '../components/Cursor';
-import useCursorPosition from '../hooks/useCursorPosition';
+import CursorImage from '../components/Cursor';
 
 import useStore from '../store';
 
 const InsertCursor = () => {
   const [{ toolState }] = useStore();
-  const [cursorPosition, setRef] = useCursorPosition(25);
+  const [position, setPosition] = useState({ x: 0, y: 0 });
+
+  const getMousePosition = (event: any) => {
+    setPosition({
+      x: event.clientX,
+      y: event.clientY,
+    });
+  };
 
   useEffect(() => {
     const viewer = document.getElementById('pdf_viewer') as HTMLDivElement;
 
     if (toolState && viewer) {
-      setRef(viewer);
+      viewer.addEventListener('mousemove', getMousePosition);
       viewer.style.cursor = 'crosshair';
     } else if (viewer) {
-      setRef(null);
+      viewer.removeEventListener('mousemove', getMousePosition);
       viewer.style.cursor = 'auto';
     }
   }, [toolState]);
 
   return ['textfield', 'checkbox', 'radio'].includes(toolState) ? (
-    <Cursor
-      x={cursorPosition.clientX || -1000}
-      y={cursorPosition.clientY || -1000}
-      appearance={toolState}
-    />
+    <CursorImage x={position.x} y={position.y} appearance={toolState} />
   ) : null;
 };
 

+ 44 - 0
public/icons/check-mark.svg

@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
+	 width="45.701px" height="45.7px" viewBox="0 0 45.701 45.7" style="enable-background:new 0 0 45.701 45.7;" xml:space="preserve"
+	>
+<g>
+	<g>
+		<path d="M20.687,38.332c-2.072,2.072-5.434,2.072-7.505,0L1.554,26.704c-2.072-2.071-2.072-5.433,0-7.504
+			c2.071-2.072,5.433-2.072,7.505,0l6.928,6.927c0.523,0.522,1.372,0.522,1.896,0L36.642,7.368c2.071-2.072,5.433-2.072,7.505,0
+			c0.995,0.995,1.554,2.345,1.554,3.752c0,1.407-0.559,2.757-1.554,3.752L20.687,38.332z"/>
+	</g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+</svg>