1
// Mixins
2
import Delayable from '../../mixins/delayable'
3
import Toggleable from '../../mixins/toggleable'
4

5
// Utilities
6
import mixins from '../../util/mixins'
7
import { consoleWarn } from '../../util/console'
8

9
// Types
10
import { VNode, ScopedSlotChildren } from 'vue/types/vnode'
11

12
export default mixins(
13
  Delayable,
14
  Toggleable
15
  /* @vue/component */
16
).extend({
17
  name: 'v-hover',
18

19
  props: {
20
    disabled: {
21
      type: Boolean,
22
      default: false,
23
    },
24
    value: {
25
      type: Boolean,
26
      default: undefined,
27
    },
28
  },
29

30
  methods: {
31 1
    onMouseEnter () {
32 1
      this.runDelay('open')
33
    },
34 1
    onMouseLeave () {
35 1
      this.runDelay('close')
36
    },
37
  },
38

39 1
  render (): VNode {
40 1
    if (!this.$scopedSlots.default && this.value === undefined) {
41 1
      consoleWarn('v-hover is missing a default scopedSlot or bound value', this)
42

43 1
      return null as any
44
    }
45

46
    let element: VNode | ScopedSlotChildren
47

48
    /* istanbul ignore else */
49 1
    if (this.$scopedSlots.default) {
50 1
      element = this.$scopedSlots.default({ hover: this.isActive })
51
    }
52

53 1
    if (Array.isArray(element) && element.length === 1) {
54 1
      element = element[0]
55
    }
56

57 1
    if (!element || Array.isArray(element) || !element.tag) {
58 1
      consoleWarn('v-hover should only contain a single element', this)
59

60 1
      return element as any
61
    }
62

63 1
    if (!this.disabled) {
64 1
      element.data = element.data || {}
65 1
      this._g(element.data, {
66
        mouseenter: this.onMouseEnter,
67
        mouseleave: this.onMouseLeave,
68
      })
69
    }
70

71 1
    return element
72
  },
73
})

Read our documentation on viewing source code .

Loading