mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-09-14 06:42:25 +03:00
Add ReusableContextMenu component
Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
parent
769d24d196
commit
cb23991841
2 changed files with 103 additions and 2 deletions
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue