CMVR-IOT-UI/src/components/SvgIcon/index.vue

60 lines
1.1 KiB
Vue
Raw Normal View History

2025-08-21 14:11:58 +08:00
<template>
2026-05-25 09:10:10 +08:00
<svg
2026-07-28 16:26:07 +08:00
:class="svgClass"
:width="resolvedSize"
:height="resolvedSize"
2026-05-25 09:10:10 +08:00
:style="svgStyle"
aria-hidden="true"
>
2026-07-28 16:26:07 +08:00
<use :xlink:href="symbolId" :fill="color || 'currentColor'" />
2025-08-21 14:11:58 +08:00
</svg>
</template>
2026-05-25 09:10:10 +08:00
<script setup>
const props = defineProps({
2026-07-28 16:26:07 +08:00
iconClass: {
type: String,
default: ''
},
2026-05-25 09:10:10 +08:00
name: {
type: String,
2026-07-28 16:26:07 +08:00
default: ''
},
className: {
type: String,
default: ''
2026-05-25 09:10:10 +08:00
},
size: {
type: [String, Number],
2026-07-28 16:26:07 +08:00
default: undefined
2026-05-25 09:10:10 +08:00
},
color: {
type: String,
2026-07-28 16:26:07 +08:00
default: ''
2025-08-21 14:11:58 +08:00
},
2026-05-25 09:10:10 +08:00
customStyle: {
type: Object,
default: () => ({})
2025-08-21 14:11:58 +08:00
}
})
2026-07-28 16:26:07 +08:00
const icon = computed(() => props.name || props.iconClass)
const symbolId = computed(() => `#icon-${icon.value}`)
const resolvedSize = computed(() => props.size ?? (props.name ? 24 : undefined))
const svgClass = computed(() => props.className ? `svg-icon ${props.className}` : 'svg-icon')
2026-05-25 09:10:10 +08:00
const svgStyle = computed(() => ({
2026-07-28 16:26:07 +08:00
color: props.color || undefined,
2026-05-25 09:10:10 +08:00
...props.customStyle
}))
</script>
2026-07-28 16:26:07 +08:00
<style scoped>
.svg-icon {
width: 1em;
height: 1em;
vertical-align: -0.15em;
fill: currentColor;
overflow: hidden;
}
</style>