Skip to content

Commit

Permalink
feat: Add default pointer style reset on directives
Browse files Browse the repository at this point in the history
  • Loading branch information
Namchee committed Sep 6, 2020
1 parent ae1844e commit 2ab874f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
],
"verbose": true
},
"files": [
"src/**/*",
"dist/**/*"
],
"homepage": "https://github.com/Namchee/tetikus",
"keywords": [
"javascript",
Expand Down
18 changes: 13 additions & 5 deletions src/directives/hover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { HoverBehavior, TransformProps } from '@/common/types';

export const hoverState: Ref<HoverBehavior | null> = ref(null);

const updateHoverState = (props: TransformProps, vnode: VNode) => {
const updateHoverState = (props: TransformProps = {}, vnode: VNode) => {
if (!props) {
return;
}

const state: HoverBehavior = {
transformProps: props,
domElement: vnode.el as HTMLElement,
Expand All @@ -19,25 +23,29 @@ const clearHoverState = () => {
export const TetikusHover = {
mounted(
el: HTMLElement,
binding: DirectiveBinding<TransformProps>,
{ value: props }: DirectiveBinding<TransformProps>,
vnode: VNode,
) {
el.style.cursor = 'none'; // favor tetikus beautiful cursor

el.addEventListener(
'mouseover',
() => updateHoverState(binding.value, vnode),
() => updateHoverState(props, vnode),
);

el.addEventListener('mouseleave', clearHoverState);
},

beforeUnmount(
el: HTMLElement,
binding: DirectiveBinding<TransformProps>,
{ value: props }: DirectiveBinding<TransformProps>,
vnode: VNode,
) {
el.style.cursor = 'auto';

el.removeEventListener(
'mouseover',
() => updateHoverState(binding.value, vnode),
() => updateHoverState(props, vnode),
);

el.removeEventListener('mouseout', clearHoverState);
Expand Down

0 comments on commit 2ab874f

Please sign in to comment.