-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathDOMUtil.ts
39 lines (35 loc) · 997 Bytes
/
DOMUtil.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { IDatePicker } from '../common/@types';
const convertPx = (value: number) => `${value}px`;
/**
* Getting Div position as far as distance
* @param node
* @param direction
* @param distance
*/
export const getDivPosition = (
node: HTMLDivElement | null,
direction: IDatePicker.PickerDirection = IDatePicker.PickerDirection.BOTTOM,
height: number,
distance: number = 5
): IDatePicker.Position => {
if (!node) return { left: '', top: '', bottom: '' };
let top = 0;
let left = 0;
switch (direction) {
case IDatePicker.PickerDirection.BOTTOM:
top = node.offsetTop + node.offsetHeight + distance;
left = node.offsetLeft;
break;
case IDatePicker.PickerDirection.TOP:
top = node.offsetTop - height - distance;
left = node.offsetLeft;
break;
}
return {
top: convertPx(top),
left: convertPx(left),
};
};
export const getDomHeight = (node: HTMLDivElement | null): number => {
return node ? node.clientHeight : 0;
};