Add ReusableContextMenu component

Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
Ajay Bura 2022-01-11 20:43:40 +05:30
parent 769d24d196
commit cb23991841
2 changed files with 103 additions and 2 deletions

View file

@ -21,11 +21,28 @@ export function isInSameDay(dt2, dt1) {
);
}
export function getEventCords(ev) {
const boxInfo = ev.target.getBoundingClientRect();
/**
* @param {Event} ev
* @param {string} [targetSelector] element selector for Element.matches([selector])
*/
export function getEventCords(ev, targetSelector) {
let boxInfo;
const path = ev.nativeEvent.composedPath();
const target = targetSelector
? path.find((element) => element.matches?.(targetSelector))
: null;
if (target) {
boxInfo = target.getBoundingClientRect();
} else {
boxInfo = ev.target.getBoundingClientRect();
}
return {
x: boxInfo.x,
y: boxInfo.y,
width: boxInfo.width,
height: boxInfo.height,
detail: ev.detail,
};
}