-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
/
VBreadcrumbs.ts
110 lines (91 loc) 路 2.65 KB
/
VBreadcrumbs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Styles
import '../../stylus/components/_breadcrumbs.styl'
// Types
import { VNode } from 'vue'
import { PropValidator } from 'vue/types/options'
// Components
import { VBreadcrumbsDivider, VBreadcrumbsItem } from '.'
// Mixins
import Themeable from '../../mixins/themeable'
// Utils
import { deprecate } from '../../util/console'
import mixins from '../../util/mixins'
export default mixins(
Themeable
/* @vue/component */
).extend({
name: 'v-breadcrumbs',
props: {
divider: {
type: String,
default: '/'
},
items: {
type: Array,
default: () => ([])
} as PropValidator<any[]>,
large: Boolean,
justifyCenter: Boolean,
justifyEnd: Boolean
},
computed: {
classes (): object {
return {
'v-breadcrumbs--large': this.large,
'justify-center': this.justifyCenter,
'justify-end': this.justifyEnd,
...this.themeClasses
}
}
},
mounted () {
if (this.justifyCenter) deprecate('justify-center', 'class="justify-center"', this)
if (this.justifyEnd) deprecate('justify-end', 'class="justify-end"', this)
if (this.$slots.default) deprecate('default slot', ':items and scoped slot "item"', this)
},
methods: {
/* @deprecated */
genChildren /* istanbul ignore next */ () {
if (!this.$slots.default) return undefined
const children = []
let createDividers = false
for (let i = 0; i < this.$slots.default.length; i++) {
const elm = this.$slots.default[i]
if (
!elm.componentOptions ||
elm.componentOptions.Ctor.options.name !== 'v-breadcrumbs-item'
) {
children.push(elm)
} else {
if (createDividers) {
children.push(this.genDivider())
}
children.push(elm)
createDividers = true
}
}
return children
},
genDivider () {
return this.$createElement(VBreadcrumbsDivider, this.$slots.divider ? this.$slots.divider : this.divider)
},
genItems () {
const items = []
const hasSlot = !!this.$scopedSlots.item
for (let i = 0; i < this.items.length; i++) {
const item = this.items[i]
if (hasSlot) items.push(this.$scopedSlots.item!({ item }))
else items.push(this.$createElement(VBreadcrumbsItem, { key: item.text, props: item }, [item.text]))
if (i < this.items.length - 1) items.push(this.genDivider())
}
return items
}
},
render (h): VNode {
const children = this.$slots.default ? this.genChildren() : this.genItems()
return h('ul', {
staticClass: 'v-breadcrumbs',
'class': this.classes
}, children)
}
})