Created
April 15, 2020 10:06
-
-
Save loopmode/f1760d6562d9fa04ff73b64d0fe25651 to your computer and use it in GitHub Desktop.
use-electron-context-menu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* example of making inspector menu item available on everything from the "root" component | |
*/ | |
import { hot } from 'react-hot-loader/root'; | |
import React from 'react'; | |
import useContextMenu from './hooks/use-context-menu'; | |
const App: React.FC = React.memo(() => { | |
useContextMenu('body', { showInspectElement: true }); | |
// return ( | |
// <Router history={appHistory}> | |
// ... | |
// </Router> | |
// ); | |
return null; | |
}); | |
export default hot(App); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* example of using a custom menu on list items | |
*/ | |
import React, { useRef, useCallback } from 'react'; | |
import { useDispatch } from 'react-redux'; | |
import { | |
removeCommand, | |
cloneCommand | |
} from 'renderer/model/slices/project/project-slice'; | |
import useContextMenu from 'renderer/hooks/use-context-menu'; | |
export interface CommandListItemProps { | |
command: Command; | |
} | |
export const CommandListItem: React.FC<CommandListItemProps> = ({ | |
command | |
}) => { | |
const ref = useRef(null); | |
const dispatch = useDispatch(); | |
const handleDelete = useCallback(() => { | |
dispatch(removeCommand(command)); | |
}, [command.id]); | |
const handleClone = React.useCallback(() => dispatch(cloneCommand(command)), [ | |
command.id | |
]); | |
useContextMenu( | |
ref, | |
{ | |
showInspectElement: process.env.NODE_ENV !== 'production', | |
items: [ | |
{ | |
id: 'clone-command', | |
enabled: true, | |
label: 'Clone command', | |
click: handleClone | |
}, | |
{ | |
id: 'delete-command', | |
enabled: true, | |
label: 'Delete command', | |
click: handleDelete | |
} | |
] | |
}, | |
[command.id] | |
); | |
return <div ref={ref}>command list item</div>; | |
// return ( | |
// <CommandListItemView | |
// {...props} | |
// ref={ref} | |
// className={className} | |
// command={command} | |
// showDeleteButton={withDeleteButton} | |
// showDeleteModal={deleteModalVisible} | |
// onDeleteShowModal={showConfirmDelete} | |
// onDeleteCancel={hideConfirmDelete} | |
// onDeleteConfirm={handleConfirmDelete} | |
// showProcessButton={withControlButton} | |
// isProcessRunning={!!processId} | |
// onProcessClick={handleProcessClick} | |
// /> | |
// ); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment