@@ -3,7 +3,7 @@ import Paper from '@material-ui/core/Paper';
33import { makeStyles } from '@material-ui/core' ;
44import Typography from '@material-ui/core/Typography' ;
55import CheckIcon from '@material-ui/icons/Check' ;
6- import { Menu , Item , MenuProvider } from 'react-contexify' ;
6+ import { Menu , Item , useContextMenu } from 'react-contexify' ;
77import 'react-contexify/dist/ReactContexify.min.css' ;
88import CopyIcon from '@material-ui/icons/FileCopy' ;
99
@@ -19,6 +19,7 @@ const useStyles = makeStyles((theme) => ({
1919const Hash = ( {
2020 hashType, content, compareString, id, copy,
2121} ) => {
22+ const MENU_ID = `hashMenu${ id } ` ;
2223 const classes = useStyles ( ) ;
2324
2425 let compareColor = null ;
@@ -28,15 +29,32 @@ const Hash = ({
2829 compareColor = { color : 'green' } ;
2930 }
3031
32+ const { show } = useContextMenu ( {
33+ id : MENU_ID ,
34+ } ) ;
35+
36+ /**
37+ * Handle the context menu event
38+ * @param event The event argument
39+ */
40+ const handleContextMenu = ( event ) => {
41+ event . preventDefault ( ) ;
42+ show ( event , {
43+ props : {
44+ key : 'value' ,
45+ } ,
46+ } ) ;
47+ } ;
48+
3149 return (
3250 < Paper className = { classes . paper } >
3351 < Typography variant = "subtitle1" color = "primary" gutterBottom >
3452 { hashType }
3553 { compareIcon }
3654 </ Typography >
37- < MenuProvider id = { `hashMenu ${ id } ` } >
55+ < div onContextMenu = { handleContextMenu } >
3856 < span style = { compareColor } > { content } </ span >
39- </ MenuProvider >
57+ </ div >
4058 < Menu id = { `hashMenu${ id } ` } >
4159 < Item onClick = { ( ) => navigator . clipboard . writeText ( content ) } >
4260 < CopyIcon />
0 commit comments