mirror of
https://github.com/immich-app/immich
synced 2025-10-17 18:19:27 +00:00
feat(web): better context menu position (#4271)
* feat(web): better context menu position * fix: album context menu * fix: add middle variant * fix: rest of context menus * fix: linting error
This commit is contained in:
parent
3e73cfb71a
commit
68d6d89a3b
8 changed files with 40 additions and 29 deletions
18
web/src/lib/utils/context-menu.ts
Normal file
18
web/src/lib/utils/context-menu.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
export type Align = 'middle' | 'top-left' | 'top-right';
|
||||
|
||||
export const getContextMenuPosition = (event: MouseEvent, align: Align = 'middle') => {
|
||||
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 };
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue