feat: surface meal taxonomy chips
This commit is contained in:
+21
-6
@@ -30,6 +30,20 @@ function optionHtml(options, selected) {
|
||||
return options.map(([value, label]) => `<option value="${value}" ${value === selected ? 'selected' : ''}>${label}</option>`).join('');
|
||||
}
|
||||
|
||||
function optionLabel(options, value) {
|
||||
return options.find(([optionValue]) => optionValue === value)?.[1] || value || '';
|
||||
}
|
||||
|
||||
function taxonomyChip(kind, value, label) {
|
||||
if (!value || !label) return null;
|
||||
const chip = document.createElement('span');
|
||||
chip.className = `recipe-taxonomy-chip recipe-taxonomy-chip--${kind}`;
|
||||
chip.dataset.recipeTaxonomy = kind;
|
||||
chip.dataset.taxonomyValue = value;
|
||||
chip.textContent = label;
|
||||
return chip;
|
||||
}
|
||||
|
||||
function mealCategories() {
|
||||
return state.categories.filter((c) => c.name !== 'Haushalt' && c.name !== 'Drogerie');
|
||||
}
|
||||
@@ -216,14 +230,15 @@ function renderRecipeList() {
|
||||
card.appendChild(h);
|
||||
|
||||
const taxonomy = [
|
||||
recipe.meal_category ? MEAL_CATEGORY_OPTIONS.find(([v]) => v === recipe.meal_category)?.[1] || recipe.meal_category : '',
|
||||
recipe.protein ? PROTEIN_OPTIONS.find(([v]) => v === recipe.protein)?.[1] || recipe.protein : '',
|
||||
recipe.style ? STYLE_OPTIONS.find(([v]) => v === recipe.style)?.[1] || recipe.style : '',
|
||||
taxonomyChip('category', recipe.meal_category, optionLabel(MEAL_CATEGORY_OPTIONS, recipe.meal_category)),
|
||||
taxonomyChip('protein', recipe.protein, optionLabel(PROTEIN_OPTIONS, recipe.protein)),
|
||||
taxonomyChip('style', recipe.style, optionLabel(STYLE_OPTIONS, recipe.style)),
|
||||
].filter(Boolean);
|
||||
if (taxonomy.length) {
|
||||
const meta = document.createElement('p');
|
||||
meta.className = 'recipe-card__notes';
|
||||
meta.textContent = `Kategori: ${taxonomy.join(' · ')}`;
|
||||
const meta = document.createElement('div');
|
||||
meta.className = 'recipe-card__taxonomy';
|
||||
meta.setAttribute('aria-label', 'Recipe classification');
|
||||
meta.append(...taxonomy);
|
||||
card.appendChild(meta);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user