Skip to content

Commit da2daa9

Browse files
committed
feat: AFCL CountryFlag gets size sm and md and a hairline ring instead of a blurred shadow, classes from the app merge with its own instead of clashing AdminForth/2005
1 parent b64504b commit da2daa9

3 files changed

Lines changed: 54 additions & 16 deletions

File tree

‎adminforth/design/system.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2477,7 +2477,7 @@ <h3 class="t-h3">Storage adapter</h3>
24772477
<span class="fl" role="img" aria-label="Ukraine" style="width: 32px; height: 24px; border-radius: 3px"><span style="background: #0057B7"></span><span style="background: #FFD700"></span></span>
24782478
<span class="fl" role="img" aria-label="Ukraine" style="width: 48px; height: 36px; border-radius: 4px"><span style="background: #0057B7"></span><span style="background: #FFD700"></span></span>
24792479
</div>
2480-
<div class="tile-cap"><b>Sizes</b><code>16 · 24 · 32 · 48</code></div>
2480+
<div class="tile-cap"><b>Sizes</b><code>size="sm" 16 · size="md" 32 · class for 24, 48</code></div>
24812481
</div>
24822482
<div class="tile">
24832483
<div class="tile-stage">

‎adminforth/spa/src/afcl/CountryFlag.vue‎

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,48 @@
11
<template>
2-
<div class="aspect-[4/3] w-8 h-6 flex items-center justify-center">
3-
<img v-if="flagUrl" :src="flagUrl" :alt="countryCode" class="flag-icon h-full object-contain rounded-sm"/>
2+
<span v-bind="restAttrs" :class="rootClasses">
3+
<!-- a hairline edge keeps white stripes visible on a white page -->
4+
<img
5+
v-if="flagUrl"
6+
:src="flagUrl"
7+
:alt="countryCode"
8+
class="block w-full h-full object-cover ring-1 ring-black/10 dark:ring-white/10"
9+
:class="IMAGE_RADIUS[size]"
10+
/>
411
<span v-else-if="getFlagUrl && countryCode">{{ countryCode }}</span>
5-
</div>
12+
</span>
613
</template>
714

815
<script setup lang="ts">
9-
import { computed, shallowRef } from 'vue';
16+
import { computed, shallowRef, useAttrs } from 'vue';
17+
import { type ClassNameValue } from 'tailwind-merge';
18+
import { mergeClasses } from './classMerge';
1019
11-
const props = defineProps(['countryCode']);
20+
type CountryFlagSize = 'sm' | 'md';
21+
22+
defineOptions({ inheritAttrs: false });
23+
24+
const props = withDefaults(defineProps<{
25+
countryCode?: string,
26+
// sm is 16×12 for menus, lists and selects, md is 32×24
27+
size?: CountryFlagSize,
28+
}>(), {
29+
size: 'md',
30+
});
31+
32+
const SIZES: Record<CountryFlagSize, string> = { sm: 'w-4 h-3', md: 'w-8 h-6' };
33+
const IMAGE_RADIUS: Record<CountryFlagSize, string> = { sm: 'rounded-[2px]', md: 'rounded-[3px]' };
34+
35+
const attrs = useAttrs();
36+
const restAttrs = computed(() => {
37+
const { class: _class, ...rest } = attrs;
38+
return rest;
39+
});
40+
41+
const rootClasses = computed(() => mergeClasses(
42+
'afcl-country-flag inline-flex shrink-0 items-center justify-center',
43+
SIZES[props.size],
44+
attrs.class as ClassNameValue,
45+
));
1246
1347
// the map of flag URLs is loaded when a flag is shown for the first time
1448
const getFlagUrl = shallowRef<(countryCode: string) => string | undefined>();
@@ -18,12 +52,3 @@ import('./countryFlagUrls').then((module) => {
1852
1953
const flagUrl = computed(() => props.countryCode && getFlagUrl.value?.(props.countryCode));
2054
</script>
21-
22-
<style scoped>
23-
.flag-icon {
24-
box-shadow: inset -0.3px -0.3px 0.3px 0px rgba(0 0 0 / 0.2),
25-
inset 0.3px 0.3px 0.3px 0px rgba(255 255 255 / 0.2),
26-
0px 0px 3px #00000030;
27-
width: auto;
28-
}
29-
</style>

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1738,7 +1738,7 @@ import { Spinner } from '@/afcl'
17381738

17391739
## Country Flag
17401740

1741-
The Country Flag component displays national flags using ISO 3166-1 alpha-2 country codes.
1741+
The Country Flag component displays national flags using ISO 3166-1 alpha-2 country codes. A flag has a hairline edge, so white stripes stay visible on a white page. Only the SVG of a shown flag is downloaded.
17421742

17431743
<AfclPreview id="country-flag">
17441744

@@ -1752,6 +1752,19 @@ import { CountryFlag } from '@/afcl'
17521752

17531753
</AfclPreview>
17541754

1755+
`size` is `md` (default, 32×24) or `sm` (16×12) for menus, selects and lists:
1756+
1757+
<AfclPreview id="country-flag-sizes">
1758+
1759+
```html
1760+
<div class="flex items-center gap-4">
1761+
<span class="flex items-center gap-2 text-sm"><CountryFlag countryCode="jp" size="sm" />日本語</span>
1762+
<CountryFlag countryCode="jp" />
1763+
</div>
1764+
```
1765+
1766+
</AfclPreview>
1767+
17551768
## Bar Chart
17561769

17571770
Under the hood AdminForth uses MIT-licensed [ApexCharts](https://apexcharts.com/). It has very rich variety of options, you can pass

0 commit comments

Comments
 (0)