Add actions

This commit is contained in:
Vadim
2021-04-20 12:21:42 +03:00
parent ac8b9c150f
commit 29d012dce0
2 changed files with 69 additions and 6 deletions

39
src/utils/hoverable.js Normal file
View File

@@ -0,0 +1,39 @@
import { createDispatcher } from './event'
export function hoverable(node) {
const dispatch = createDispatcher(node)
function handleMouseenter() {
dispatch('hovered', { value: true })
// node.addEventListener('mouseleave', handleMouseleave)
// node.addEventListener('touchend', handleMouseleave)
// node.addEventListener('touchcancel', handleMouseleave)
}
function handleMouseleave() {
dispatch('hovered', { value: false })
// node.removeEventListener('mouseleave', handleMouseleave)
// node.removeEventListener('touchend', handleMouseleave)
// node.removeEventListener('touchcancel', handleMouseleave)
}
node.addEventListener('mouseenter', handleMouseenter)
node.addEventListener('touchstart', handleMouseenter)
node.addEventListener('mouseleave', handleMouseleave)
node.addEventListener('touchend', handleMouseleave)
node.addEventListener('touchcancel', handleMouseleave)
return {
destroy() {
node.removeEventListener('mouseenter', handleMouseenter)
node.removeEventListener('touchstart', handleMouseenter)
node.removeEventListener('mouseleave', handleMouseleave)
node.removeEventListener('touchend', handleMouseleave)
node.removeEventListener('touchcancel', handleMouseleave)
},
}
}