import React, { useLayoutEffect, useRef, useState } from 'react'; import { EllipsisHorizontalCircleIcon, PencilSquareIcon, TrashIcon } from '@heroicons/react/24/outline'; import Portal from '../ui/Portal'; import type { InventoryItem } from '../../hooks/useInventory'; interface Props { item: InventoryItem; onEdit: (item: InventoryItem) => void; onDelete: (item: InventoryItem) => void; } const MENU_W = 160; /** * «عملیات» trigger + dropdown — mirrors the tauri InventoryActionsPopover. * Rendered through a Portal with fixed positioning so it is never clipped by the * table container's `overflow: hidden`. */ export default function InventoryActionsMenu({ item, onEdit, onDelete }: Props) { const [open, setOpen] = useState(false); const [pos, setPos] = useState<{ top: number; left: number }>({ top: 0, left: 0 }); const triggerRef = useRef(null); useLayoutEffect(() => { if (!open || !triggerRef.current) return; const place = () => { const r = triggerRef.current!.getBoundingClientRect(); // align the menu's right edge to the trigger's right edge (RTL-friendly) const left = Math.max(8, Math.min(r.right - MENU_W, window.innerWidth - MENU_W - 8)); setPos({ top: r.bottom + 4, left }); }; place(); window.addEventListener('scroll', place, true); window.addEventListener('resize', place); return () => { window.removeEventListener('scroll', place, true); window.removeEventListener('resize', place); }; }, [open]); return ( <> {open && (
setOpen(false)} style={{ position: 'fixed', inset: 0, zIndex: 60 }} />
)} ); }