mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-09-09 09:28:21 +00:00
feat: add NATIONALITY and NATION field types with dedicated country-picker logic and storage conversion
This commit is contained in:
@@ -5,6 +5,7 @@ import { registerLocale, getNames, getName, getAlpha2Code } from 'i18n-iso-count
|
||||
import {
|
||||
registerLocale as registerNationalityLocale,
|
||||
getName as getNationalityNameRaw,
|
||||
getAlpha2Code as getNationalityAlpha2Code,
|
||||
} from 'i18n-nationality';
|
||||
import * as Flags from 'country-flag-icons/react/3x2';
|
||||
import en from 'i18n-iso-countries/langs/en.json';
|
||||
@@ -44,6 +45,17 @@ export function getNationalityName(code: string | null | undefined, lang: Countr
|
||||
return getCountryName(code, lang);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alpha-2 code for a stored demonym (e.g. "Ethiopian" -> "ET"), the reverse of
|
||||
* `getNationalityName`. Falls back to the country-name lookup so a field that
|
||||
* happens to hold "Ethiopia" still resolves.
|
||||
*/
|
||||
export function getNationalityCode(name: string | null | undefined, lang: CountryLang = 'en'): string | undefined {
|
||||
if (!name) return undefined;
|
||||
const demonymCode = lang === 'en' ? getNationalityAlpha2Code(name, 'en') : undefined;
|
||||
return demonymCode || getCountryCode(name, lang);
|
||||
}
|
||||
|
||||
export function CountryFlag({ code }: { code: string }) {
|
||||
const Flag = Flags[code as keyof typeof Flags];
|
||||
return Flag ? <Flag style={{ width: 22, borderRadius: 2, display: 'block' }} /> : null;
|
||||
|
||||
Reference in New Issue
Block a user