File tree Expand file tree Collapse file tree 5 files changed +74
-32
lines changed
Filter options
Expand file tree Collapse file tree 5 files changed +74
-32
lines changed
Original file line number Diff line number Diff line change @@ -191,31 +191,7 @@ <h1 class="d-flex flex-column align-items-center font-monospace text-uppercase t
191
191
<!-- Filtered tags -->
192
192
< div class ="row ">
193
193
< div class ="col-12 ">
194
- < ul class ="list-group list-group-horizontal d-flex flex-wrap gap-3 ">
195
- < li class ="list-group-item d-flex justify-content-between flex-wrap align-items-center rounded col-6 col-md-3 col-lg-2 py-3 bg-primary ">
196
- An item
197
- < button
198
- type ="button "
199
- class ="btn-close "
200
- aria-label ="Supprimer cet ingrédient ">
201
- </ button >
202
- </ li >
203
- < li class ="list-group-item d-flex justify-content-between flex-wrap align-items-center rounded col-6 col-md-3 col-lg-2 py-3 bg-primary ">
204
- An item
205
- < button
206
- type ="button "
207
- class ="btn-close "
208
- aria-label ="Supprimer cet appareil ">
209
- </ button >
210
- </ li >
211
- < li class ="list-group-item d-flex justify-content-between flex-wrap align-items-center rounded col-6 col-md-3 col-lg-2 py-3 bg-primary ">
212
- An item
213
- < button
214
- type ="button "
215
- class ="btn-close "
216
- aria-label ="Supprimer cet ustensile ">
217
- </ button >
218
- </ li >
194
+ < ul id ="active_tags " class ="list-group list-group-horizontal d-flex flex-wrap gap-3 ">
219
195
</ ul >
220
196
</ div >
221
197
</ div > <!-- End Filtered tags -->
@@ -241,6 +217,7 @@ <h1 class="d-flex flex-column align-items-center font-monospace text-uppercase t
241
217
< script src ="js/api/DataApi.js "> </ script >
242
218
<!-- Templates -->
243
219
< script src ="js/templates/ItemDropdown.js "> </ script >
220
+ < script src ="js/templates/ActiveTag.js "> </ script >
244
221
< script src ="js/templates/RecipeCard.js "> </ script >
245
222
<!-- Pages -->
246
223
< script src ="js/pages/RecipesPage.js "> </ script >
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ class RecipesApp {
10
10
constructor ( ) {
11
11
this . dataApi = new DataApi ( '/data/recipes.json' ) ;
12
12
this . recipesPage = new RecipesPage ( ) ;
13
+ this . tags = new Array ( ) ;
13
14
14
15
this . $ingredientsList = document . querySelector ( '#ingredients_list' ) ;
15
16
this . $appliancesList = document . querySelector ( '#appliances_list' ) ;
@@ -28,6 +29,11 @@ class RecipesApp {
28
29
29
30
// Cards
30
31
this . displayRecipeCardsWithData ( ) ;
32
+
33
+ // Tags
34
+ this . tags . push ( 'item 1' , 'item 2' , 'item 3' ) ;
35
+ const tags = this . tags ;
36
+ this . displayActiveTags ( tags ) ;
31
37
}
32
38
33
39
displayRecipeCardsWithData ( ) {
@@ -96,6 +102,19 @@ class RecipesApp {
96
102
this . recipesPage . displayItemForDropdown ( ustensil , this . $ustensilsList ) ;
97
103
} ) ;
98
104
}
105
+
106
+ /**
107
+ * @type {(string|Array) }
108
+ * @param {Object } items
109
+ */
110
+ displayActiveTags ( items ) {
111
+ items
112
+ . forEach ( item => {
113
+ const activeTag = new ActiveTag ( ) ;
114
+ const tag = activeTag . createActivetag ( item ) ;
115
+ this . recipesPage . displayActiveTag ( tag ) ;
116
+ } ) ;
117
+ }
99
118
}
100
119
const recipesApp = new RecipesApp ( ) ;
101
120
recipesApp . init ( ) ;
Original file line number Diff line number Diff line change 7
7
class RecipesPage {
8
8
constructor ( ) {
9
9
this . $recipeCards = document . querySelector ( '.recipe-cards' ) ;
10
+ this . $activeTags = document . querySelector ( '#active_tags' ) ;
10
11
}
11
12
12
13
/**
19
20
const itemDropdown = new ItemDropdown ( ) ;
20
21
itemDropdown . createItemForDropdown ( data , list ) ;
21
22
}
23
+
24
+ /**
25
+ * Displays active tag
26
+ * @param {HTMLElement } item
27
+ */
28
+ async displayActiveTag ( item ) {
29
+ this . $activeTags . appendChild ( item ) ;
30
+ }
22
31
23
32
/**
24
33
* Displays recipe card
Original file line number Diff line number Diff line change
1
+ /**
2
+ * ------------------------------------------------------------
3
+ * Les Petits Plats templates/ActiveTag.js
4
+ * ------------------------------------------------------------
5
+ */
6
+
7
+ class ActiveTag {
8
+ /**
9
+ * Creates li tag with close button
10
+ * @param {string } item
11
+ * @returns HTMLElement - li
12
+ */
13
+ createActivetag ( item ) {
14
+
15
+ const li = document . createElement ( 'li' ) ;
16
+ li . classList . add (
17
+ 'list-group-item' ,
18
+ 'd-flex' ,
19
+ 'justify-content-between' ,
20
+ 'flex-wrap' ,
21
+ 'align-items-center' ,
22
+ 'rounded' ,
23
+ 'col-6' ,
24
+ 'col-md-3' ,
25
+ 'col-lg-2' ,
26
+ 'py-3' ,
27
+ 'bg-primary' ) ;
28
+
29
+ li . innerHTML = `
30
+ ${ item }
31
+ <button
32
+ type="button"
33
+ class="btn-close"
34
+ aria-label="Supprimer cet ingrédient">
35
+ </button>` ;
36
+
37
+ return li ;
38
+ }
39
+ }
Original file line number Diff line number Diff line change 4
4
* ------------------------------------------------------------
5
5
*/
6
6
7
- class ItemDropdown {
7
+ class ItemDropdown {
8
8
/**
9
9
* @param {Object } recipes - list of objects from .json file
10
10
*/
22
22
* @param {string } data
23
23
* @param {HTMLElement } list
24
24
*/
25
- createItemForDropdown ( data , list ) {
25
+ createItemForDropdown ( data , list ) {
26
26
27
27
const li = document . createElement ( 'li' ) ;
28
28
29
29
if ( data !== undefined ) {
30
30
31
31
li . innerHTML = `
32
- <li>
33
- <a class="dropdown-item" role="option">
32
+ <a class="dropdown-item" role="option">
34
33
${ data }
35
- </a>
36
- </li>` ;
34
+ </a>` ;
37
35
}
38
36
39
37
list . appendChild ( li ) ;
40
38
}
41
- }
39
+ }
You can’t perform that action at this time.
0 commit comments