@modelmenu/navigation 1.0.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.
@@ -0,0 +1,523 @@
1
+ <template>
2
+ <div class="menu-container">
3
+ <div class="horizontal-menu">
4
+ <div class="menu-button" >
5
+ <div class="menu-icon" @click="openVerticalMenu($event)">
6
+ <FontAwesomeIcon v-if="menuBar.icon" :icon="menuBar.icon"></FontAwesomeIcon>
7
+ </div>
8
+ </div>
9
+ <TopMenuItem :topMenuItems="topMenuItems" :menuBar="menuBar"></TopMenuItem>
10
+ </div>
11
+
12
+ <div class="vertical-menu" :class="{'vertical-menu-opened': menuBar.opened}">
13
+ <div v-for="(item, index) in leftMenuItems" :key="index" :class="['menu-item-heading', { 'item-active': item.active }]" @mouseenter="showTooltipItems($event, item.items)">
14
+ <div class="item" :class="{'menu-item-opened': menuBar.opened, }">
15
+ <MenuItem @changeMenuItem="handleMenuItem($event)" :item="item" :menuBar="menuBar" :left-items="leftMenuItems"></MenuItem>
16
+ <SubMenuItems @openmenu="handleOpenMenu($event)" v-show="menuBar.opened" :left-menu-items="leftMenuItems" :item="item" :menuBar="menuBar"></SubMenuItems>
17
+ <div class="active-tooltip" v-if="tooltip && item.items?.length && !menuBar.opened" @mouseleave="hideTooltipItems($event)">
18
+ <div v-for="value in item.items" :key="value.name" class="tooltip-item" @click="openTooltipItem($event, value, item)">
19
+ {{ value.name }}
20
+
21
+ </div>
22
+ </div>
23
+ </div>
24
+
25
+ </div>
26
+
27
+ </div>
28
+
29
+
30
+ <div class="main" :class="{'main-loading': menuBar.loading}">
31
+ <slot name="handler"></slot>
32
+ <div class="loader " v-if="menuBar.loading">
33
+ <svg class="loader-icon" viewBox="0 0 64 64" aria-hidden="true">
34
+ <circle class="loader-track" cx="32" cy="32" r="24"></circle>
35
+ <circle class="loader-ring" cx="32" cy="32" r="24"></circle>
36
+ </svg>
37
+ </div>
38
+ </div>
39
+ </div>
40
+
41
+ </template>
42
+
43
+ <script lang="ts">
44
+ import { defineComponent, watch } from 'vue';
45
+ import { LeftMenuItems, MenuBarModel, ThemeModel, TopMenuItems } from './models/menu-models';
46
+ import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
47
+ import { faChevronDown, faChevronLeft, faChevronRight, faChevronUp } from '@fortawesome/free-solid-svg-icons';
48
+ import MenuItem from './components/menu-item.vue';
49
+ import SubMenuItems from './components/sub-menu-items.vue';
50
+ import { load, router, toTop, menubar } from './routing/routing';
51
+ import TopMenuItem from './components/top-menu-items/top-menu-item.vue';
52
+ import { themes } from './resources/theme';
53
+
54
+ export default defineComponent({
55
+ name: 'MenuPlate',
56
+ components: {
57
+ FontAwesomeIcon: FontAwesomeIcon,
58
+ MenuItem: MenuItem,
59
+ SubMenuItems: SubMenuItems,
60
+ TopMenuItem: TopMenuItem
61
+ },
62
+ props: {
63
+ initialMenuBar: {
64
+ type: Object as () => MenuBarModel,
65
+ default: () => (new MenuBarModel())
66
+ },
67
+ leftItems: {
68
+ type: Array as () => any[],
69
+ default: () => [] as any[]
70
+ },
71
+ Router: {
72
+ type: null,
73
+ required: false
74
+ },
75
+ topItems: {
76
+ type: Array as () => any[],
77
+ default: () => [] as any[]
78
+ },
79
+ theme: {
80
+ type: ThemeModel,
81
+ default: () => new ThemeModel()
82
+ }
83
+ },
84
+ emits: [
85
+ 'changeTheme'
86
+ ],
87
+ watch: {
88
+ initialMenuBar(newVal: any) {
89
+ this.menuBar = newVal;
90
+ },
91
+ leftItems(newVal: any) {
92
+ this.leftItems = newVal;
93
+ const idCounter = { value: 0 };
94
+ this.leftMenuItems = this.toLeftMenuItems(newVal, idCounter);
95
+ this.setActiveByRoute();
96
+ },
97
+ topItems(newVal: any) {
98
+ this.topItems = newVal;
99
+ },
100
+ },
101
+ mounted() {
102
+ watch(() => this.$route, () => {
103
+ this.setActiveByRoute();
104
+ });
105
+ },
106
+ created() {
107
+ const idCounter = { value: 0 };
108
+ this.leftMenuItems = this.toLeftMenuItems(this.leftItems, idCounter);
109
+ this.topMenuItems = this.toTopMenuItems(this.topItems, idCounter);
110
+ router(this.Router);
111
+ load(false);
112
+ menubar(this.menuBar);
113
+ this.setActiveByRoute();
114
+ },
115
+ initTheme(){
116
+ let themeLink = themes.find(x=> x.type === this.theme.type);
117
+ if(themeLink){
118
+ document.documentElement.setAttribute('data-theme', themeLink.value);
119
+ }
120
+ this.$emit('changeTheme', this.theme);
121
+ },
122
+ data() {
123
+ return {
124
+ menuBar: this.initialMenuBar,
125
+ faChevronDown: faChevronDown,
126
+ faChevronRight: faChevronRight,
127
+ topMenuItems: [] as TopMenuItems[],
128
+ leftMenuItems: [] as LeftMenuItems[],
129
+ tooltip: false,
130
+ tooltipItems: [] as any[],
131
+ topItems: this.topItems,
132
+ leftItems: this.leftItems,
133
+ floor: 20,
134
+ router: router,
135
+ toTop: toTop,
136
+ menubar: menubar,
137
+ themes: themes
138
+ }
139
+ },
140
+ methods: {
141
+ toLeftMenuItems(items: any[], counter: { value: number }) : LeftMenuItems[] {
142
+ let leftMenuItems: LeftMenuItems[] = [];
143
+ for(let item of items){
144
+ let leftMenuItem = new LeftMenuItems();
145
+ leftMenuItem.id = counter.value++;
146
+ leftMenuItem.name = item.name;
147
+ leftMenuItem.icon = item.icon;
148
+ leftMenuItem.route = item.route;
149
+
150
+ if(item.items?.length){
151
+ leftMenuItem.items = this.toTopMenuItems(item.items, counter);
152
+ }
153
+
154
+ leftMenuItems = [...leftMenuItems, leftMenuItem];
155
+ }
156
+ return leftMenuItems;
157
+ },
158
+ handleMenuItem(items: any[]){
159
+ this.leftMenuItems = items;
160
+ },
161
+ toTopMenuItems(items: any[], counter: { value: number }) : TopMenuItems[] {
162
+ let topMenuItems: TopMenuItems[] = [];
163
+ for(let item of items){
164
+ let topMenuItem = new TopMenuItems();
165
+ topMenuItem.id = counter.value++;
166
+ topMenuItem.name = item.name;
167
+ topMenuItem.route = item.route;
168
+ if(item.items?.length){
169
+ topMenuItem.items = this.toTopMenuItems(item.items, counter);
170
+ }
171
+
172
+ topMenuItems = [...topMenuItems, topMenuItem];
173
+ }
174
+ return topMenuItems;
175
+ },
176
+ openVerticalMenu(event: MouseEvent) {
177
+ this.menuBar.opened = !this.menuBar.opened;
178
+ this.menuBar.changeIcon = 'flip';
179
+ this.menuBar.icon = this.menuBar.opened ? faChevronRight : faChevronLeft;
180
+ },
181
+ openSubMenu(item: any) {
182
+ item.opened = !item.opened;
183
+ },
184
+ setActiveByRoute() {
185
+ const path = this.$route?.path || '/';
186
+ this.clearActiveItems(this.leftMenuItems);
187
+ this.markActiveRoute(this.leftMenuItems, path);
188
+ },
189
+ clearActiveItems(items: any[]) {
190
+ for (const item of items) {
191
+ item.active = false;
192
+ if (item.items?.length) {
193
+ this.clearActiveItems(item.items);
194
+ }
195
+ }
196
+ },
197
+ markActiveRoute(items: any[], path: string): boolean {
198
+ let found = false;
199
+ for (const item of items) {
200
+ const childActive = item.items?.length ? this.markActiveRoute(item.items, path) : false;
201
+ item.active = item.route === path || childActive;
202
+ item.opened = childActive;
203
+ if (item.active) {
204
+ found = true;
205
+ }
206
+ }
207
+ return found;
208
+ },
209
+ showTooltipItems(event: any, items: any[]) {
210
+ if (!this.menuBar.opened) {
211
+ if(items?.length){
212
+ this.tooltip = true;
213
+ this.tooltipItems = items;
214
+ }
215
+ }
216
+ },
217
+ hideTooltipItems(event: any) {
218
+ if (!this.menuBar.opened) {
219
+ this.tooltip = false;
220
+ this.tooltipItems = [];
221
+ }
222
+ },
223
+ handleOpenMenu(item: any) {
224
+ for(let subItem of this.leftMenuItems || []){
225
+ if(subItem.items?.length){
226
+ subItem.opened = true;
227
+ subItem.openIcon = subItem.openIcon ? faChevronDown : faChevronRight;
228
+ }
229
+ }
230
+ let item1 = this.leftMenuItems.find(x=> x.name === item.name);
231
+ if(item1){
232
+ item1.opened = !item1.opened;
233
+ item1.openIcon = item1.opened ? faChevronDown : faChevronRight;
234
+ }
235
+ },
236
+ openTooltipItem(event: any, item: any, parentItem: any) {
237
+ if(item.items?.length){
238
+ this.openVerticalMenu(event);
239
+ let parent = this.leftMenuItems.find((x: any) => x.id === parentItem.id)!;
240
+ parent.opened = true;
241
+ parent.openIcon = faChevronUp;
242
+
243
+ let currentItem = parent.items.find((x: any) => x.id === item.id)!;
244
+ currentItem.opened = true;
245
+ currentItem.openIcon = faChevronUp;
246
+ return;
247
+ }
248
+ parentItem.active = true;
249
+ toTop(item.route);
250
+ }
251
+ }
252
+ });
253
+ </script>
254
+
255
+ <style scoped>
256
+ .menu-container {
257
+ position: relative;
258
+ width: 100%;
259
+ height: 100%;
260
+ }
261
+
262
+ .top-sub-menu-items {
263
+ position: absolute;
264
+ top: 38px;
265
+ right: 0px;
266
+ border: 1px solid #424242;
267
+ padding: 10px;
268
+ width: 150px;
269
+ z-index: 99999;
270
+ }
271
+
272
+ .svg-inline--fa {
273
+ color: rgba(60, 60, 60, 0.8) !important;
274
+ }
275
+
276
+ .item-active{
277
+ background-color: #f2f2f2;
278
+ }
279
+
280
+ .horizontal-menu-item{
281
+ cursor: pointer;
282
+ }
283
+
284
+ .horizontal-items{
285
+ display: flex;
286
+ gap: 20px;
287
+ padding: 10px;
288
+ }
289
+
290
+ .loader{
291
+ width: 100%;
292
+ display: flex;
293
+ justify-content: center;
294
+ align-items: center;
295
+ height: 36dvh;
296
+ }
297
+
298
+ .loader-icon{
299
+ width: 80px;
300
+ height: 80px;
301
+ transform-origin: center;
302
+ animation: rotateLoader 1s linear infinite;
303
+ }
304
+
305
+ @keyframes rotateLoader {
306
+ from {
307
+ transform: rotate(0deg);
308
+ }
309
+ to {
310
+ transform: rotate(360deg);
311
+ }
312
+ }
313
+
314
+ .loader-track,
315
+ .loader-ring {
316
+ fill: none;
317
+ stroke-width: 8;
318
+ }
319
+
320
+ .loader-track {
321
+ stroke: rgba(66, 148, 255, 0.18);
322
+ }
323
+
324
+ .loader-ring {
325
+ stroke: #4294ff;
326
+ stroke-dasharray: 110 160;
327
+ stroke-dashoffset: 0;
328
+ }
329
+
330
+ .menu-text-opened {
331
+ display: inline-block;
332
+ }
333
+
334
+ .menu-text-closed {
335
+ display: none;
336
+ }
337
+ .item{
338
+ display: flex;
339
+ flex-wrap: wrap;
340
+ cursor: pointer;
341
+ width: 180px;
342
+ }
343
+
344
+ .menu-item p {
345
+ margin-left: 10px;
346
+ }
347
+
348
+
349
+ .menu-item-opened {
350
+ display: flex;
351
+ }
352
+
353
+ .horizontal-items{
354
+ display: flex;
355
+ align-self: flex-end;
356
+ }
357
+
358
+ .tooltip-item{
359
+ padding: 8px;
360
+ cursor: pointer;
361
+ }
362
+
363
+ .horizontal-menu {
364
+ position: absolute;
365
+ border-bottom: 1px solid rgba(70, 70, 70, 0.5);
366
+ top: 0;
367
+ left: 0;
368
+ width: 100%;
369
+ height: 50px;
370
+ display: flex;
371
+ align-items: center;
372
+ justify-content: space-between;
373
+ }
374
+
375
+ .vertical-menu {
376
+ position: absolute;
377
+ top: 50px;
378
+ overflow-x: hidden;
379
+ left: 0;
380
+ z-index: 200;
381
+ width: 70px;
382
+ animation: closeMenu 0.3s ease-out forwards;
383
+ height: 100dvh;
384
+ border-right: 1px solid rgba(70, 70, 70, 0.5);
385
+ }
386
+
387
+ .menu-item {
388
+ margin: 0 auto;
389
+ margin-top: 10px;
390
+ margin-bottom: 10px;
391
+ width: 180px;
392
+ margin-left: 20px;
393
+ height: 30px;
394
+ cursor: pointer;
395
+ display: flex;
396
+ justify-content: flex-start;
397
+ align-items: center;
398
+ }
399
+
400
+ @keyframes openMenu {
401
+ from {
402
+ width: 70px;
403
+ }
404
+ to {
405
+ width: 200px;
406
+ }
407
+ }
408
+
409
+ @keyframes closeMenu {
410
+ from {
411
+ width: 200px;
412
+ }
413
+ to {
414
+ width: 70px;
415
+ }
416
+ }
417
+
418
+ .vertical-menu.vertical-menu-opened {
419
+ width: 200px;
420
+ animation: openMenu 0.3s ease-in forwards;
421
+ }
422
+
423
+ .menu-button{
424
+ width: 74px;
425
+ height: 50px;
426
+ display: flex;
427
+ justify-content: center;
428
+ cursor: pointer;
429
+ align-items: center;
430
+ border-right: 1px solid rgba(70, 70, 70, 0.5);
431
+ }
432
+
433
+ .menu-icon{
434
+ width: 30px;
435
+ height: 30px;
436
+ border: 1px solid rgba(0, 0, 0, 0.7);
437
+ display: flex;
438
+ justify-content: center;
439
+ align-items: center;
440
+ border-radius: 4px;
441
+ }
442
+
443
+ .menu-icon:hover {
444
+ cursor: pointer;
445
+ background-color: rgb(66, 66, 66, 0.1);
446
+ }
447
+
448
+ @keyframes flipAnimation {
449
+ from {
450
+ transform: rotate(0deg);
451
+ }
452
+ to {
453
+ transform: rotate(180deg);
454
+ }
455
+ }
456
+
457
+ @keyframes rotateAnimation {
458
+ from {
459
+ transform: rotate(0deg);
460
+ }
461
+ to {
462
+ transform: rotate(90deg);
463
+ }
464
+ }
465
+
466
+
467
+ @keyframes hoverAnimation {
468
+ from {
469
+ transform: scale(1);
470
+ }
471
+ to {
472
+ transform: scale(1.2);
473
+ }
474
+ }
475
+
476
+
477
+ .menu-icon.opened.flip svg{
478
+ transform: rotate(180deg);
479
+ }
480
+
481
+ .menu-icon.opened.rotate svg{
482
+ animation: rotateAnimation 0.5s forwards;
483
+ }
484
+
485
+ .menu-icon.opened.hover svg{
486
+ animation: hoverAnimation 0.5s forwards;
487
+ }
488
+
489
+ .none{
490
+ transform: none;
491
+ }
492
+
493
+ .horizontal-menu-item{
494
+ display: flex;
495
+ align-items: center;
496
+ justify-content:center;
497
+ margin-right: 10px !important;
498
+ margin: 0 auto;
499
+ }
500
+
501
+ .active-tooltip {
502
+ position: fixed;
503
+ left: 80px;
504
+ width: 240px;
505
+ height: 80px;
506
+ background-color: white;
507
+ z-index: 9999999;
508
+ border: 1px solid #424242;
509
+ }
510
+
511
+ .main{
512
+ width: calc(100vw - 300px);
513
+ height: 100%;
514
+ position: absolute;
515
+ left: 180px;
516
+ top: 70px;
517
+ }
518
+
519
+ .main-loading{
520
+ opacity: 0.1;
521
+ background-color: white;
522
+ }
523
+ </style>