Skip to content

Instantly share code, notes, and snippets.

@neiljohnston
Created February 2, 2022 16:00
Show Gist options
  • Save neiljohnston/e359b357c570031b5326093ca94153d8 to your computer and use it in GitHub Desktop.
Save neiljohnston/e359b357c570031b5326093ca94153d8 to your computer and use it in GitHub Desktop.
Framer Right Click / oncontextmenu - How to capture a right click/oncontextmenu event in framer/react
import type { ComponentType } from "react"
import { createStore } from "https://framer.com/m/framer/store.js@^1.0.0"
import { randomColor } from "https://framer.com/m/framer/utils.js@^0.9.0"
import { useRef, useEffect } from "react"
// Learn more: https://www.framer.com/docs/guides/overrides/
const useStore = createStore({
background: "#0099FF",
})
export function withConextMenu(Component): ComponentType {
return (props) => {
const [store, setStore] = useStore()
const elementRef = useRef()
const showMenu = (e, i) => {
e.preventDefault
console.log(e, e.pageX, e.pageY)
setStore({ background: randomColor() })
}
// containerRef.current
useEffect(() => {
elementRef.current.addEventListener("contextmenu", showMenu)
}, [])
return (
<Component
{...props}
ref={elementRef}
animate={{
background: store.background,
}}
// onClick={showMenu}
oncontextmenu={showMenu}
/>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment