From 1d24f912aeb2e472e2ccbd040bd8e4cea1b23b67 Mon Sep 17 00:00:00 2001 From: louis-19041904 Date: Mon, 3 Aug 2026 21:17:02 +0200 Subject: [PATCH] add country-flag component --- .../country-flag/country-flag.component.html | 9 ++++++ .../country-flag/country-flag.component.scss | 12 ++++++++ .../ui/country-flag/country-flag.component.ts | 29 +++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 webapp/src/app/shared/ui/country-flag/country-flag.component.html create mode 100644 webapp/src/app/shared/ui/country-flag/country-flag.component.scss create mode 100644 webapp/src/app/shared/ui/country-flag/country-flag.component.ts diff --git a/webapp/src/app/shared/ui/country-flag/country-flag.component.html b/webapp/src/app/shared/ui/country-flag/country-flag.component.html new file mode 100644 index 00000000..6d7a322a --- /dev/null +++ b/webapp/src/app/shared/ui/country-flag/country-flag.component.html @@ -0,0 +1,9 @@ +@if (flagUrl(); as url) { + +} diff --git a/webapp/src/app/shared/ui/country-flag/country-flag.component.scss b/webapp/src/app/shared/ui/country-flag/country-flag.component.scss new file mode 100644 index 00000000..816e2013 --- /dev/null +++ b/webapp/src/app/shared/ui/country-flag/country-flag.component.scss @@ -0,0 +1,12 @@ +.country-flag-img { + display: inline-block; + vertical-align: middle; + + &--bordered { + border: 1px solid var(--sg-border); + } + + &--rounded { + border-radius: 2px; + } +} diff --git a/webapp/src/app/shared/ui/country-flag/country-flag.component.ts b/webapp/src/app/shared/ui/country-flag/country-flag.component.ts new file mode 100644 index 00000000..7d2acbe7 --- /dev/null +++ b/webapp/src/app/shared/ui/country-flag/country-flag.component.ts @@ -0,0 +1,29 @@ +import { Component, computed, input } from '@angular/core'; + +const COUNTRY_CODE_ALIASES: Record = { + uk: 'gb', +}; + +@Component({ + selector: 'app-country-flag', + standalone: true, + templateUrl: './country-flag.component.html', + styleUrl: './country-flag.component.scss', +}) +export class CountryFlagComponent { + readonly countryCode = input(null); + readonly height = input(12); + readonly bordered = input(true); + readonly rounded = input(false); + + readonly normalizedCode = computed(() => { + const code = this.countryCode()?.trim().toLowerCase(); + if (!code) return null; + return COUNTRY_CODE_ALIASES[code] ?? code; + }); + + readonly flagUrl = computed(() => { + const code = this.normalizedCode(); + return code ? `https://flagcdn.io/${code}.svg` : null; + }); +}