Better performance on large workspaces

This commit is contained in:
Gregory Schier
2024-06-21 10:53:11 -07:00
parent 5722880890
commit 151450f55b
3 changed files with 231 additions and 230 deletions

View File

@@ -167,32 +167,34 @@ export const Dropdown = forwardRef<DropdownRef, DropdownProps>(function Dropdown
});
interface ContextMenuProps {
show: { x: number; y: number } | null;
triggerPosition: { x: number; y: number } | null;
className?: string;
items: DropdownProps['items'];
onClose: () => void;
}
export const ContextMenu = forwardRef<DropdownRef, ContextMenuProps>(function ContextMenu(
{ show, className, items, onClose },
{ triggerPosition, className, items, onClose },
ref,
) {
const triggerShape = useMemo(
() => ({
top: show?.y ?? 0,
bottom: show?.y ?? 0,
left: show?.x ?? 0,
right: show?.x ?? 0,
top: triggerPosition?.y ?? 0,
bottom: triggerPosition?.y ?? 0,
left: triggerPosition?.x ?? 0,
right: triggerPosition?.x ?? 0,
}),
[show],
[triggerPosition],
);
if (triggerPosition == null) return null;
return (
<Menu
isOpen // Always open because we return null if not
className={className}
ref={ref}
items={items}
isOpen={show != null}
onClose={onClose}
triggerShape={triggerShape}
/>