<!--
 * @Author: ChileeHong
 * @Date: 2021-01-25 10:02:01
 * @LastEditors: Billy
 * @LastEditTime: 2021-09-23 01:06:15
 * @Description: icon-class必填，是icons/svg下面的文件名，注意不要带后缀.svg
-->

<!--
参考：
https://www.jianshu.com/p/70f9c9268c83
https://segmentfault.com/a/1190000015367490
-->

<template>
  <svg
    :class="svgClass"
    :style="iconStyle"
    aria-hidden="true"
    v-on="$listeners"
  >
    <use :xlink:href="iconName" />
  </svg>
</template>

<script>
export default {
  name: "SvgIcon",
  props: {
    iconClass: {
      type: String,
      required: true,
    },
    iconStyle: {
      type: [String, Object],
    },
    className: {
      type: String,
    },
  },
  computed: {
    iconName() {
      return `#icon-${this.iconClass}`;
    },
    svgClass() {
      if (this.className) return `svg-icon ${this.className}`;
      else return "svg-icon";
    },
  },
};
</script>

<style scoped>
.svg-icon {
  width: 1em;
  height: 1em;
  vertical-align: top;
  fill: currentColor;
  overflow: hidden;
}

.svg-external-icon {
  background-color: currentColor;
  mask-size: cover !important;
  display: inline-block;
}
</style>
