import { MouseEvent } from 'react' ; type TDetectMouseButtonOptions = { allowAltClick ? : boolean ; allowCtrlClick ? : boolean ; allowMetaClick ? : boolean ; allowShiftClick ? : boolean ; } ; buttonNumber export function detectMouseButton ( evt , buttonNumber = 1 , options = { } ) { if ( ( evt . metaKey && ! options . allowMetaClick ) || ( evt . ctrlKey && ! options . allowCtrlClick ) || ( evt . altKey && ! options . allowAltClick ) || ( evt . shiftKey && ! options . allowShiftClick ) ) { return false ; } if ( 'buttons' in evt ) { return evt . buttons === buttonNumber ; } if ( 'which' in evt ) { return ( evt as KeyboardEvent ) . which === buttonNumber ; } return ( evt as MouseEvent ) . button === buttonNumber - 1 ; }