@@ -6,11 +6,8 @@ Description:
6
6
7
7
<template >
8
8
<section class =" icon-grid" >
9
- <button
10
- @click.prevent =" changeState(elementName)"
11
- v-for =" ([elementName, iconString], idx) in Object.entries(icons)"
12
- :key =" idx + Date.now()"
13
- >
9
+ <button @click.prevent =" changeState(elementName)" v-for =" ([elementName, iconString], idx) in Object.entries(icons)"
10
+ :key =" idx + Date.now()" >
14
11
<span class =" badge" > {{ elementStorage[elementName] }}</span >
15
12
<br />
16
13
<i :class =" iconString" ></i >
@@ -41,13 +38,33 @@ export default {
41
38
elementStorage : function () {
42
39
let computedElementalStorage = {};
43
40
if (this .activeComponent ) {
41
+
44
42
this .componentMap [this .activeComponent ].htmlList .forEach ((el ) => {
45
43
if (! computedElementalStorage[el .text ]) {
46
44
computedElementalStorage[el .text ] = 1 ;
47
- } else {
45
+ }
46
+ else if (computedElementalStorage[el .text ]) {
48
47
computedElementalStorage[el .text ] += 1 ;
49
48
}
50
49
});
50
+ // show the badge for all nested children arrays
51
+ const checkChild = array => {
52
+ for (let html of array) {
53
+ console .log (html)
54
+ if (html .children .length ) {
55
+ checkChild (html .children )
56
+ } else {
57
+ if (! computedElementalStorage[html .text ]) {
58
+ computedElementalStorage[html .text ] = 1
59
+ } else {
60
+ ++ computedElementalStorage[html .text ]
61
+ }
62
+ }
63
+ }
64
+ }
65
+ // invoke the recursive function
66
+ checkChild (this .componentMap [this .activeComponent ].htmlList )
67
+
51
68
} else if (this .activeComponent === " " ) {
52
69
// if component was switched from existing component to '', reset cache and update items
53
70
if (computedElementalStorage !== {}) computedElementalStorage = {};
@@ -104,23 +121,28 @@ export default {
104
121
width : 100% ;
105
122
}
106
123
}
124
+
107
125
button {
108
126
background : none ;
109
127
color : $menutext ;
110
128
border : none ;
111
129
}
130
+
112
131
button :hover {
113
132
cursor : pointer ;
114
133
color : $secondary ;
115
134
}
135
+
116
136
button :focus {
117
137
outline : none ;
118
138
color : $secondary ;
119
139
}
140
+
120
141
button :active {
121
142
box-shadow : 0 5px inherit ;
122
143
transform : translateY (4px );
123
144
}
145
+
124
146
.badge {
125
147
width : 15px ;
126
148
line-height : 15px ;
0 commit comments