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