forked from Easterok/telegram-onboarding-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Icon.vue
59 lines (46 loc) · 1.33 KB
/
Icon.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<template>
<svg-icon v-bind="props" :name="onlyName">
<component
v-if="onlyLoader"
:is="onlyLoader"
tabindex="-1"
focusable="false"
aria-hidden="true"
width="100%"
height="100%"
/>
</svg-icon>
</template>
<script setup lang="ts">
import { useI18n } from '@tok/i18n';
import { SvgIcon } from '@tok/ui/components/SvgIcon';
import { computed, defineAsyncComponent, toRefs } from 'vue';
import { _MediaLoader, IconPresetProps } from './Media.preset.props';
const props = withDefaults(defineProps<IconPresetProps>(), {
src: '',
webp: '',
});
const { src } = toRefs(props);
const srcProbablyTranslated = computed(() => {
return src.value && typeof src.value === 'string' ? src.value : '';
});
const i18n = useI18n();
const translatedSrc = i18n.useTranslated<
string | _MediaLoader<{ render: () => void }>
>(srcProbablyTranslated);
const onlyLoader = computed(() => {
const value = translatedSrc.value;
if (typeof value === 'object' && 'then' in value) {
return defineAsyncComponent(() => value);
}
const _src = src.value;
if (typeof _src === 'object' && 'then' in _src) {
return defineAsyncComponent(() => _src);
}
return null;
});
const onlyName = computed(() => {
const value = translatedSrc.value;
return typeof value === 'string' ? value : '';
});
</script>