import { PluginID, PluginKey } from '@/types/plugin'; import { IconKey } from '@tabler/icons-react'; import { FC, KeyboardEvent, useEffect, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { SidebarButton } from '../Sidebar/SidebarButton'; interface Props { pluginKeys: PluginKey[]; onPluginKeyChange: (pluginKey: PluginKey) => void; onClearPluginKey: (pluginKey: PluginKey) => void; } export const PluginKeys: FC = ({ pluginKeys, onPluginKeyChange, onClearPluginKey, }) => { const { t } = useTranslation('sidebar'); const [isChanging, setIsChanging] = useState(false); const modalRef = useRef(null); const handleEnter = (e: KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); setIsChanging(false); } }; useEffect(() => { const handleMouseDown = (e: MouseEvent) => { if (modalRef.current && !modalRef.current.contains(e.target as Node)) { window.addEventListener('mouseup', handleMouseUp); } }; const handleMouseUp = (e: MouseEvent) => { window.removeEventListener('mouseup', handleMouseUp); setIsChanging(false); }; window.addEventListener('mousedown', handleMouseDown); return () => { window.removeEventListener('mousedown', handleMouseDown); }; }, []); return ( <> } onClick={() => setIsChanging(true)} /> {isChanging && (
)} ); };