vuetifyjs / vuetify
1 1
// Mixins
2 1
import { factory as GroupableFactory } from '../../mixins/groupable'
3

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

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

12
/* @vue/component */
13 1
export const BaseItem = Vue.extend({
14
  props: {
15
    activeClass: String,
16
    value: {
17
      required: false,
18
    },
19
  },
20

21 1
  data: () => ({
22
    isActive: false,
23
  }),
24

25
  methods: {
26 0
    toggle () {
27 0
      this.isActive = !this.isActive
28
    },
29
  },
30

31 1
  render (): VNode {
32 1
    if (!this.$scopedSlots.default) {
33 1
      consoleWarn('v-item is missing a default scopedSlot', this)
34

35 1
      return null as any
36
    }
37

38
    let element: VNode | ScopedSlotChildren
39

40
    /* istanbul ignore else */
41 1
    if (this.$scopedSlots.default) {
42 1
      element = this.$scopedSlots.default({
43
        active: this.isActive,
44
        toggle: this.toggle,
45
      })
46
    }
47

48 1
    if (Array.isArray(element) && element.length === 1) {
49 1
      element = element[0]
50
    }
51

52 1
    if (!element || Array.isArray(element) || !element.tag) {
53 1
      consoleWarn('v-item should only contain a single element', this)
54

55 1
      return element as any
56
    }
57

58 1
    element.data = this._b(element.data || {}, element.tag!, {
59
      class: { [this.activeClass]: this.isActive },
60
    })
61

62 1
    return element
63
  },
64
})
65

66 1
export default mixins(
67
  BaseItem,
68
  GroupableFactory('itemGroup', 'v-item', 'v-item-group')
69
).extend({
70
  name: 'v-item',
71
})

Read our documentation on viewing source code .

Loading