From e9e3a96cd98883038b69807ac150f90d7f2c5838 Mon Sep 17 00:00:00 2001 From: Zachary Date: Sun, 10 Nov 2024 22:41:06 +0100 Subject: [PATCH] Add flags --- src/routes/+page.svelte | 58 ++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 365ff72..8bad09c 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -16,6 +16,9 @@ let daysOff = ptoData['BE']; let optimizedDaysOff = []; let consecutiveDaysOff = []; + let placeholder = "Country"; + let isFirstClick = true; + let inputElement; function handleYearChange(event) { year = parseInt(event.target.value); @@ -23,13 +26,25 @@ } function handleCountryChange(event) { - const countryName = event.target.value; - const countryCode = Object.keys(countriesList).find(code => countriesList[code] === countryName); + const fullValue = event.target.value; + const countryCode = Object.keys(countriesList).find(code => countriesList[code] === fullValue); if (countryCode) { - selectedCountry = countryName; + selectedCountry = fullValue; daysOff = ptoData[countryCode] || 0; updateHolidays(); } + adjustInputWidth(event.target); + } + + function adjustInputWidth(inputElement) { + const tempSpan = document.createElement('span'); + tempSpan.style.visibility = 'hidden'; + tempSpan.style.position = 'absolute'; + tempSpan.style.whiteSpace = 'nowrap'; + tempSpan.textContent = inputElement.value || inputElement.placeholder; + document.body.appendChild(tempSpan); + inputElement.style.width = `${tempSpan.offsetWidth + 30}px`; + document.body.removeChild(tempSpan); } function updateHolidays() { @@ -68,11 +83,23 @@ } } + function getFlagEmoji(countryCode) { + return countryCode + .toUpperCase() + .replace(/./g, char => String.fromCodePoint(127397 + char.charCodeAt())); + } + onMount(() => { window.addEventListener('keydown', handleKeyDown); return () => { window.removeEventListener('keydown', handleKeyDown); }; + adjustInputWidth(inputElement); + inputElement.addEventListener('input', () => adjustInputWidth(inputElement)); + inputElement.addEventListener('focus', () => { + inputElement.value = ''; + adjustInputWidth(inputElement); + }); }); updateHolidays(); @@ -171,10 +198,18 @@ color: inherit; font-size: inherit; font-family: inherit; - width: auto; text-align: center; margin: 0 10px; outline: none; + transition: width 0.2s; + -webkit-appearance: none; /* Remove default styling */ + -moz-appearance: none; + appearance: none; + color: #e0e0e0; /* Default text color */ + } + + .editable-input::placeholder { + color: #a0a0a0; /* Slightly grayer text for placeholder */ } .arrow-controls { @@ -213,17 +248,22 @@ font-weight: bold; font-size: 1.2em; } + + .flag { + font-size: 2em; /* Adjust the size as needed */ + }
-

Stretch My Holidays

+

Stretch My Time Off

I live in - + {getFlagEmoji(Object.keys(countriesList).find(code => countriesList[code] === selectedCountry))} + { inputElement.value = ''; adjustInputWidth(); }} on:change={handleCountryChange} aria-label="Select country" /> and have @@ -238,8 +278,8 @@

- {#each Object.values(countriesList) as name} - + {#each Object.entries(countriesList) as [code, name]} + {/each}
@@ -256,5 +296,5 @@
\ No newline at end of file