From 92b90dd3b0c6c38f254b613da4655bb66c08b029 Mon Sep 17 00:00:00 2001 From: w33ble Date: Sun, 11 Jan 2026 20:01:29 -0700 Subject: [PATCH] feat: move the unit selection above the inputs, make it blue --- index.html | 27 +++++++++++++++------------ src/main.ts | 27 ++++++++++++++++++--------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/index.html b/index.html index 1454ad7..6b792a7 100644 --- a/index.html +++ b/index.html @@ -15,11 +15,22 @@
-

- Drawer Dimensions -

+
+

+ Drawer Dimensions +

+ +
+ +
+ + +
+
+ +
-
+
@@ -33,14 +44,6 @@
- -
- -
- - -
-
diff --git a/src/main.ts b/src/main.ts index b01fede..a474c34 100644 --- a/src/main.ts +++ b/src/main.ts @@ -22,7 +22,7 @@ const gapLength = document.getElementById('gap-length') as HTMLElement; const gapHeight = document.getElementById('gap-height') as HTMLElement; // State -let currentUnit: 'mm' | 'in' = 'mm'; +let currentUnit: 'mm' | 'in' = 'in'; function updateResults() { const width = parseFloat(inputWidth.value) || 0; @@ -68,6 +68,20 @@ function updateResults() { el.addEventListener('input', updateResults); }); +function setUnitStyles(unit: 'mm' | 'in') { + if (unit === 'in') { + unitInBtn.classList.add('bg-blue-600', 'text-white', 'shadow-sm'); + unitInBtn.classList.remove('text-slate-600', 'hover:text-slate-900'); + unitMmBtn.classList.remove('bg-blue-600', 'text-white', 'shadow-sm'); + unitMmBtn.classList.add('text-slate-600', 'hover:text-slate-900'); + } else { + unitMmBtn.classList.add('bg-blue-600', 'text-white', 'shadow-sm'); + unitMmBtn.classList.remove('text-slate-600', 'hover:text-slate-900'); + unitInBtn.classList.remove('bg-blue-600', 'text-white', 'shadow-sm'); + unitInBtn.classList.add('text-slate-600', 'hover:text-slate-900'); + } +} + unitMmBtn.addEventListener('click', () => { if (currentUnit === 'mm') return; @@ -81,10 +95,7 @@ unitMmBtn.addEventListener('click', () => { if (height > 0) inputHeight.value = convertUnits(height, 'in', 'mm').toFixed(1); currentUnit = 'mm'; - unitMmBtn.classList.add('bg-white', 'shadow-sm'); - unitMmBtn.classList.remove('text-slate-600'); - unitInBtn.classList.remove('bg-white', 'shadow-sm'); - unitInBtn.classList.add('text-slate-600'); + setUnitStyles('mm'); updateResults(); }); @@ -101,12 +112,10 @@ unitInBtn.addEventListener('click', () => { if (height > 0) inputHeight.value = convertUnits(height, 'mm', 'in').toFixed(2); currentUnit = 'in'; - unitInBtn.classList.add('bg-white', 'shadow-sm'); - unitInBtn.classList.remove('text-slate-600'); - unitMmBtn.classList.remove('bg-white', 'shadow-sm'); - unitMmBtn.classList.add('text-slate-600'); + setUnitStyles('in'); updateResults(); }); // Initial call updateResults(); +setUnitStyles(currentUnit);