index.vue 766 Bytes
<template>
  <svg aria-hidden="true"
       class="svg-icon"
       :style="iconStyle">
    <use :xlink:href="iconName" />
  </svg>
</template>

<script>
export default {
	name: "SvgIcon",
	props: {
		name: {
			type: String,
			required: true,
		},
		size: {
			type: [String, Number],
			default: "1em",
		},
		color: {
			type: String,
			default: "#000",
		},
	},
	computed: {
		iconName() {
			return `#icon-${this.name}`;
		},
		iconStyle() {
			const size = typeof this.size === "number" ? `${this.size}px` : this.size;
			return {
				width: size,
				height: size,
				fill: this.color,
				color: this.color,
			};
		},
	},
};
</script>

<style lang="scss" scoped>
.svg-icon {
	display: inline-block;
	vertical-align: middle;
	overflow: hidden;
}
</style>