@react-pakistan/util-functions 1.11.5 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/hooks/use-position.d.ts +26 -0
- package/hooks/use-position.js +43 -0
- package/package.json +10 -10
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A util hook to get element positioning.
|
|
3
|
+
*
|
|
4
|
+
* @param elementRef as an element ref for it's position
|
|
5
|
+
* @returns [x, y]
|
|
6
|
+
* @author Taimoor Khan
|
|
7
|
+
* @remarks
|
|
8
|
+
*/
|
|
9
|
+
/** End file docs */
|
|
10
|
+
import { RefObject } from 'react';
|
|
11
|
+
declare type PositionRef = {
|
|
12
|
+
offsetLeft: 0 | null;
|
|
13
|
+
offsetRight: 0 | null;
|
|
14
|
+
offsetTop: 0 | null;
|
|
15
|
+
offsetBottom: 0 | null;
|
|
16
|
+
};
|
|
17
|
+
declare type StateX = {
|
|
18
|
+
xLeft: 0 | null;
|
|
19
|
+
xRight: 0 | null;
|
|
20
|
+
};
|
|
21
|
+
declare type StateY = {
|
|
22
|
+
yTop: 0 | null;
|
|
23
|
+
yBottom: 0 | null;
|
|
24
|
+
};
|
|
25
|
+
export declare const usePosition: (elementRef: RefObject<PositionRef>) => [StateX, StateY];
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* A util hook to get element positioning.
|
|
4
|
+
*
|
|
5
|
+
* @param elementRef as an element ref for it's position
|
|
6
|
+
* @returns [x, y]
|
|
7
|
+
* @author Taimoor Khan
|
|
8
|
+
* @remarks
|
|
9
|
+
*/
|
|
10
|
+
/** End file docs */
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.usePosition = void 0;
|
|
13
|
+
const react_1 = require("react");
|
|
14
|
+
const usePosition = (elementRef) => {
|
|
15
|
+
const [x, setX] = (0, react_1.useState)({
|
|
16
|
+
xLeft: 0,
|
|
17
|
+
xRight: 0,
|
|
18
|
+
});
|
|
19
|
+
const [y, setY] = (0, react_1.useState)({
|
|
20
|
+
yTop: 0,
|
|
21
|
+
yBottom: 0,
|
|
22
|
+
});
|
|
23
|
+
const getPosition = (0, react_1.useCallback)(() => {
|
|
24
|
+
var _a, _b, _c, _d;
|
|
25
|
+
const xLeft = ((_a = elementRef === null || elementRef === void 0 ? void 0 : elementRef.current) === null || _a === void 0 ? void 0 : _a.offsetLeft) || null;
|
|
26
|
+
const xRight = ((_b = elementRef === null || elementRef === void 0 ? void 0 : elementRef.current) === null || _b === void 0 ? void 0 : _b.offsetRight) || null;
|
|
27
|
+
const yTop = ((_c = elementRef === null || elementRef === void 0 ? void 0 : elementRef.current) === null || _c === void 0 ? void 0 : _c.offsetTop) || null;
|
|
28
|
+
const yBottom = ((_d = elementRef === null || elementRef === void 0 ? void 0 : elementRef.current) === null || _d === void 0 ? void 0 : _d.offsetBottom) || null;
|
|
29
|
+
setX({
|
|
30
|
+
xLeft,
|
|
31
|
+
xRight,
|
|
32
|
+
});
|
|
33
|
+
setY({
|
|
34
|
+
yTop,
|
|
35
|
+
yBottom,
|
|
36
|
+
});
|
|
37
|
+
}, [elementRef, setX, setY]);
|
|
38
|
+
(0, react_1.useEffect)(() => {
|
|
39
|
+
getPosition();
|
|
40
|
+
}, [getPosition]);
|
|
41
|
+
return [x, y];
|
|
42
|
+
};
|
|
43
|
+
exports.usePosition = usePosition;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-pakistan/util-functions",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "A library of all util functions",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -39,25 +39,25 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@microsoft/tsdoc": "^0.14.1",
|
|
41
41
|
"date-fns": "^2.29.2",
|
|
42
|
-
"date-fns-tz": "^1.3.
|
|
42
|
+
"date-fns-tz": "^1.3.7",
|
|
43
43
|
"lodash.curry": "^4.1.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@babel/core": "^7.
|
|
46
|
+
"@babel/core": "^7.19.0",
|
|
47
47
|
"@babel/eslint-parser": "^7.18.9",
|
|
48
48
|
"@babel/preset-typescript": "^7.18.6",
|
|
49
|
-
"@react-pakistan/eslint-config-shared": "^1.4.
|
|
50
|
-
"@types/jest": "^
|
|
49
|
+
"@react-pakistan/eslint-config-shared": "^1.4.36",
|
|
50
|
+
"@types/jest": "^29.0.0",
|
|
51
51
|
"@types/lodash.curry": "^4.1.7",
|
|
52
|
-
"@types/node": "^18.7.
|
|
52
|
+
"@types/node": "^18.7.15",
|
|
53
53
|
"@types/react-redux": "^7.1.24",
|
|
54
54
|
"@types/styled-components": "^5.1.26",
|
|
55
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
56
|
-
"@typescript-eslint/parser": "^5.
|
|
57
|
-
"eslint": "^8.
|
|
55
|
+
"@typescript-eslint/eslint-plugin": "^5.36.2",
|
|
56
|
+
"@typescript-eslint/parser": "^5.36.2",
|
|
57
|
+
"eslint": "^8.23.0",
|
|
58
58
|
"eslint-plugin-import": "^2.26.0",
|
|
59
59
|
"husky": "^8.0.1",
|
|
60
|
-
"jest": "^29.0.
|
|
60
|
+
"jest": "^29.0.2",
|
|
61
61
|
"lint-staged": "^13.0.3",
|
|
62
62
|
"lodash.isequal": "^4.5.0",
|
|
63
63
|
"react": "^18.2.0",
|