@modelmenu/navigation 2.5.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,194 +1,224 @@
1
- <template>
2
- <div class="horizontal-top-menu">
3
- <div v-for="item in topMenuItems" :key="item.id" class="horizontal-top-menu-item" :class="{'menu-hover': item.opened, 'active': item.opened}" @mouseenter="hoverOpenTopMenuItem($event, item)">
4
-
5
- <div class="top-menu-item-heading" @click="openMenuItem($event, item)" @mouseleave="closeTopMenu($event, item)">
6
- <div>{{ item.name }}</div>
7
- <div v-if="item.items?.length"><FontAwesomeIcon :size="'sm'" :class="{'icon-opened': item.opened}" :icon="item.openIcon"></FontAwesomeIcon></div>
8
- </div>
9
-
10
- <TopSubMenuItems @mouseleave="closeTopMenuItem($event, item)" v-if="item.items?.length" :item="item" :topMenuItems="topMenuItems" :menuBar="menuBar" @click.stop></TopSubMenuItems>
11
- </div>
12
- </div>
13
- </template>
14
-
15
-
16
- <script lang="ts">
17
- import { faChevronDown, faChevronUp } from '@fortawesome/free-solid-svg-icons';
18
- import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
19
- import TopSubMenuItems from './../top-menu-items/top-sub-menu-items.vue';
20
- import { toTop } from '../../routing/routing';
21
-
22
- export default {
23
- name: 'TopMenuItems',
24
- components: {
25
- FontAwesomeIcon: FontAwesomeIcon,
26
- TopSubMenuItems: TopSubMenuItems
27
- },
28
- props: {
29
- topMenuItems: {
30
- type: Array,
31
- default: () => [] as any[]
32
- },
33
- menuBar: {
34
- type: Object,
35
- required: true
36
- }
37
- },
38
- created() {
39
- console.log("Test", this.topMenuItems);
40
- },
41
- data() {
42
- return {
43
- topMenuItems: this.topMenuItems as any[],
44
- menuBar: this.menuBar,
45
- toTop: toTop
46
- }
47
- },
48
- watch: {
49
- topMenuItems(newVal){
50
- this.topMenuItems = newVal;
51
- }
52
- },
53
- methods: {
54
- openTopMenuItem(event: MouseEvent, item: any) {
55
- console.log(item)
56
- if(!item.items?.length){
57
- item.openIcon = faChevronUp;
58
- toTop(item.route);
59
- return;
60
- }
61
-
62
- },
63
- hoverOpenTopMenuItem(event: MouseEvent, item: any) {
64
- document.querySelector<Element>(`.horizontal-top-menu-item-${item.id}`)?.classList.add('menu-hover');
65
- this.closeMenuTabs(this.topMenuItems);
66
-
67
- let timeout = 200;
68
-
69
- for(let item of document.querySelectorAll('.top-sub-menu-items')){
70
- item.classList.remove('tooltip-opened')
71
- }
72
-
73
- setTimeout(() => {
74
- item.opened = true;
75
- this.closeSubItems(item);
76
- }, timeout)
77
- },
78
- closeTopMenuItem(event: MouseEvent, item: any) {
79
- document.querySelector<Element>(`.horizontal-top-menu-item-${item.id}`)?.classList.remove('menu-hover');
80
-
81
- setTimeout(() => {
82
- item.opened = false;
83
- item.openIcon = faChevronDown;
84
- this.closeSubItems(item);
85
- }, 200)
86
- },
87
- closeTopMenu(event: MouseEvent, item: any) {
88
- if(!item.items?.length){
89
- item.opened = false;
90
- item.openIcon = faChevronDown;
91
- }
92
- this.closeSubItems(item);
93
- },
94
- openMenuItem(event: MouseEvent, item: any) {
95
- item.openIcon = faChevronUp;
96
- if(!item.items?.length){
97
- toTop(item.route);
98
- return;
99
- }
100
- },
101
- closeMenuTabs(items: any[]) {
102
- for(let item of items){
103
- item.opened = false;
104
- item.openIcon = faChevronDown;
105
- }
106
- },
107
- closeSubItems(item: any) {
108
- if(!item.opened){
109
- for(let subItem of item.items || []){
110
- subItem.opened = false;
111
- if(subItem.items?.length){
112
- this.closeSubItems(subItem);
113
- }
114
- }
115
- }
116
- },
117
- }
118
- }
119
- </script>
120
-
121
- <style scoped>
122
-
123
- .item{
124
- display: flex;
125
- flex-wrap: wrap;
126
- width: 180px;
127
- }
128
- .horizontal-items{
129
- display: flex;
130
- gap: 20px;
131
- padding: 10px;
132
- }
133
-
134
- .top-menu-item-heading{
135
- display: flex;
136
- align-items: center;
137
- cursor: pointer;
138
- column-gap: 4px;
139
- border-bottom: 1px solid transparent;
140
- margin: 4px;
141
- box-sizing: border-box;
142
- }
143
-
144
- .horizontal-top-menu-item.active {
145
- border-bottom: 2px solid black;
146
- }
147
-
148
- .menu-hover {
149
- background-color: #eeeeee;
150
- }
151
-
152
- .horizontal-top-menu {
153
- width: 100%;
154
- display: flex;
155
- justify-content: flex-end;
156
- align-items: center;
157
- }
158
-
159
- .horizontal-top-menu-item{
160
- display: flex;
161
- align-items: center;
162
- box-sizing: border-box;
163
- cursor: pointer;
164
- height: 48px;
165
- border-bottom: 2px solid transparent;
166
- padding: 4px 12px;
167
- }
168
-
169
- @keyframes openMenu {
170
- from {
171
- transform: rotate(0deg);
172
- }
173
- to {
174
- transform: rotate(180deg);
175
- }
176
- }
177
-
178
- @keyframes closeMenu{
179
- from {
180
- transform: rotate(0deg);
181
- }
182
- to {
183
- transform: rotate(-180deg);
184
- }
185
- }
186
-
187
- .icon-opened{
188
- animation: openMenu 0.2s ease forwards;
189
- }
190
-
191
- .icon-closed{
192
- animation: closeMenu 0.2s ease forwards;
193
- }
194
- </style>
1
+ <template>
2
+ <div class="horizontal-top-menu">
3
+ <div
4
+ v-for="item in topMenuItems"
5
+ :key="item.id"
6
+ class="horizontal-top-menu-item"
7
+ :class="{ 'menu-hover': item.opened, active: item.opened }"
8
+ @mouseenter="hoverOpenTopMenuItem($event, item)"
9
+ >
10
+ <div
11
+ class="top-menu-item-heading"
12
+ @click="openMenuItem($event, item)"
13
+ @mouseleave="closeTopMenu($event, item)"
14
+ >
15
+ <div>{{ item.name }}</div>
16
+ <div v-if="item.items?.length">
17
+ <FontAwesomeIcon
18
+ :size="'sm'"
19
+ :class="{ 'icon-opened': item.opened }"
20
+ :icon="item.openIcon"
21
+ ></FontAwesomeIcon>
22
+ </div>
23
+ </div>
24
+
25
+ <TopSubMenuItems
26
+ @mouseleave="closeTopMenuItem($event, item)"
27
+ v-if="item.items?.length"
28
+ :item="item"
29
+ :topMenuItems="topMenuItems"
30
+ :menuBar="menuBar"
31
+ @click.stop
32
+ ></TopSubMenuItems>
33
+ </div>
34
+ </div>
35
+ </template>
36
+
37
+ <script lang="ts">
38
+ import { faChevronDown, faChevronUp } from "@fortawesome/free-solid-svg-icons";
39
+ import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
40
+ import TopSubMenuItems from "./../top-menu-items/top-sub-menu-items.vue";
41
+ import { toTop } from "../../routing/routing";
42
+
43
+ export default {
44
+ name: "TopMenuItems",
45
+ components: {
46
+ FontAwesomeIcon: FontAwesomeIcon,
47
+ TopSubMenuItems: TopSubMenuItems,
48
+ },
49
+ props: {
50
+ topMenuItems: {
51
+ type: Array,
52
+ default: () => [] as any[],
53
+ },
54
+ menuBar: {
55
+ type: Object,
56
+ required: true,
57
+ },
58
+ },
59
+ created() {
60
+ console.log("Test", this.topMenuItems);
61
+ },
62
+ data() {
63
+ return {
64
+ topMenuItems: this.topMenuItems as any[],
65
+ menuBar: this.menuBar,
66
+ toTop: toTop,
67
+ menuTimeout: null as ReturnType<typeof setTimeout> | null,
68
+ };
69
+ },
70
+ watch: {
71
+ topMenuItems(newVal) {
72
+ this.topMenuItems = newVal;
73
+ },
74
+ },
75
+ methods: {
76
+ openTopMenuItem(event: MouseEvent, item: any) {
77
+ console.log(item);
78
+ if (!item.items?.length) {
79
+ item.openIcon = faChevronUp;
80
+ toTop(item.route);
81
+ return;
82
+ }
83
+ },
84
+ hoverOpenTopMenuItem(event: MouseEvent, item: any) {
85
+ if (this.menuTimeout) {
86
+ clearTimeout(this.menuTimeout);
87
+ }
88
+ document
89
+ .querySelector<Element>(`.horizontal-top-menu-item-${item.id}`)
90
+ ?.classList.add("menu-hover");
91
+ this.closeMenuTabs(this.topMenuItems);
92
+
93
+ for (const item of document.querySelectorAll(".top-sub-menu-items")) {
94
+ item.classList.remove("tooltip-opened");
95
+ }
96
+
97
+ this.menuTimeout = setTimeout(() => {
98
+ item.opened = true;
99
+ this.closeSubItems(item);
100
+ this.menuTimeout = null;
101
+ }, 200);
102
+ },
103
+ closeTopMenuItem(event: MouseEvent, item: any) {
104
+ document
105
+ .querySelector<Element>(`.horizontal-top-menu-item-${item.id}`)
106
+ ?.classList.remove("menu-hover");
107
+
108
+ if (this.menuTimeout) {
109
+ clearTimeout(this.menuTimeout);
110
+ }
111
+ this.menuTimeout = setTimeout(() => {
112
+ item.opened = false;
113
+ item.openIcon = faChevronDown;
114
+ this.closeSubItems(item);
115
+ this.menuTimeout = null;
116
+ }, 200);
117
+ },
118
+ closeTopMenu(event: MouseEvent, item: any) {
119
+ if (!item.items?.length) {
120
+ item.opened = false;
121
+ item.openIcon = faChevronDown;
122
+ }
123
+ this.closeSubItems(item);
124
+ },
125
+ openMenuItem(event: MouseEvent, item: any) {
126
+ item.openIcon = faChevronUp;
127
+ if (!item.items?.length) {
128
+ toTop(item.route);
129
+ return;
130
+ }
131
+ },
132
+ closeMenuTabs(items: any[]) {
133
+ for (const item of items) {
134
+ item.opened = false;
135
+ item.openIcon = faChevronDown;
136
+ }
137
+ },
138
+ closeSubItems(item: any) {
139
+ if (!item.opened) {
140
+ for (const subItem of item.items || []) {
141
+ subItem.opened = false;
142
+ if (subItem.items?.length) {
143
+ this.closeSubItems(subItem);
144
+ }
145
+ }
146
+ }
147
+ },
148
+ },
149
+ };
150
+ </script>
151
+
152
+ <style scoped>
153
+ .item {
154
+ display: flex;
155
+ flex-wrap: wrap;
156
+ width: 180px;
157
+ }
158
+ .horizontal-items {
159
+ display: flex;
160
+ gap: 20px;
161
+ padding: 10px;
162
+ }
163
+
164
+ .top-menu-item-heading {
165
+ display: flex;
166
+ align-items: center;
167
+ cursor: pointer;
168
+ column-gap: 4px;
169
+ border-bottom: 1px solid transparent;
170
+ margin: 4px;
171
+ box-sizing: border-box;
172
+ }
173
+
174
+ .horizontal-top-menu-item.active {
175
+ border-bottom: 2px solid black;
176
+ }
177
+
178
+ .menu-hover {
179
+ background-color: #eeeeee;
180
+ }
181
+
182
+ .horizontal-top-menu {
183
+ width: 100%;
184
+ display: flex;
185
+ justify-content: flex-end;
186
+ align-items: center;
187
+ }
188
+
189
+ .horizontal-top-menu-item {
190
+ display: flex;
191
+ align-items: center;
192
+ box-sizing: border-box;
193
+ cursor: pointer;
194
+ height: 48px;
195
+ border-bottom: 2px solid transparent;
196
+ padding: 4px 12px;
197
+ }
198
+
199
+ @keyframes openMenu {
200
+ from {
201
+ transform: rotate(0deg);
202
+ }
203
+ to {
204
+ transform: rotate(180deg);
205
+ }
206
+ }
207
+
208
+ @keyframes closeMenu {
209
+ from {
210
+ transform: rotate(0deg);
211
+ }
212
+ to {
213
+ transform: rotate(-180deg);
214
+ }
215
+ }
216
+
217
+ .icon-opened {
218
+ animation: openMenu 0.2s ease forwards;
219
+ }
220
+
221
+ .icon-closed {
222
+ animation: closeMenu 0.2s ease forwards;
223
+ }
224
+ </style>