Merge pull request #51 from Lsq128/main

feat(components): svgIcon,添加type,调整size方案
This commit is contained in:
Soybean 2022-02-27 08:45:59 +08:00 committed by GitHub
commit f92d7ecfbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 35 deletions

View File

@ -1,43 +1,31 @@
<template>
<svg :style="svgStyle" class="svg-icon" aria-hidden="true">
<svg class="svg-icon" aria-hidden="true">
<use :xlink:href="symbolId" :fill="fill" />
</svg>
</template>
<script setup lang="ts">
import { computed } from 'vue';
const props = defineProps({
prefix: {
type: String,
default: 'icon'
},
name: {
type: String,
required: true
},
size: {
type: [String, Number],
default: 30
},
color: {
type: String,
default: ''
}
});
const svgStyle = computed(() => {
const { size } = props;
let s = `${size}`;
s = `${s.replace('px', '')}px`;
return {
width: s,
height: s
};
interface Props {
/** icon前缀 */
prefix?: string;
/** icon 名称 */
name: string;
/** 填充颜色 */
color?: string;
}
const props = withDefaults(defineProps<Props>(), {
prefix: 'icon',
name: '',
color: ''
});
const fill = computed(() => props.color || 'currentColor');
const symbolId = computed(() => `#${props.prefix}-${props.name}`);
</script>
<style scoped>
.svg-icon {
width: 1em;
height: 1em;
vertical-align: -0.15em;
overflow: hidden;
}

View File

@ -1,7 +0,0 @@
import type { App } from 'vue';
import { SvgIcon } from '@/components';
/** 注册全局svg-icon组件 */
export default function setupNaiveUI(app: App) {
app.component('SvgIcon', SvgIcon);
}

View File

@ -20,7 +20,7 @@
<div class="grid grid-cols-10">
<template v-for="item in svgIcons" :key="item">
<div class="mt-5px flex-x-center">
<svg-icon :name="item" />
<svg-icon :name="item" class="text-30px" />
</div>
</template>
</div>