munch-ease-frontend/src/components/IngredientLine.vue

166 lines
4.5 KiB
Vue
Raw Normal View History

2024-01-13 02:00:15 +00:00
<template>
<div class="ingredient-item">
2024-01-17 06:03:11 +00:00
<div class="full-ingredient">
<p>
<input v-model="ingredientText" @keyup.enter="updateIngredient" @focusout="updateIngredient" placeholder="Enter an ingredient" />
<input v-model="productLink" class="product-link-input" placeholder="Enter product link" @keyup.enter="updateProductLink" @focusout="updateProductLink" />
</p>
</div>
2024-01-13 02:00:15 +00:00
<!-- Full ingredient line text bar -->
2024-01-13 06:36:02 +00:00
<div class="action_items">
<div class="action-bar">
<!-- Single line parse results -->
<div class="compact-parse-results">
2024-01-14 06:20:21 +00:00
<compact-parsed-ingredient :ingredient="ingredient" />
2024-01-13 06:36:02 +00:00
</div>
<!-- Expand details button with animated chevron -->
<button class="expand-button" @click="showDetails = !showDetails">
<span :class="{'rotate-chevron': showDetails}">&#9662;</span>
</button>
2024-01-13 02:00:15 +00:00
</div>
2024-01-13 06:36:02 +00:00
<!-- Details section -->
2024-01-14 06:20:21 +00:00
<div v-if="showDetails" class="expanded-section">
<div class="details-section ingredient-details">
<div class="parse-result">
<p><small>Ingredient: </small><strong>{{ ingredient.name }}</strong></p>
<p><small>Quantity: </small> <strong>{{ ingredient.quantity }}</strong></p>
<p><small>Unit: </small> <strong>{{ ingredient.unit }}</strong></p>
<p><small>Preparation: </small> <strong>{{ ingredient.preparation }}</strong></p>
</div>
<div v-if="ingredient.product" class="product-result">
<p>
<a :href="ingredient?.product?.link"><small>Product: </small>
<strong>{{ ingredient.product.name }}</strong>
<img src="@/assets/external-link.svg" style="width: 1em; height: 1em; vertical-align: middle; margin-left: 0.5em; margin-bottom: 0.2em;" target=_blank/>
</a>
</p>
<p><img :src="ingredient.product.img_small" /></p>
</div>
2024-01-13 06:36:02 +00:00
</div>
2024-01-13 02:00:15 +00:00
</div>
</div>
2024-01-13 06:36:02 +00:00
2024-01-13 02:00:15 +00:00
</div>
</template>
<script>
2024-01-14 06:20:21 +00:00
import CompactParsedIngredient from './CompactParsedIngredient.vue';
2024-01-13 02:00:15 +00:00
export default {
props: {
2024-01-14 06:20:21 +00:00
ingredient: { type: Object },
showExpanded: { type: Boolean, default: false }
2024-01-13 02:00:15 +00:00
},
events: ['update-ingredient', 'update-product-link'],
2024-01-14 06:20:21 +00:00
components: { CompactParsedIngredient },
2024-01-13 02:00:15 +00:00
data() {
return {
ingredientText: this.ingredient.line,
productLink: this.ingredient.product?.link ?? "",
2024-01-14 06:20:21 +00:00
showDetails: this.showExpanded
2024-01-13 02:00:15 +00:00
};
},
methods: {
updateIngredient() {
if (this.ingredientText != this.ingredient.line)
this.$emit('update-ingredient', this.ingredient, this.ingredientText);
},
updateProductLink() {
if (this.productLink && this.productLink != this.ingredient.product?.link)
this.$emit('update-product-link', this.ingredient, this.productLink);
2024-01-14 02:12:19 +00:00
}
2024-01-13 02:00:15 +00:00
}
};
</script>
<style scoped>
2024-01-14 06:20:21 +00:00
.compact-parse-results {
flex: 1;
}
2024-01-13 02:00:15 +00:00
.ingredient-item {
border-radius: 5px;
padding: 10px;
margin-bottom: 10px;
}
.full-ingredient {
display: flex;
flex-direction: row;
justify-content: space-between;
text-align: left;
padding-left: 1em;
}
2024-01-13 06:36:02 +00:00
.action-bar {
display: flex;
align-items: center;
justify-content: right;
padding: 10px;
border: 1px solid #ccc;
margin-bottom: 10px;
}
.delete-button,
.expand-button {
padding: 8px 16px;
margin: 0 5px;
cursor: pointer;
}
.expand-button {
background-color: #f0f0f0;
border: 1px solid #ccc;
}
.rotate-chevron {
transform: rotate(180deg);
}
.details-section {
margin-top: 10px;
padding: 10px;
border: 1px solid #ccc;
display: flex;
flex-direction: column;
align-items: flex-start;
}
2024-01-13 02:00:15 +00:00
.full-ingredient p {
flex: 1;
}
.full-ingredient input {
border: 0;
font-size: larger;
border-bottom: 1px solid #ccc;
border-left: 1px solid #ccc;
width: 100%;
}
2024-01-14 01:46:45 +00:00
.product-link-input {
padding: 0.5vh;
color: #777;
margin-top: 0.2vh;
}
2024-01-13 02:00:15 +00:00
.ingredient-details {
display: flex;
flex-direction: row;
justify-content: space-between;
text-align: left;
padding-left: 1em;
}
.parse-result {
flex: 1;
}
.product-result {
flex: 1;
}
</style>