77 lines
1.8 KiB
Vue
77 lines
1.8 KiB
Vue
<script setup lang="ts">
|
|||
|
|
import { computed } from 'vue';
|
||
|
|
import { getVuesaxSvg } from '@/icons/vuesax';
|
||
|
|
import { resolveVuesaxName } from '@/icons/name-map';
|
||
|
|
|
||
|
|
const props = withDefaults(
|
||
|
|
defineProps<{
|
||
|
|
/** کلید کوتاه vuesax (مثل add) یا نام UiIcon / Ant با map */
|
||
|
|
name: string;
|
||
|
|
size?: number | string;
|
||
|
|
/** منبع نگاشت نام؛ پیشفرض raw = کلید مستقیم پک */
|
||
|
|
map?: 'raw' | 'ui' | 'ant';
|
||
|
|
spin?: boolean;
|
||
|
|
title?: string;
|
||
|
|
}>(),
|
||
|
|
{
|
||
|
|
size: 20,
|
||
|
|
map: 'raw',
|
||
|
|
spin: false,
|
||
|
|
},
|
||
|
|
);
|
||
|
|
|
||
|
|
const resolved = computed(() => resolveVuesaxName(props.name, props.map));
|
||
|
|
|
||
|
|
const markup = computed(() => {
|
||
|
|
const svg = getVuesaxSvg(resolved.value);
|
||
|
|
if (!svg) return '';
|
||
|
|
// Strip fixed width/height so CSS size controls the box; keep viewBox.
|
||
|
|
return svg
|
||
|
|
.replace(/\swidth="[^"]*"/, '')
|
||
|
|
.replace(/\sheight="[^"]*"/, '')
|
||
|
|
.replace(
|
||
|
|
'<svg ',
|
||
|
|
`<svg width="${props.size}" height="${props.size}" style="width:${typeof props.size === 'number' ? props.size + 'px' : props.size};height:${typeof props.size === 'number' ? props.size + 'px' : props.size}" `,
|
||
|
|
);
|
||
|
|
});
|
||
|
|
</script>
|
||
|
|
|
||
|
|
<template>
|
||
|
|
<span
|
||
|
|
class="vs-icon"
|
||
|
|
:class="{ 'vs-icon--spin': spin }"
|
||
|
|
:style="{
|
||
|
|
width: typeof size === 'number' ? `${size}px` : size,
|
||
|
|
height: typeof size === 'number' ? `${size}px` : size,
|
||
|
|
}"
|
||
|
|
:title="title"
|
||
|
|
role="img"
|
||
|
|
aria-hidden="true"
|
||
|
|
v-html="markup"
|
||
|
|
/>
|
||
|
|
</template>
|
||
|
|
|
||
|
|
<style scoped>
|
||
|
|
.vs-icon {
|
||
|
|
display: inline-flex;
|
||
|
|
align-items: center;
|
||
|
|
justify-content: center;
|
||
|
|
line-height: 0;
|
||
|
|
flex-shrink: 0;
|
||
|
|
color: inherit;
|
||
|
|
}
|
||
|
|
.vs-icon :deep(svg) {
|
||
|
|
display: block;
|
||
|
|
width: 100%;
|
||
|
|
height: 100%;
|
||
|
|
}
|
||
|
|
.vs-icon--spin {
|
||
|
|
animation: vs-icon-spin 1s linear infinite;
|
||
|
|
}
|
||
|
|
@keyframes vs-icon-spin {
|
||
|
|
to {
|
||
|
|
transform: rotate(360deg);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
</style>
|