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> <template>
<svg :style="svgStyle" class="svg-icon" aria-hidden="true"> <svg class="svg-icon" aria-hidden="true">
<use :xlink:href="symbolId" :fill="fill" /> <use :xlink:href="symbolId" :fill="fill" />
</svg> </svg>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { computed } from 'vue'; import { computed } from 'vue';
const props = defineProps({ interface Props {
prefix: { /** icon前缀 */
type: String, prefix?: string;
default: 'icon' /** icon 名称 */
}, name: string;
name: { /** 填充颜色 */
type: String, color?: string;
required: true
},
size: {
type: [String, Number],
default: 30
},
color: {
type: String,
default: ''
} }
}); const props = withDefaults(defineProps<Props>(), {
const svgStyle = computed(() => { prefix: 'icon',
const { size } = props; name: '',
let s = `${size}`; color: ''
s = `${s.replace('px', '')}px`;
return {
width: s,
height: s
};
}); });
const fill = computed(() => props.color || 'currentColor'); const fill = computed(() => props.color || 'currentColor');
const symbolId = computed(() => `#${props.prefix}-${props.name}`); const symbolId = computed(() => `#${props.prefix}-${props.name}`);
</script> </script>
<style scoped> <style scoped>
.svg-icon { .svg-icon {
width: 1em;
height: 1em;
vertical-align: -0.15em; vertical-align: -0.15em;
overflow: hidden; 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"> <div class="grid grid-cols-10">
<template v-for="item in svgIcons" :key="item"> <template v-for="item in svgIcons" :key="item">
<div class="mt-5px flex-x-center"> <div class="mt-5px flex-x-center">
<svg-icon :name="item" /> <svg-icon :name="item" class="text-30px" />
</div> </div>
</template> </template>
</div> </div>