forked from vuetifyjs/vuetify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
79 lines (66 loc) 路 1.82 KB
/
index.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
// Mixins
import { Registrable, inject as RegistrableInject } from '../registrable'
// Utilities
import { ExtractVue } from '../../util/mixins'
import { VueConstructor } from 'vue'
import { PropValidator } from 'vue/types/options'
export type Groupable<T extends string, C extends VueConstructor | null = null> = VueConstructor<ExtractVue<Registrable<T, C>> & {
activeClass: string
isActive: boolean
disabled: boolean
groupClasses: object
toggle (e?: Event): void
}>
export function factory<T extends string, C extends VueConstructor | null = null> (
namespace: T,
child?: string,
parent?: string
): Groupable<T, C> {
return RegistrableInject<T, C>(namespace, child, parent).extend({
name: 'groupable',
props: {
activeClass: {
type: String,
default (): string | undefined {
if (!this[namespace]) return undefined
return this[namespace].activeClass
},
} as any as PropValidator<string>,
disabled: Boolean,
},
data () {
return {
isActive: false,
}
},
computed: {
groupClasses (): object {
if (!this.activeClass) return {}
return {
[this.activeClass]: this.isActive,
}
},
},
created () {
this[namespace] && (this[namespace] as any).register(this)
},
beforeDestroy () {
this[namespace] && (this[namespace] as any).unregister(this)
},
methods: {
toggle (e?: Event) {
if (this.disabled && e) {
// Prevent keyboard actions
// from children elements
// within disabled tabs
e.preventDefault()
return
}
this.$emit('change')
},
},
})
}
/* eslint-disable-next-line @typescript-eslint/no-redeclare */
const Groupable = factory('itemGroup')
export default Groupable