add country-flag component

This commit is contained in:
2026-08-03 21:17:02 +02:00
parent f9591c512c
commit 1d24f912ae
3 changed files with 50 additions and 0 deletions
@@ -0,0 +1,9 @@
@if (flagUrl(); as url) {
<img
alt=""
class="country-flag-img"
[class.country-flag-img--bordered]="bordered()"
[class.country-flag-img--rounded]="rounded()"
[src]="url"
[style.height.px]="height()" />
}
@@ -0,0 +1,12 @@
.country-flag-img {
display: inline-block;
vertical-align: middle;
&--bordered {
border: 1px solid var(--sg-border);
}
&--rounded {
border-radius: 2px;
}
}
@@ -0,0 +1,29 @@
import { Component, computed, input } from '@angular/core';
const COUNTRY_CODE_ALIASES: Record<string, string> = {
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<string | null | undefined>(null);
readonly height = input<number>(12);
readonly bordered = input<boolean>(true);
readonly rounded = input<boolean>(false);
readonly normalizedCode = computed<string | null>(() => {
const code = this.countryCode()?.trim().toLowerCase();
if (!code) return null;
return COUNTRY_CODE_ALIASES[code] ?? code;
});
readonly flagUrl = computed<string | null>(() => {
const code = this.normalizedCode();
return code ? `https://flagcdn.io/${code}.svg` : null;
});
}