Skip to content

Commit ce254c9

Browse files
committed
feat: Add country flag to adminforth components library
1 parent 722c072 commit ce254c9

File tree

7 files changed

+61
-25
lines changed

7 files changed

+61
-25
lines changed

adminforth/documentation/docs/tutorial/03-Customization/15-afcl.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,22 @@ Spinner component is used to display a loading state for a component.
861861
</div>
862862
</div>
863863

864+
## Country Flag
865+
866+
The Country Flag component displays national flags using ISO 3166-1 alpha-2 country codes.
867+
868+
<div class="split-screen" >
869+
<div>
870+
```html
871+
<CountryFlag countryCode="ua" />
872+
```
873+
</div>
874+
<div>
875+
![Country Flag](image-92.png)
876+
</div>
877+
</div>
878+
879+
864880
## Bar Chart
865881

866882
Under the hood AdminForth uses MIT-licensed [ApexCharts](https://apexcharts.com/). It has very rich variety of options, you can pass
@@ -1454,7 +1470,7 @@ import { PieChart } from '@/afcl'
14541470
//diff-add
14551471
offset: -10, // Moves labels closer to or further from the slices
14561472
//diff-add
1457-
minAngleToShowLabel: 10, // Ensures that small slices dont show labels
1473+
minAngleToShowLabel: 10, // Ensures that small slices don't show labels
14581474
//diff-add
14591475
},
14601476
//diff-add
@@ -1686,7 +1702,3 @@ import { MixedChart } from '@/afcl'
16861702
</div>
16871703
</div>
16881704

1689-
1690-
1691-
1692-
2.46 KB
Loading

adminforth/spa/package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adminforth/spa/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"i18n:extract": "echo '{}' > i18n-empty.json && vue-i18n-extract report --vueFiles './src/**/*.?(js|vue)' --output ./i18n-messages.json --languageFiles 'i18n-empty.json' --add"
1414
},
1515
"dependencies": {
16+
"@iconify-prerendered/vue-flag": "^0.28.1748584105",
1617
"@iconify-prerendered/vue-flowbite": "^0.23.1714023977",
1718
"@unhead/vue": "^1.9.12",
1819
"@vueuse/core": "^10.10.0",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<template>
2+
<component v-if="getFlagComponent(countryCode)" class="flag-icon rounded-sm" :is="getFlagComponent(countryCode)" />
3+
<span v-else-if="countryCode">{{ countryCode }}</span>
4+
</template>
5+
6+
<script setup lang="ts">
7+
import * as FlagIcons from '@iconify-prerendered/vue-flag';
8+
9+
defineProps(['countryCode']);
10+
11+
const getFlagComponent = (countryCode: string) => {
12+
if (!countryCode) return null;
13+
14+
const normalizedCode = countryCode.charAt(0).toUpperCase() + countryCode.slice(1).toLowerCase();
15+
const iconName = `Icon${normalizedCode}4x3`; // 4:3 aspect ratio flags
16+
return FlagIcons[iconName as keyof typeof FlagIcons] || null;
17+
};
18+
</script>
19+
20+
<style scoped>
21+
.flag-icon {
22+
box-shadow: inset -0.3px -0.3px 0.3px 0px rgba(0 0 0 / 0.2),
23+
inset 0.3px 0.3px 0.3px 0px rgba(255 255 255 / 0.2),
24+
0px 0px 3px #00000030;
25+
}
26+
</style>

adminforth/spa/src/afcl/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ export { default as Spinner } from './Spinner.vue';
1818
export { default as Skeleton } from './Skeleton.vue';
1919
export { default as Dialog } from './Dialog.vue';
2020
export { default as MixedChart } from './MixedChart.vue';
21+
export { default as CountryFlag } from './CountryFlag.vue';
22+
2123

2224

adminforth/spa/src/renderers/CountryFlag.vue

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<template>
22
<Tooltip>
33
<span class="flex items-center">
4-
<span
5-
:class="{[`fi-${countryIsoLow}`]: true, 'flag-icon': countryName}"
6-
></span>
4+
<CountryFlag class="w-[1.6rem] h-[1.2rem]" :countryCode="countryIsoLow" />
75
<span v-if="meta.showCountryName" class="ms-2">{{ countryName }}</span>
86
</span>
97

@@ -16,10 +14,10 @@
1614
<script setup>
1715
1816
import { computed, ref, onMounted } from 'vue';
19-
import 'flag-icons/css/flag-icons.min.css';
2017
import isoCountries from 'i18n-iso-countries';
2118
import enLocal from 'i18n-iso-countries/langs/en.json';
2219
import Tooltip from '@/afcl/Tooltip.vue';
20+
import CountryFlag from '@/afcl/CountryFlag.vue';
2321
2422
isoCountries.registerLocale(enLocal);
2523
@@ -47,19 +45,3 @@ const countryName = computed(() => {
4745
});
4846
4947
</script>
50-
51-
<style scoped lang="scss">
52-
53-
.flag-icon {
54-
width: 1.6rem;
55-
height: 1.2rem;
56-
flex-shrink: 0;
57-
58-
// border radius for background
59-
border-radius: 2px;
60-
box-shadow: inset -0.3px -0.3px 0.3px 0px rgba(0 0 0 / 0.2),
61-
inset 0.3px 0.3px 0.3px 0px rgba(255 255 255 / 0.2),
62-
0px 0px 3px #00000030;
63-
}
64-
65-
</style>

0 commit comments

Comments
 (0)