Add flags
This commit is contained in:
+49
-9
@@ -16,6 +16,9 @@
|
|||||||
let daysOff = ptoData['BE'];
|
let daysOff = ptoData['BE'];
|
||||||
let optimizedDaysOff = [];
|
let optimizedDaysOff = [];
|
||||||
let consecutiveDaysOff = [];
|
let consecutiveDaysOff = [];
|
||||||
|
let placeholder = "Country";
|
||||||
|
let isFirstClick = true;
|
||||||
|
let inputElement;
|
||||||
|
|
||||||
function handleYearChange(event) {
|
function handleYearChange(event) {
|
||||||
year = parseInt(event.target.value);
|
year = parseInt(event.target.value);
|
||||||
@@ -23,13 +26,25 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleCountryChange(event) {
|
function handleCountryChange(event) {
|
||||||
const countryName = event.target.value;
|
const fullValue = event.target.value;
|
||||||
const countryCode = Object.keys(countriesList).find(code => countriesList[code] === countryName);
|
const countryCode = Object.keys(countriesList).find(code => countriesList[code] === fullValue);
|
||||||
if (countryCode) {
|
if (countryCode) {
|
||||||
selectedCountry = countryName;
|
selectedCountry = fullValue;
|
||||||
daysOff = ptoData[countryCode] || 0;
|
daysOff = ptoData[countryCode] || 0;
|
||||||
updateHolidays();
|
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() {
|
function updateHolidays() {
|
||||||
@@ -68,11 +83,23 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getFlagEmoji(countryCode) {
|
||||||
|
return countryCode
|
||||||
|
.toUpperCase()
|
||||||
|
.replace(/./g, char => String.fromCodePoint(127397 + char.charCodeAt()));
|
||||||
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
window.addEventListener('keydown', handleKeyDown);
|
window.addEventListener('keydown', handleKeyDown);
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener('keydown', handleKeyDown);
|
window.removeEventListener('keydown', handleKeyDown);
|
||||||
};
|
};
|
||||||
|
adjustInputWidth(inputElement);
|
||||||
|
inputElement.addEventListener('input', () => adjustInputWidth(inputElement));
|
||||||
|
inputElement.addEventListener('focus', () => {
|
||||||
|
inputElement.value = '';
|
||||||
|
adjustInputWidth(inputElement);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
updateHolidays();
|
updateHolidays();
|
||||||
@@ -171,10 +198,18 @@
|
|||||||
color: inherit;
|
color: inherit;
|
||||||
font-size: inherit;
|
font-size: inherit;
|
||||||
font-family: inherit;
|
font-family: inherit;
|
||||||
width: auto;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
margin: 0 10px;
|
margin: 0 10px;
|
||||||
outline: none;
|
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 {
|
.arrow-controls {
|
||||||
@@ -213,17 +248,22 @@
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
font-size: 1.2em;
|
font-size: 1.2em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.flag {
|
||||||
|
font-size: 2em; /* Adjust the size as needed */
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<header>
|
<header>
|
||||||
<h1>Stretch My Holidays</h1>
|
<h1>Stretch My Time Off</h1>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
<div class="content-box">
|
<div class="content-box">
|
||||||
<p>
|
<p>
|
||||||
I live in
|
I live in
|
||||||
<input list="countries" class="editable-input bold" bind:value={selectedCountry} on:change={handleCountryChange} aria-label="Select country" />
|
<span class="flag">{getFlagEmoji(Object.keys(countriesList).find(code => countriesList[code] === selectedCountry))}</span>
|
||||||
|
<input bind:this={inputElement} list="countries" class="editable-input bold" bind:value={selectedCountry} placeholder={placeholder} on:input={adjustInputWidth} on:focus={() => { inputElement.value = ''; adjustInputWidth(); }} on:change={handleCountryChange} aria-label="Select country" />
|
||||||
and have
|
and have
|
||||||
<span class="arrow-controls">
|
<span class="arrow-controls">
|
||||||
<button on:click={() => { daysOff++; updateHolidays(); }} aria-label="Increase days off">▲</button>
|
<button on:click={() => { daysOff++; updateHolidays(); }} aria-label="Increase days off">▲</button>
|
||||||
@@ -238,8 +278,8 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<datalist id="countries">
|
<datalist id="countries">
|
||||||
{#each Object.values(countriesList) as name}
|
{#each Object.entries(countriesList) as [code, name]}
|
||||||
<option value={name}></option>
|
<option value={name}>{name}</option>
|
||||||
{/each}
|
{/each}
|
||||||
</datalist>
|
</datalist>
|
||||||
</div>
|
</div>
|
||||||
@@ -256,5 +296,5 @@
|
|||||||
</main>
|
</main>
|
||||||
|
|
||||||
<footer>
|
<footer>
|
||||||
<p>© 2023 Stretch My Holidays. All rights reserved.</p>
|
<p>© { new Date().getFullYear() } Stretch My Time Off. All rights reserved.</p>
|
||||||
</footer>
|
</footer>
|
||||||
Reference in New Issue
Block a user