1
0
forked from Cutlery/immich
immich-quadlet/web/src/lib/utils/context-menu.ts
Michel Heusschen cfb14ca80b
fix(web): minor album card issues (#7975)
* fix(web): minor album card issues

* fix album grid gap
2024-03-15 12:03:54 -04:00

24 lines
687 B
TypeScript

export type Align = 'middle' | 'top-left' | 'top-right';
export type ContextMenuPosition = { x: number; y: number };
export const getContextMenuPosition = (event: MouseEvent, align: Align = 'middle'): ContextMenuPosition => {
const { x, y, currentTarget, target } = event;
const box = ((currentTarget || target) as HTMLElement)?.getBoundingClientRect();
if (box) {
switch (align) {
case 'middle': {
return { x: box.x + box.width / 2, y: box.y + box.height / 2 };
}
case 'top-left': {
return { x: box.x, y: box.y };
}
case 'top-right': {
return { x: box.x + box.width, y: box.y };
}
}
}
return { x, y };
};