Add country dropdown and flags (#28)

* Add country dropdown and flags

* Fix build for country flags

* Improve country select filtering and scoreboard teams

* Fix country select display value

* Fix country select input display
This commit is contained in:
Pandipipas
2026-02-09 22:42:00 +01:00
committed by GitHub
parent 2dfd57786d
commit 547f9ab95f
7 changed files with 236 additions and 3 deletions
+49
View File
@@ -0,0 +1,49 @@
import { getData, type CountryRecord } from 'country-list';
export interface CountryOption {
value: string;
label: string;
}
const baseCountries = getData();
export const countryOptions: CountryOption[] = baseCountries
.map((country: CountryRecord) => ({
value: country.code,
label: country.name,
}))
.sort((a: CountryOption, b: CountryOption) => a.label.localeCompare(b.label));
const countryByCode = new Map(
countryOptions.map((country) => [country.value.toUpperCase(), country.label]),
);
const countryByName = new Map(
countryOptions.map((country) => [country.label.toLowerCase(), country.value]),
);
export const resolveCountryCode = (value?: string) => {
if (!value) {
return '';
}
const trimmed = value.trim();
if (!trimmed) {
return '';
}
const upper = trimmed.toUpperCase();
if (countryByCode.has(upper)) {
return upper;
}
const byName = countryByName.get(trimmed.toLowerCase());
return byName ?? '';
};
export const getCountryLabel = (value?: string) => {
if (!value) {
return '';
}
const resolved = resolveCountryCode(value);
if (!resolved) {
return value;
}
return countryByCode.get(resolved) ?? value;
};