@modelmenu/navigation 2.4.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,236 +1,256 @@
1
- <template>
2
- <div class="menu-item" :ref="ref" @click="openSubMenu(item)" :class="{ 'item-opened': item.opened, 'item-closed': !item.opened, 'item-active': item.active }">
3
- <FontAwesomeIcon class="menu-item-icon" v-if="item.icon" :size="'lg'" :icon="item.icon"></FontAwesomeIcon>
4
- <p class="menu-item-text" :class="{'menu-text-opened': menuBar.opened, 'menu-text-closed': !menuBar.opened }"> {{ item.name }}</p>
5
- <div class="sub-menu-button" v-if="item.items?.length">
6
- <FontAwesomeIcon :class="{'icon-opened': item.opened}" :icon="item.openIcon"></FontAwesomeIcon>
7
- </div>
8
- </div>
9
- </template>
10
-
11
- <script lang="ts">
12
- import { ref } from 'vue';
13
- import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
14
- import { router, to } from '../routing/routing';
15
- import { LeftMenuItems } from '../models/menu-models';
16
-
17
- export default {
18
- name: 'MenuItem',
19
- components: {
20
- FontAwesomeIcon
21
- },
22
- props: {
23
- item: {
24
- type: Object,
25
- required: true
26
- },
27
- leftItems: {
28
- type: Array,
29
- default: () => [] as LeftMenuItems[]
30
- },
31
- menuBar: {
32
- type: Object,
33
- required: true
34
- }
35
- },
36
- data() {
37
- return {
38
- menuBar: this.menuBar,
39
- tooltip: true,
40
- item: this.item,
41
- leftItems: this.leftItems as LeftMenuItems[],
42
- ref: 'item',
43
- rotuer: router,
44
- to: to,
45
- }
46
- },
47
- watch:{
48
- menuBar(newVal: any) {
49
- this.menuBar = newVal;
50
- },
51
- item(newVal: any) {
52
- this.item = newVal;
53
- },
54
- leftItems(newVal: any) {
55
- this.leftItems = newVal;
56
- }
57
- },
58
- emits: [
59
- 'changeMenuItem'
60
- ],
61
- methods: {
62
- openSubMenu(item: any) {
63
- if(!item.items?.length){
64
- to(item.route);
65
-
66
- this.setUnActiveItems(this.leftItems);
67
- let activeItem = this.findItem(this.leftItems, item, true);
68
- this.$emit('changeMenuItem', this.leftItems);
69
- return;
70
- }
71
- item.opened = !item.opened;
72
-
73
- if(!this.menuBar.opened){
74
- return;
75
- }
76
- },
77
- findItem(items: any[], item: any, setActive: boolean): any | undefined {
78
- for(const entry of items){
79
- if(entry.id === item.id){
80
- entry.active = setActive;
81
- entry.opened = setActive;
82
- return entry;
83
- }
84
-
85
- if(entry.items?.length){
86
- const found = this.findItem(entry.items, item, setActive);
87
- if(found){
88
- entry.active = setActive;
89
- entry.opened = setActive;
90
- return found;
91
- }
92
- }
93
- }
94
- return undefined;
95
- },
96
- setUnActiveItems(items: any[]) {
97
- for(let item of items){
98
- item.active = false;
99
- if(item.items?.length){
100
- this.setUnActiveItems(item.items);
101
- }
102
- }
103
- },
104
- setActiveItem(items: any[], currentItem: any = null) {
105
- for(let leftItem of items){
106
- leftItem.active = leftItem.id === currentItem?.id;
107
- if(leftItem.items?.length){
108
- this.setActiveItem(leftItem.items, currentItem);
109
- }
110
- }
111
- },
112
- showTooltipItems(event: any) {
113
- if (!this.menuBar.opened) {
114
- if(this.item.items?.length){
115
- this.tooltip = true;
116
- document.querySelector('.active-tooltip')?.classList.add('show');
117
- }
118
- }
119
- },
120
- hideTooltipItems(event: any) {
121
- if (!this.menuBar.opened) {
122
- this.tooltip = false;
123
- document.querySelector('.active-tooltip')?.classList.remove('show');
124
- }
125
- }
126
- }
127
- };
128
-
129
-
130
- </script>
131
-
132
-
133
- <style scoped>
134
-
135
- .menu-plate {
136
- display: flex;
137
- flex-direction: column;
138
- width: 100%;
139
- height: 100%;
140
- background-color: #2c2c2c;
141
- color: white;
142
- }
143
-
144
- .horizontal-menu {
145
- display: flex;
146
- gap: 20px;
147
- padding: 10px;
148
- }
149
-
150
- .clicked {
151
- background-color: lightgray;
152
- }
153
-
154
- .menu-item-text{
155
- margin-left: 8px;
156
- }
157
-
158
- .show{
159
- display: flex;
160
- }
161
-
162
- .vertical-menu {
163
- display: flex;
164
- flex-direction: column;
165
- align-items: center;
166
- gap: 20px;
167
- padding: 10px;
168
- }
169
-
170
- .vertical-menu-opened {
171
- width: 200px;
172
- }
173
-
174
- .menu-item {
175
- margin-top: 20px;
176
- width: 180px;
177
- margin-left: 20px;
178
- height: 30px;
179
- margin: 0 16px !important;
180
- padding: 20px 0px;
181
- cursor: pointer;
182
- display: flex;
183
- justify-content: flex-start;
184
- align-items: center;
185
- }
186
- .menu-text-opened {
187
- animation: openMenuText 0.2s ease-in forwards;
188
- }
189
- .menu-text-closed {
190
- animation: closeMenuText 0.2s ease-out forwards;
191
- }
192
-
193
- .item-active {
194
- background-color: #ececec;
195
- }
196
-
197
- .sub-menu-button{
198
- margin-left: 8px;
199
- }
200
-
201
-
202
- @keyframes openMenuText {
203
- from {
204
- opacity: 0;
205
- transform: translateX(-20px);
206
- }
207
- to {
208
- opacity: 1;
209
- transform: translateX(0);
210
- }
211
- }
212
-
213
- @keyframes closeMenuText {
214
- from {
215
- opacity: 1;
216
- transform: translateX(0);
217
- }
218
- to {
219
- opacity: 0;
220
- transform: translateX(-20px);
221
- }
222
- }
223
-
224
- @keyframes openMenu {
225
- from {
226
- transform: rotate(0deg);
227
- }
228
- to {
229
- transform: rotate(90deg);
230
- }
231
- }
232
-
233
- .icon-opened{
234
- animation: openMenu 0.02s ease forwards;
235
- }
236
- </style>
1
+ <template>
2
+ <div
3
+ class="menu-item"
4
+ :ref="ref"
5
+ @click="openSubMenu(item)"
6
+ :class="{
7
+ 'item-opened': item.opened,
8
+ 'item-closed': !item.opened,
9
+ 'item-active': item.active,
10
+ }"
11
+ >
12
+ <FontAwesomeIcon
13
+ class="menu-item-icon"
14
+ v-if="item.icon"
15
+ :size="'lg'"
16
+ :icon="item.icon"
17
+ ></FontAwesomeIcon>
18
+ <p
19
+ class="menu-item-text"
20
+ :class="{
21
+ 'menu-text-opened': menuBar.opened,
22
+ 'menu-text-closed': !menuBar.opened,
23
+ }"
24
+ >
25
+ {{ item.name }}
26
+ </p>
27
+ <div class="sub-menu-button" v-if="item.items?.length">
28
+ <FontAwesomeIcon
29
+ :class="{ 'icon-opened': item.opened }"
30
+ :icon="item.openIcon"
31
+ ></FontAwesomeIcon>
32
+ </div>
33
+ </div>
34
+ </template>
35
+
36
+ <script lang="ts">
37
+ import { ref } from "vue";
38
+ import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
39
+ import { router, to } from "../routing/routing";
40
+ import { LeftMenuItems } from "../models/menu-models";
41
+ import { faChevronDown } from "@fortawesome/free-solid-svg-icons";
42
+
43
+ export default {
44
+ name: "MenuItem",
45
+ components: {
46
+ FontAwesomeIcon,
47
+ },
48
+ props: {
49
+ item: {
50
+ type: Object,
51
+ required: true,
52
+ },
53
+ leftItems: {
54
+ type: Array,
55
+ default: () => [] as LeftMenuItems[],
56
+ },
57
+ menuBar: {
58
+ type: Object,
59
+ required: true,
60
+ },
61
+ },
62
+ data() {
63
+ return {
64
+ menuBar: this.menuBar,
65
+ tooltip: true,
66
+ item: this.item,
67
+ faChevronDown: faChevronDown,
68
+ leftItems: this.leftItems as LeftMenuItems[],
69
+ ref: "item",
70
+ rotuer: router,
71
+ to: to,
72
+ };
73
+ },
74
+ watch: {
75
+ menuBar(newVal: any) {
76
+ this.menuBar = newVal;
77
+ },
78
+ item(newVal: any) {
79
+ this.item = newVal;
80
+ },
81
+ leftItems(newVal: any) {
82
+ this.leftItems = newVal;
83
+ },
84
+ },
85
+ emits: ["changeMenuItem"],
86
+ methods: {
87
+ openSubMenu(item: any) {
88
+ if (!item.items?.length) {
89
+ to(item.route);
90
+
91
+ this.setUnActiveItems(this.leftItems);
92
+ const activeItem = this.findItem(this.leftItems, item, true);
93
+ this.$emit("changeMenuItem", this.leftItems);
94
+ return;
95
+ }
96
+ item.opened = !item.opened;
97
+
98
+ if (!this.menuBar.opened) {
99
+ return;
100
+ }
101
+ },
102
+ findItem(items: any[], item: any, setActive: boolean): any | undefined {
103
+ for (const entry of items) {
104
+ if (entry.id === item.id) {
105
+ entry.active = setActive;
106
+ entry.opened = setActive;
107
+ return entry;
108
+ }
109
+
110
+ if (entry.items?.length) {
111
+ const found = this.findItem(entry.items, item, setActive);
112
+ if (found) {
113
+ entry.active = setActive;
114
+ entry.opened = setActive;
115
+ return found;
116
+ }
117
+ }
118
+ }
119
+ return undefined;
120
+ },
121
+ setUnActiveItems(items: any[]) {
122
+ for (const item of items) {
123
+ item.active = false;
124
+ if (item.items?.length) {
125
+ this.setUnActiveItems(item.items);
126
+ }
127
+ }
128
+ },
129
+ setActiveItem(items: any[], currentItem: any = null) {
130
+ for (const leftItem of items) {
131
+ leftItem.active = leftItem.id === currentItem?.id;
132
+ if (leftItem.items?.length) {
133
+ this.setActiveItem(leftItem.items, currentItem);
134
+ }
135
+ }
136
+ },
137
+ showTooltipItems(event: any) {
138
+ if (!this.menuBar.opened) {
139
+ if (this.item.items?.length) {
140
+ this.tooltip = true;
141
+ document.querySelector(".active-tooltip")?.classList.add("show");
142
+ }
143
+ }
144
+ },
145
+ hideTooltipItems(event: any) {
146
+ if (!this.menuBar.opened) {
147
+ this.tooltip = false;
148
+ document.querySelector(".active-tooltip")?.classList.remove("show");
149
+ }
150
+ },
151
+ },
152
+ };
153
+ </script>
154
+
155
+ <style scoped>
156
+ .menu-plate {
157
+ display: flex;
158
+ flex-direction: column;
159
+ width: 100%;
160
+ height: 100%;
161
+ background-color: #2c2c2c;
162
+ color: white;
163
+ }
164
+
165
+ .horizontal-menu {
166
+ display: flex;
167
+ gap: 20px;
168
+ padding: 10px;
169
+ }
170
+
171
+ .clicked {
172
+ background-color: lightgray;
173
+ }
174
+
175
+ .menu-item-text {
176
+ margin-left: 8px;
177
+ }
178
+
179
+ .show {
180
+ display: flex;
181
+ }
182
+
183
+ .vertical-menu {
184
+ display: flex;
185
+ flex-direction: column;
186
+ align-items: center;
187
+ gap: 20px;
188
+ padding: 10px;
189
+ }
190
+
191
+ .vertical-menu-opened {
192
+ width: 200px;
193
+ }
194
+
195
+ .menu-item {
196
+ margin-top: 20px;
197
+ width: 180px;
198
+ margin-left: 20px;
199
+ height: 30px;
200
+ margin: 0 16px !important;
201
+ padding: 20px 0px;
202
+ cursor: pointer;
203
+ display: flex;
204
+ justify-content: flex-start;
205
+ align-items: center;
206
+ }
207
+ .menu-text-opened {
208
+ animation: openMenuText 0.2s ease-in forwards;
209
+ }
210
+ .menu-text-closed {
211
+ animation: closeMenuText 0.2s ease-out forwards;
212
+ }
213
+
214
+ .item-active {
215
+ background-color: #ececec;
216
+ }
217
+
218
+ .sub-menu-button {
219
+ margin-left: 8px;
220
+ }
221
+
222
+ @keyframes openMenuText {
223
+ from {
224
+ opacity: 0;
225
+ transform: translateY(-20px);
226
+ }
227
+ to {
228
+ opacity: 1;
229
+ transform: translateY(0);
230
+ }
231
+ }
232
+
233
+ @keyframes closeMenuText {
234
+ from {
235
+ opacity: 1;
236
+ transform: translateX(0);
237
+ }
238
+ to {
239
+ opacity: 0;
240
+ transform: translateX(-20px);
241
+ }
242
+ }
243
+
244
+ @keyframes openMenu {
245
+ from {
246
+ transform: rotate(0deg);
247
+ }
248
+ to {
249
+ transform: rotate(180deg);
250
+ }
251
+ }
252
+
253
+ .icon-opened {
254
+ animation: openMenu 0.02s ease forwards;
255
+ }
256
+ </style>