| 
									
										
										
										
											2022-06-09 18:01:25 +02:00
										 |  |  | <template> | 
					
						
							| 
									
										
										
										
											2024-11-20 08:46:27 -06:00
										 |  |  |   <div v-if="yieldDisplay"> | 
					
						
							| 
									
										
										
										
											2022-06-09 18:01:25 +02:00
										 |  |  |     <div class="text-center d-flex align-center"> | 
					
						
							|  |  |  |       <div> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |         <v-menu | 
					
						
							|  |  |  |           v-model="menu" | 
					
						
							|  |  |  |           :disabled="!canEditScale" | 
					
						
							|  |  |  |           offset-y | 
					
						
							|  |  |  |           top | 
					
						
							|  |  |  |           nudge-top="6" | 
					
						
							|  |  |  |           :close-on-content-click="false" | 
					
						
							|  |  |  |         > | 
					
						
							| 
									
										
										
										
											2025-07-30 20:37:02 +02:00
										 |  |  |           <template #activator="{ props: activatorProps }"> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |             <v-tooltip | 
					
						
							|  |  |  |               v-if="canEditScale" | 
					
						
							|  |  |  |               size="small" | 
					
						
							| 
									
										
										
										
											2025-07-29 16:53:33 -05:00
										 |  |  |               location="top" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |               color="secondary-darken-1" | 
					
						
							|  |  |  |             > | 
					
						
							|  |  |  |               <template #activator="{ props: tooltipProps }"> | 
					
						
							|  |  |  |                 <v-card | 
					
						
							|  |  |  |                   class="pa-1 px-2" | 
					
						
							|  |  |  |                   dark | 
					
						
							|  |  |  |                   color="secondary-darken-1" | 
					
						
							|  |  |  |                   size="small" | 
					
						
							| 
									
										
										
										
											2025-07-30 20:37:02 +02:00
										 |  |  |                   v-bind="{ ...activatorProps, ...tooltipProps }" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |                   :style="{ cursor: canEditScale ? '' : 'default' }" | 
					
						
							|  |  |  |                 > | 
					
						
							|  |  |  |                   <v-icon | 
					
						
							|  |  |  |                     v-if="canEditScale" | 
					
						
							|  |  |  |                     size="small" | 
					
						
							|  |  |  |                     class="mr-2" | 
					
						
							|  |  |  |                   > | 
					
						
							|  |  |  |                     {{ $globals.icons.edit }} | 
					
						
							|  |  |  |                   </v-icon> | 
					
						
							|  |  |  |                   <!-- eslint-disable-next-line vue/no-v-html --> | 
					
						
							|  |  |  |                   <span v-html="yieldDisplay" /> | 
					
						
							|  |  |  |                 </v-card> | 
					
						
							|  |  |  |               </template> | 
					
						
							|  |  |  |               <span> {{ $t("recipe.edit-scale") }} </span> | 
					
						
							|  |  |  |             </v-tooltip> | 
					
						
							| 
									
										
										
										
											2025-01-07 18:26:36 +01:00
										 |  |  |             <v-card | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |               v-else | 
					
						
							| 
									
										
										
										
											2025-01-07 18:26:36 +01:00
										 |  |  |               class="pa-1 px-2" | 
					
						
							|  |  |  |               dark | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |               color="secondary-darken-1" | 
					
						
							|  |  |  |               size="small" | 
					
						
							| 
									
										
										
										
											2025-07-30 20:37:02 +02:00
										 |  |  |               v-bind="activatorProps" | 
					
						
							| 
									
										
										
										
											2025-01-07 18:26:36 +01:00
										 |  |  |               :style="{ cursor: canEditScale ? '' : 'default' }" | 
					
						
							|  |  |  |             > | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |               <v-icon | 
					
						
							|  |  |  |                 v-if="canEditScale" | 
					
						
							|  |  |  |                 size="small" | 
					
						
							|  |  |  |                 class="mr-2" | 
					
						
							|  |  |  |               > | 
					
						
							|  |  |  |                 {{ $globals.icons.edit }} | 
					
						
							|  |  |  |               </v-icon> | 
					
						
							| 
									
										
										
										
											2024-11-20 08:46:27 -06:00
										 |  |  |               <!-- eslint-disable-next-line vue/no-v-html --> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |               <span v-html="yieldDisplay" /> | 
					
						
							| 
									
										
										
										
											2022-06-09 18:01:25 +02:00
										 |  |  |             </v-card> | 
					
						
							|  |  |  |           </template> | 
					
						
							|  |  |  |           <v-card min-width="300px"> | 
					
						
							|  |  |  |             <v-card-title class="mb-0"> | 
					
						
							| 
									
										
										
										
											2024-10-01 16:31:04 +02:00
										 |  |  |               {{ $t("recipe.servings") }} | 
					
						
							| 
									
										
										
										
											2022-06-09 18:01:25 +02:00
										 |  |  |             </v-card-title> | 
					
						
							|  |  |  |             <v-card-text class="mt-n5"> | 
					
						
							|  |  |  |               <div class="mt-4 d-flex align-center"> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |                 <v-text-field | 
					
						
							| 
									
										
										
										
											2025-07-28 10:54:59 -05:00
										 |  |  |                   :model-value="yieldQuantity" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |                   type="number" | 
					
						
							|  |  |  |                   :min="0" | 
					
						
							|  |  |  |                   variant="underlined" | 
					
						
							|  |  |  |                   hide-spin-buttons | 
					
						
							| 
									
										
										
										
											2025-07-28 10:54:59 -05:00
										 |  |  |                   @update:model-value="recalculateScale(parseFloat($event) || 0)" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |                 /> | 
					
						
							|  |  |  |                 <v-tooltip | 
					
						
							| 
									
										
										
										
											2025-07-29 16:53:33 -05:00
										 |  |  |                   location="end" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |                   color="secondary-darken-1" | 
					
						
							|  |  |  |                 > | 
					
						
							| 
									
										
										
										
											2025-07-30 20:37:02 +02:00
										 |  |  |                   <template #activator="{ props: resetTooltipProps }"> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |                     <v-btn | 
					
						
							| 
									
										
										
										
											2025-07-30 20:37:02 +02:00
										 |  |  |                       v-bind="resetTooltipProps" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |                       icon | 
					
						
							| 
									
										
										
										
											2025-07-28 10:54:59 -05:00
										 |  |  |                       flat | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |                       class="mx-1" | 
					
						
							|  |  |  |                       size="small" | 
					
						
							|  |  |  |                       @click="scale = 1" | 
					
						
							|  |  |  |                     > | 
					
						
							| 
									
										
										
										
											2022-06-09 18:01:25 +02:00
										 |  |  |                       <v-icon> | 
					
						
							|  |  |  |                         {{ $globals.icons.undo }} | 
					
						
							|  |  |  |                       </v-icon> | 
					
						
							|  |  |  |                     </v-btn> | 
					
						
							|  |  |  |                   </template> | 
					
						
							| 
									
										
										
										
											2024-10-01 16:31:04 +02:00
										 |  |  |                   <span> {{ $t("recipe.reset-servings-count") }} </span> | 
					
						
							| 
									
										
										
										
											2022-06-09 18:01:25 +02:00
										 |  |  |                 </v-tooltip> | 
					
						
							|  |  |  |               </div> | 
					
						
							|  |  |  |             </v-card-text> | 
					
						
							|  |  |  |           </v-card> | 
					
						
							|  |  |  |         </v-menu> | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |       <BaseButtonGroup | 
					
						
							| 
									
										
										
										
											2024-11-20 08:46:27 -06:00
										 |  |  |         v-if="canEditScale" | 
					
						
							| 
									
										
										
										
											2022-06-09 18:01:25 +02:00
										 |  |  |         class="pl-2" | 
					
						
							|  |  |  |         :large="false" | 
					
						
							|  |  |  |         :buttons="[ | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             icon: $globals.icons.minus, | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |             text: $t('recipe.decrease-scale-label'), | 
					
						
							| 
									
										
										
										
											2022-06-09 18:01:25 +02:00
										 |  |  |             event: 'decrement', | 
					
						
							| 
									
										
										
										
											2024-10-01 16:31:04 +02:00
										 |  |  |             disabled: disableDecrement, | 
					
						
							| 
									
										
										
										
											2022-06-09 18:01:25 +02:00
										 |  |  |           }, | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             icon: $globals.icons.createAlt, | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |             text: $t('recipe.increase-scale-label'), | 
					
						
							| 
									
										
										
										
											2022-06-09 18:01:25 +02:00
										 |  |  |             event: 'increment', | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         ]" | 
					
						
							| 
									
										
										
										
											2024-11-20 08:46:27 -06:00
										 |  |  |         @decrement="recalculateScale(yieldQuantity - 1)" | 
					
						
							|  |  |  |         @increment="recalculateScale(yieldQuantity + 1)" | 
					
						
							| 
									
										
										
										
											2022-06-09 18:01:25 +02:00
										 |  |  |       /> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   </div> | 
					
						
							|  |  |  | </template> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-30 20:37:02 +02:00
										 |  |  | <script setup lang="ts"> | 
					
						
							| 
									
										
										
										
											2024-11-20 08:46:27 -06:00
										 |  |  | import { useScaledAmount } from "~/composables/recipes/use-scaled-amount"; | 
					
						
							| 
									
										
										
										
											2022-06-09 18:01:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-30 20:37:02 +02:00
										 |  |  | interface Props { | 
					
						
							|  |  |  |   recipeServings?: number; | 
					
						
							|  |  |  |   editScale?: boolean; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | const props = withDefaults(defineProps<Props>(), { | 
					
						
							|  |  |  |   recipeServings: 0, | 
					
						
							|  |  |  |   editScale: false, | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2022-06-09 18:01:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-30 20:37:02 +02:00
										 |  |  | const scale = defineModel<number>({ required: true }); | 
					
						
							| 
									
										
										
										
											2022-06-09 18:01:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-30 20:37:02 +02:00
										 |  |  | const i18n = useI18n(); | 
					
						
							|  |  |  | const menu = ref<boolean>(false); | 
					
						
							|  |  |  | const canEditScale = computed(() => props.editScale && props.recipeServings > 0); | 
					
						
							| 
									
										
										
										
											2024-11-20 08:46:27 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-30 20:37:02 +02:00
										 |  |  | function recalculateScale(newYield: number) { | 
					
						
							|  |  |  |   if (isNaN(newYield) || newYield <= 0) { | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2024-10-01 16:31:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-30 20:37:02 +02:00
										 |  |  |   if (props.recipeServings <= 0) { | 
					
						
							|  |  |  |     scale.value = 1; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     scale.value = newYield / props.recipeServings; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2024-10-01 16:31:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-30 20:37:02 +02:00
										 |  |  | const recipeYieldAmount = computed(() => { | 
					
						
							|  |  |  |   return useScaledAmount(props.recipeServings, scale.value); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | const yieldQuantity = computed(() => recipeYieldAmount.value.scaledAmount); | 
					
						
							|  |  |  | const yieldDisplay = computed(() => { | 
					
						
							|  |  |  |   return yieldQuantity.value | 
					
						
							|  |  |  |     ? i18n.t( | 
					
						
							|  |  |  |       "recipe.serves-amount", { amount: recipeYieldAmount.value.scaledAmountDisplay }, | 
					
						
							|  |  |  |     ) as string | 
					
						
							|  |  |  |     : ""; | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2024-10-01 16:31:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-30 20:37:02 +02:00
										 |  |  | const disableDecrement = computed(() => { | 
					
						
							|  |  |  |   return yieldQuantity.value <= 1; | 
					
						
							| 
									
										
										
										
											2022-06-09 18:01:25 +02:00
										 |  |  | }); | 
					
						
							|  |  |  | </script> |