import React from 'react'; import { createPortal } from 'react-dom'; interface DesktopSpeedMenuProps { showSpeedMenu: boolean; playbackRate: number; speeds: number[]; onSpeedChange: (speed: number) => void; onToggleSpeedMenu: () => void; onMouseEnter: () => void; onMouseLeave: () => void; containerRef: React.RefObject; } export function DesktopSpeedMenu({ showSpeedMenu, playbackRate, speeds, onSpeedChange, onToggleSpeedMenu, onMouseEnter, onMouseLeave, containerRef }: DesktopSpeedMenuProps) { const buttonRef = React.useRef(null); const [menuPosition, setMenuPosition] = React.useState({ top: 0, left: 0 }); React.useEffect(() => { if (showSpeedMenu && buttonRef.current && containerRef.current) { const buttonRect = buttonRef.current.getBoundingClientRect(); const containerRect = containerRef.current.getBoundingClientRect(); setMenuPosition({ top: buttonRect.bottom - containerRect.top + 10, left: buttonRect.right - containerRect.left }); } }, [showSpeedMenu, containerRef]); const handleToggle = () => { if (!showSpeedMenu && buttonRef.current && containerRef.current) { const buttonRect = buttonRef.current.getBoundingClientRect(); const containerRect = containerRef.current.getBoundingClientRect(); setMenuPosition({ top: buttonRect.bottom - containerRect.top + 10, left: buttonRect.right - containerRect.left }); } onToggleSpeedMenu(); }; const MenuContent = (
{speeds.map((speed) => ( ))}
); return (
{/* Speed Menu (Portal) */} {showSpeedMenu && typeof document !== 'undefined' && createPortal(MenuContent, containerRef.current || document.body)}
); }