-
Notifications
You must be signed in to change notification settings - Fork 0
/
NavigationGenerator.vue
60 lines (55 loc) · 1.86 KB
/
NavigationGenerator.vue
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
<template>
<ul class="nav">
<navigation-item v-for="(c, key) in config"
@close-all="closeAll"
@toggle-submenu="toggleSubmenu"
:key="key"
:config="c"
:portal="portal"
:showSubmenuClose="showSubmenuClose"
:showSubmenuTitle="showSubmenuTitle"
:submenusRight="submenusRight">
</navigation-item>
</ul>
</template>
<script lang="ts">
import Vue from 'vue';
import { Component, Prop } from 'vue-property-decorator';
import { NavigationGeneratorInterface } from '@/interfaces/NavigationGeneratorInterface';
import { NavigationModel } from '@/models/NavigationModel';
import NavigationItem from '@/components/navigation/NavigationItem.vue';
@Component({
components: {
NavigationItem
}
})
export default class NavigationGenerator extends Vue implements NavigationGeneratorInterface {
@Prop({ required: true }) readonly config!: Array<NavigationModel>;
@Prop([Boolean]) readonly onlyOneSubmenu!: boolean;
@Prop({ default: null }) readonly portal!: string;
@Prop([Boolean]) readonly showSubmenuClose!: boolean;
@Prop([Boolean]) readonly showSubmenuTitle!: boolean;
@Prop([Boolean]) readonly submenusRight!: boolean;
navigationItems: Array<Vue> = [];
closeAll () {
this.closeSubmenus();
}
toggleSubmenu (component: Vue) {
if (component.$data.isSubmenuOpen) {
if (this.onlyOneSubmenu) {
this.closeSubmenus();
}
this.navigationItems.push(component);
} else {
this.navigationItems.splice(this.navigationItems.indexOf(component), 1);
}
}
closeSubmenus () {
const len: number = this.navigationItems.length;
for (let i = 0; i < len; i++) {
const comp = this.navigationItems.pop();
comp!.$data.isSubmenuOpen = false;
}
}
}
</script>