Files
boursecu_user/src/components/BasicPacks/BasicIcon.vue
T

57 lines
1.3 KiB
Vue
Raw Normal View History

2026-01-18 13:01:46 +03:30
<template>
<span
ref="refIcon"
:style="{ color }"
:class="[prefixCls]"
class="!flex"
v-html="tempIcon"
></span>
</template>
<script lang="ts" setup>
import icons from '@/components/BasicPacks/tools/icons/icons.json'
import {usePrefix} from "@/utils/usePrefix";
2026-06-01 09:48:39 +03:30
import {resolveProjectColor} from "@/utils/config";
2026-01-18 13:01:46 +03:30
import {computed, onMounted, ref, withDefaults, defineProps} from "vue";
interface Props {
icon: string
color?: string | null
size?: string | number
strokeWidth?:string | number
}
const props = withDefaults(defineProps<Props>(), {
color: null,
})
const { prefixCls } = usePrefix('icons')
const tempIcon = ref<string>()
const refIcon = ref<HTMLDivElement>()
tempIcon.value = icons[`${props.icon}`] as string
const color = computed(() => {
2026-06-01 09:48:39 +03:30
return resolveProjectColor(props.color)
2026-01-18 13:01:46 +03:30
})
onMounted(() => {
if (props.size && refIcon.value) {
const svg = refIcon.value.children?.[0] as SVGElement | undefined
if (svg && typeof svg.setAttribute === 'function') {
svg.setAttribute('width', String(props.size))
svg.setAttribute('height', String(props.size))
}
2026-01-18 13:01:46 +03:30
}
})
</script>
<style lang="less" scoped>
@prefix: ~'@{prefixCls}-icons';
.@{prefix} {
& :deep(svg path) {
stroke: currentColor;
stroke-width: v-bind("props.strokeWidth");
}
}
</style>