2025-08-07 19:20:29 +02:00
|
|
|
|
<template>
|
|
|
|
|
|
<span class="country-flag" :class="{ 'country-flag--small': size === 'small' }">
|
2025-08-07 21:22:01 +02:00
|
|
|
|
<ClientOnly>
|
|
|
|
|
|
<VueCountryFlag
|
2025-08-07 21:30:47 +02:00
|
|
|
|
v-if="actualCountryCode"
|
|
|
|
|
|
:country="actualCountryCode"
|
2025-08-07 21:22:01 +02:00
|
|
|
|
:size="flagSize"
|
2025-08-07 21:30:47 +02:00
|
|
|
|
:title="getCountryName(actualCountryCode)"
|
2025-08-07 21:22:01 +02:00
|
|
|
|
/>
|
|
|
|
|
|
<template #fallback>
|
|
|
|
|
|
<span class="flag-placeholder" :style="placeholderStyle">🏳️</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</ClientOnly>
|
2025-08-07 21:30:47 +02:00
|
|
|
|
<span v-if="showName && actualCountryCode" class="country-name">
|
|
|
|
|
|
{{ getCountryName(actualCountryCode) }}
|
2025-08-07 19:20:29 +02:00
|
|
|
|
</span>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2025-08-07 21:22:01 +02:00
|
|
|
|
import VueCountryFlag from 'vue-country-flag-next';
|
2025-08-07 21:30:47 +02:00
|
|
|
|
import { getCountryName, parseCountryInput } from '~/utils/countries';
|
2025-08-07 19:20:29 +02:00
|
|
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
|
|
countryCode?: string;
|
|
|
|
|
|
showName?: boolean;
|
|
|
|
|
|
size?: 'small' | 'medium' | 'large';
|
|
|
|
|
|
square?: boolean;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const props = withDefaults(defineProps<Props>(), {
|
|
|
|
|
|
countryCode: '',
|
|
|
|
|
|
showName: true,
|
|
|
|
|
|
size: 'medium',
|
|
|
|
|
|
square: false
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-08-07 21:30:47 +02:00
|
|
|
|
// Convert country name to country code if needed
|
|
|
|
|
|
const actualCountryCode = computed(() => {
|
|
|
|
|
|
if (!props.countryCode) return '';
|
|
|
|
|
|
|
|
|
|
|
|
// If it's already a 2-letter code, use it
|
|
|
|
|
|
if (props.countryCode.length === 2) {
|
|
|
|
|
|
return props.countryCode.toUpperCase();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Try to parse country name to get the code
|
|
|
|
|
|
const parsed = parseCountryInput(props.countryCode);
|
|
|
|
|
|
return parsed || '';
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-08-07 21:09:00 +02:00
|
|
|
|
const flagSize = computed(() => {
|
2025-08-07 19:20:29 +02:00
|
|
|
|
const sizeMap = {
|
2025-08-07 21:09:00 +02:00
|
|
|
|
small: 'sm',
|
|
|
|
|
|
medium: 'md',
|
|
|
|
|
|
large: 'lg'
|
2025-08-07 19:20:29 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-08-07 21:09:00 +02:00
|
|
|
|
return sizeMap[props.size];
|
2025-08-07 19:20:29 +02:00
|
|
|
|
});
|
2025-08-07 21:22:01 +02:00
|
|
|
|
|
|
|
|
|
|
const placeholderStyle = computed(() => {
|
|
|
|
|
|
const sizeMap = {
|
|
|
|
|
|
small: '1rem',
|
|
|
|
|
|
medium: '1.5rem',
|
|
|
|
|
|
large: '2rem'
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
width: sizeMap[props.size],
|
|
|
|
|
|
height: props.square ? sizeMap[props.size] : `calc(${sizeMap[props.size]} * 0.75)`,
|
|
|
|
|
|
display: 'inline-flex',
|
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
|
borderRadius: '2px',
|
|
|
|
|
|
backgroundColor: '#f5f5f5',
|
|
|
|
|
|
fontSize: '0.75rem'
|
|
|
|
|
|
};
|
|
|
|
|
|
});
|
2025-08-07 19:20:29 +02:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.country-flag {
|
|
|
|
|
|
display: inline-flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
gap: 0.5rem;
|
|
|
|
|
|
vertical-align: middle;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.country-flag--small {
|
|
|
|
|
|
gap: 0.25rem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.country-name {
|
|
|
|
|
|
font-size: 0.875rem;
|
|
|
|
|
|
color: inherit;
|
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.country-flag--small .country-name {
|
|
|
|
|
|
font-size: 0.75rem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-07 21:22:01 +02:00
|
|
|
|
.flag-placeholder {
|
|
|
|
|
|
border-radius: 2px;
|
|
|
|
|
|
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
|
|
|
|
|
|
flex-shrink: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-07 19:20:29 +02:00
|
|
|
|
/* Ensure proper flag display */
|
2025-08-07 21:09:00 +02:00
|
|
|
|
:deep(.vue-country-flag) {
|
|
|
|
|
|
border-radius: 2px;
|
2025-08-07 19:20:29 +02:00
|
|
|
|
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
|
2025-08-07 21:09:00 +02:00
|
|
|
|
flex-shrink: 0;
|
2025-08-07 19:20:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
</style>
|