Skip to content

Commit

Permalink
精简 SvgIcon 组件配置
Browse files Browse the repository at this point in the history
  • Loading branch information
hooray committed Jan 24, 2025
1 parent 40b4178 commit 35086fc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 34 deletions.
37 changes: 4 additions & 33 deletions src/components/SvgIcon/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ defineOptions({
const props = defineProps<{
name: string
flip?: 'horizontal' | 'vertical' | 'both'
rotate?: number
color?: string
size?: string | number
}>()
const outputType = computed(() => {
Expand All @@ -24,38 +20,13 @@ const outputType = computed(() => {
return 'svg'
}
})
const style = computed(() => {
const transform = []
if (props.flip) {
switch (props.flip) {
case 'horizontal':
transform.push('rotateY(180deg)')
break
case 'vertical':
transform.push('rotateX(180deg)')
break
case 'both':
transform.push('rotateX(180deg)')
transform.push('rotateY(180deg)')
break
}
}
if (props.rotate) {
transform.push(`rotate(${props.rotate % 360}deg)`)
}
return {
...(props.color && { color: props.color }),
...(props.size && { fontSize: typeof props.size === 'number' ? `${props.size}px` : props.size }),
...(transform.length && { transform: transform.join(' ') }),
}
})
</script>

<template>
<i class="relative h-[1em] w-[1em] flex-inline items-center justify-center fill-current leading-[1em]" :class="{ [name]: outputType === 'unocss' }" :style="style">
<Icon v-if="outputType === 'iconify'" :icon="name" />
<svg v-else-if="outputType === 'svg'" class="h-[1em] w-[1em]" aria-hidden="true">
<i class="relative size-[1em] flex-inline items-center justify-center fill-current leading-[1em]">
<i v-if="outputType === 'unocss'" class="size-inherit shrink-0" :class="name" />
<Icon v-else-if="outputType === 'iconify'" :icon="name" class="shrink-0 size-inherit!" />
<svg v-else-if="outputType === 'svg'" class="size-inherit shrink-0" aria-hidden="true">
<use :xlink:href="`#icon-${name}`" />
</svg>
</i>
Expand Down
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export default defineConfig(({ mode, command }) => {
}
})
return {
base: './',
// 开发服务器选项 https://cn.vitejs.dev/config/server-options
server: {
open: true,
host: true,
proxy: {
'/proxy': {
target: env.VITE_APP_API_BASEURL,
Expand Down

0 comments on commit 35086fc

Please sign in to comment.