From 4ec42fdbc0200d003c57299814af75f069363fe9 Mon Sep 17 00:00:00 2001 From: Dayowe Date: Mon, 18 Aug 2025 14:36:25 +0200 Subject: [PATCH] Add cups unit option for kcal/cup measurements Features: - Add cups as a unit option that only works with kcal/cup energy measurements - Cups button is disabled with tooltip when kcal/cup is not selected - Auto-select cups when user selects kcal/cup as energy unit - Auto-switch to appropriate units when changing energy measurement types - Calculate cup amounts directly from calories without density assumptions Fixes: - Ensure cups display correct values immediately upon auto-selection - Fix "Per day" radio button to be pre-selected when feeding config becomes visible - Handle empty unit values with failsafe fallback to active button Technical details: - Direct calorie-to-cups conversion bypassing gram conversions - Pre-calculate cups values in food breakdown for efficient display - Set unit before updating calculations to avoid timing issues - Added CSS styling for disabled button state across all themes --- iframe.html | 330 +++++++++++++++++++++++++++++++--- src/css/themes.css | 40 +++++ src/index.html | 2 + src/js/calculator.js | 285 ++++++++++++++++++++++++++--- sundog-dog-food-calculator.js | 330 +++++++++++++++++++++++++++++++--- 5 files changed, 914 insertions(+), 73 deletions(-) diff --git a/iframe.html b/iframe.html index 624e892..983d804 100644 --- a/iframe.html +++ b/iframe.html @@ -497,9 +497,8 @@ .dog-calculator-container .dog-calculator-meal-input { display: inline-flex; align-items: center; - justify-content: center; gap: 6px; - margin-left: auto; + margin: 0 auto; } .dog-calculator-container .dog-calculator-meal-input span { @@ -660,6 +659,19 @@ background: #f19a5f; color: white; } + + .dog-calculator-container.theme-dark .dog-calculator-unit-btn:disabled { + opacity: 0.5; + cursor: not-allowed; + border-color: var(--border-color); + background: var(--bg-tertiary); + color: var(--text-secondary); + } + + .dog-calculator-container.theme-dark .dog-calculator-unit-btn:disabled:hover { + border-color: var(--border-color); + background: var(--bg-tertiary); + } .dog-calculator-container.theme-dark .dog-calculator-results { background: linear-gradient(135deg, rgba(241, 154, 95, 0.15) 0%, rgba(241, 154, 95, 0.08) 100%); @@ -853,6 +865,19 @@ background: #f19a5f; color: white; } + + .dog-calculator-container.theme-system .dog-calculator-unit-btn:disabled { + opacity: 0.5; + cursor: not-allowed; + border-color: var(--border-color); + background: var(--bg-tertiary); + color: var(--text-secondary); + } + + .dog-calculator-container.theme-system .dog-calculator-unit-btn:disabled:hover { + border-color: var(--border-color); + background: var(--bg-tertiary); + } .dog-calculator-container.theme-system .dog-calculator-results { background: linear-gradient(135deg, rgba(241, 154, 95, 0.15) 0%, rgba(241, 154, 95, 0.08) 100%); @@ -1840,6 +1865,20 @@ color: white; } + .dog-calculator-unit-btn:disabled { + opacity: 0.5; + cursor: not-allowed; + border-color: var(--border-color); + background: var(--bg-tertiary); + color: var(--text-secondary); + } + + .dog-calculator-unit-btn:disabled:hover { + border-color: var(--border-color); + background: var(--bg-tertiary); + transform: none; + } + /* Hidden unit select for compatibility */ .dog-calculator-unit-select-hidden { display: none; @@ -2117,6 +2156,7 @@ + @@ -2133,6 +2173,7 @@ + @@ -116,6 +117,7 @@ + @@ -2196,6 +2236,7 @@ const CALCULATOR_CONFIG = { +