diff --git a/app/components/ContextMenuViewer/contextMenuViewer.module.css b/app/components/ContextMenuViewer/contextMenuViewer.module.css new file mode 100644 index 0000000..059e5f3 --- /dev/null +++ b/app/components/ContextMenuViewer/contextMenuViewer.module.css @@ -0,0 +1,23 @@ +.container { + position: absolute; + background-color: var(--background); + border-radius: 6px; + border: 1px solid var(--grey-normal); + margin: 0; + padding: 0; + animation: var(--intro-animation); + box-sizing: border-box; + overflow: hidden; +} + +.item { + min-width: 100px; + cursor: default; + list-style: none; + margin: 0; + padding: 10px; +} + +.item:hover { + background-color: var(--grey-normal); +} diff --git a/app/components/ContextMenuViewer/index.tsx b/app/components/ContextMenuViewer/index.tsx new file mode 100644 index 0000000..134d86a --- /dev/null +++ b/app/components/ContextMenuViewer/index.tsx @@ -0,0 +1,39 @@ +import { useContextMenu } from '@/states/contextMenu'; +import styles from './contextMenuViewer.module.css'; +import { CSSProperties, useEffect } from 'react'; + +export default function ContextMenuViewer() { + const { menu, setMenu } = useContextMenu((state) => ({ + menu: state.menu, + setMenu: state.setMenu, + })); + + useEffect(() => { + if (menu === null) return; + const pointerDown = () => setMenu(null); + document.addEventListener('pointerdown', pointerDown); + return () => document.removeEventListener('pointerdown', pointerDown); + }, [menu, setMenu]); + + if (menu === null) return <>>; + + const style: CSSProperties = {}; + // check x overflow + if (menu.position.x < window.innerWidth / 2) style.left = menu.position.x; + else style.right = window.innerWidth - menu.position.x; + // check y overflow + if (menu.position.y < window.innerHeight / 2) style.top = menu.position.y; + else style.bottom = window.innerHeight - menu.position.y; + + return ( +
no graph available
; + const mindMapData = useViewer((state) => state.mindMapData); + if (mindMapData === null) returnno graph available
; return ( <>