Skip to content

Commit

Permalink
fix(hover): enable using dynamic params (#963)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeJim authored Jul 17, 2023
1 parent 32e08e8 commit cfaff1f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/button/button.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<button
v-hover="{ className: `${name}--hover`, active: !disabled }"
v-hover="{ className: `${name}--hover` }"
:class="buttonClass"
:disabled="disabled"
:type="type"
Expand Down Expand Up @@ -35,7 +35,7 @@ export default defineComponent({
directives: { Hover },
props: ButtonProps,
emits: ['click'],
setup(props, context) {
setup(props) {
const disabled = useFormDisabled();
const internalInstance = getCurrentInstance();
const buttonClass = computed(() => [
Expand Down
6 changes: 4 additions & 2 deletions src/cell/cell.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div v-hover="{ className: `${name}--hover`, active: hover }" :class="styleCell" @click="onClick">
<div v-hover="{ className: `${name}--hover`, disabledName: 'hoverDisabled' }" :class="styleCell" @click="onClick">
<div :class="`${name}__left`">
<div v-if="leftIconContent" :class="`${name}__left-icon`">
<t-node :content="leftIconContent" />
Expand Down Expand Up @@ -63,11 +63,12 @@ export default defineComponent({
`${name}`,
`${name}--${props.align}`,
{
[`${name}--hover`]: props.hover && disabled.value,
[`${name}--borderless`]: !props.bordered,
},
]);
const hoverDisabled = computed(() => !props.hover || disabled.value);
const onClick = (e: Event) => {
if (!disabled.value) {
props.onClick?.(e);
Expand All @@ -76,6 +77,7 @@ export default defineComponent({
return {
...toRefs(props),
hoverDisabled,
name,
onClick,
styleCell,
Expand Down
16 changes: 10 additions & 6 deletions src/shared/hover.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { DirectiveBinding } from 'vue';
import { DirectiveBinding, VNode } from 'vue';

interface BindingObj {
active: boolean;
disabledName: string;
className: string;
}

const Hover = {
created(el: HTMLElement, binding: DirectiveBinding<BindingObj>) {
created(el: HTMLElement, binding: DirectiveBinding<BindingObj>, vnode: VNode) {
const startTime = 50;
const stayTime = 70;
const { className, active = true } = binding.value;

if (!active) return;
const { className, disabledName = 'disabled' } = binding.value;

el.addEventListener(
'touchstart',
() => {
// @ts-ignore
if (vnode.ctx.ctx[disabledName]) return;

setTimeout(() => {
el?.classList.add(className);
}, startTime);
Expand All @@ -26,6 +27,9 @@ const Hover = {
el.addEventListener(
'touchend',
() => {
// @ts-ignore
if (vnode.ctx.ctx[disabledName]) return;

setTimeout(() => {
el?.classList.remove(className);
}, stayTime);
Expand Down

0 comments on commit cfaff1f

Please sign in to comment.