source: imaps-frontend/node_modules/react-use/lib/useMouse.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.7 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tslib_1 = require("tslib");
4var react_1 = require("react");
5var useRafState_1 = tslib_1.__importDefault(require("./useRafState"));
6var util_1 = require("./misc/util");
7var useMouse = function (ref) {
8 if (process.env.NODE_ENV === 'development') {
9 if (typeof ref !== 'object' || typeof ref.current === 'undefined') {
10 console.error('useMouse expects a single ref argument.');
11 }
12 }
13 var _a = useRafState_1.default({
14 docX: 0,
15 docY: 0,
16 posX: 0,
17 posY: 0,
18 elX: 0,
19 elY: 0,
20 elH: 0,
21 elW: 0,
22 }), state = _a[0], setState = _a[1];
23 react_1.useEffect(function () {
24 var moveHandler = function (event) {
25 if (ref && ref.current) {
26 var _a = ref.current.getBoundingClientRect(), left = _a.left, top_1 = _a.top, elW = _a.width, elH = _a.height;
27 var posX = left + window.pageXOffset;
28 var posY = top_1 + window.pageYOffset;
29 var elX = event.pageX - posX;
30 var elY = event.pageY - posY;
31 setState({
32 docX: event.pageX,
33 docY: event.pageY,
34 posX: posX,
35 posY: posY,
36 elX: elX,
37 elY: elY,
38 elH: elH,
39 elW: elW,
40 });
41 }
42 };
43 util_1.on(document, 'mousemove', moveHandler);
44 return function () {
45 util_1.off(document, 'mousemove', moveHandler);
46 };
47 }, [ref]);
48 return state;
49};
50exports.default = useMouse;
Note: See TracBrowser for help on using the repository browser.