From 9a7f15b1d24997076295f27b2a8a6a843a188fb0 Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Thu, 11 Mar 2021 16:57:03 +0100 Subject: [PATCH 1/2] Use single context menu --- .../file-explorer/src/lib/file-explorer.tsx | 192 ++++++++---------- 1 file changed, 85 insertions(+), 107 deletions(-) diff --git a/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx b/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx index 97f25ff8aa..94ee19d2af 100644 --- a/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx +++ b/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx @@ -32,7 +32,8 @@ export const FileExplorer = (props: FileExplorerProps) => { focusContext: { element: null, x: null, - y: null + y: null, + type: '' }, focusEdit: { element: null, @@ -57,7 +58,8 @@ export const FileExplorer = (props: FileExplorerProps) => { }, modals: [], toasterMsg: '', - mouseOverElement: null + mouseOverElement: null, + showContextMenu: false }) const editRef = useRef(null) @@ -755,20 +757,20 @@ export const FileExplorer = (props: FileExplorerProps) => { const handleContextMenuFile = (pageX: number, pageY: number, path: string, content: string) => { if (!content) return setState(prevState => { - return { ...prevState, focusContext: { element: path, x: pageX, y: pageY }, focusEdit: { ...prevState.focusEdit, lastEdit: content } } + return { ...prevState, focusContext: { element: path, x: pageX, y: pageY, type: 'file' }, focusEdit: { ...prevState.focusEdit, lastEdit: content }, showContextMenu: prevState.focusEdit.element !== path } }) } const handleContextMenuFolder = (pageX: number, pageY: number, path: string, content: string) => { if (!content) return setState(prevState => { - return { ...prevState, focusContext: { element: path, x: pageX, y: pageY }, focusEdit: { ...prevState.focusEdit, lastEdit: content } } + return { ...prevState, focusContext: { element: path, x: pageX, y: pageY, type: 'folder' }, focusEdit: { ...prevState.focusEdit, lastEdit: content }, showContextMenu: prevState.focusEdit.element !== path } }) } const hideContextMenu = () => { setState(prevState => { - return { ...prevState, focusContext: { element: null, x: 0, y: 0 } } + return { ...prevState, focusContext: { element: null, x: 0, y: 0, type: '' }, showContextMenu: false } }) } @@ -907,113 +909,69 @@ export const FileExplorer = (props: FileExplorerProps) => { if (file.isDirectory) { return ( -
- { - e.stopPropagation() - if (state.focusEdit.element !== file.path) handleClickFolder(file.path) - }} - onContextMenu={(e) => { - e.preventDefault() - e.stopPropagation() - handleContextMenuFolder(e.pageX, e.pageY, file.path, e.target.textContent) - }} - labelClass={labelClass} - controlBehaviour={ state.ctrlKey } - expand={state.expandPath.includes(file.path)} - onMouseOver={(e) => { - e.stopPropagation() - handleMouseOver(file.path) - }} - onMouseOut={(e) => { - e.stopPropagation() - if (state.mouseOverElement === file.path) handleMouseOut() - }} - > - { - file.child ? { - file.child.map((file, index) => { - return renderFiles(file, index) - }) - } - : + { + e.stopPropagation() + if (state.focusEdit.element !== file.path) handleClickFolder(file.path) + }} + onContextMenu={(e) => { + e.preventDefault() + e.stopPropagation() + handleContextMenuFolder(e.pageX, e.pageY, file.path, e.target.textContent) + }} + labelClass={labelClass} + controlBehaviour={ state.ctrlKey } + expand={state.expandPath.includes(file.path)} + onMouseOver={(e) => { + e.stopPropagation() + handleMouseOver(file.path) + }} + onMouseOut={(e) => { + e.stopPropagation() + if (state.mouseOverElement === file.path) handleMouseOut() + }} + > + { + file.child ? { + file.child.map((file, index) => { + return renderFiles(file, index) + }) } - - { ((state.focusContext.element === file.path) && (state.focusEdit.element !== file.path)) && - { - e.stopPropagation() - handleMouseOver(file.path) - }} - /> + : } -
+ ) } else { return ( -
- { - e.stopPropagation() - if (state.focusEdit.element !== file.path) handleClickFile(file.path) - }} - onContextMenu={(e) => { - e.preventDefault() - e.stopPropagation() - handleContextMenuFile(e.pageX, e.pageY, file.path, e.target.textContent) - }} - icon={icon} - labelClass={labelClass} - onMouseOver={(e) => { - e.stopPropagation() - handleMouseOver(file.path) - }} - onMouseOut={(e) => { - e.stopPropagation() - if (state.mouseOverElement === file.path) handleMouseOut() - }} - /> - { ((state.focusContext.element === file.path) && (state.focusEdit.element !== file.path)) && - { - e.stopPropagation() - handleMouseOver(file.path) - }} - /> - } -
+ { + e.stopPropagation() + if (state.focusEdit.element !== file.path) handleClickFile(file.path) + }} + onContextMenu={(e) => { + e.preventDefault() + e.stopPropagation() + handleContextMenuFile(e.pageX, e.pageY, file.path, e.target.textContent) + }} + icon={icon} + labelClass={labelClass} + onMouseOver={(e) => { + e.stopPropagation() + handleMouseOver(file.path) + }} + onMouseOut={(e) => { + e.stopPropagation() + if (state.mouseOverElement === file.path) handleMouseOut() + }} + /> ) } } @@ -1073,6 +1031,26 @@ export const FileExplorer = (props: FileExplorerProps) => { /> } + { state.showContextMenu && + { + e.stopPropagation() + handleMouseOver(state.focusContext.element) + }} + /> + } ) } From 196e25d14c172c144b2adcba9ebcfaac77e4f4d1 Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Fri, 12 Mar 2021 13:20:52 +0100 Subject: [PATCH 2/2] Set position to fixed --- .../file-explorer/src/lib/file-explorer-context-menu.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-ui/file-explorer/src/lib/file-explorer-context-menu.tsx b/libs/remix-ui/file-explorer/src/lib/file-explorer-context-menu.tsx index 3a842d91b3..3e6b308a35 100644 --- a/libs/remix-ui/file-explorer/src/lib/file-explorer-context-menu.tsx +++ b/libs/remix-ui/file-explorer/src/lib/file-explorer-context-menu.tsx @@ -16,7 +16,7 @@ export const FileExplorerContextMenu = (props: FileExplorerContextMenuProps) => const boundary = menuItemsContainer.getBoundingClientRect() if (boundary.bottom > (window.innerHeight || document.documentElement.clientHeight)) { - menuItemsContainer.style.position = 'absolute' + menuItemsContainer.style.position = 'fixed' menuItemsContainer.style.bottom = '10px' menuItemsContainer.style.top = null }