<template>
  <svg
    v-if="isSvg"
    v-bind="$attrs"
    class="svgicon"
    aria-hidden="true"
    v-on="$listeners"
  >
    <use :xlink:href="`#${value}`" />
  </svg>
  <svg
    v-else-if="ifEmsFont"
    v-bind="$attrs"
    class="svgicon"
    aria-hidden="true"
    v-on="$listeners"
  >
    <use :xlink:href="`#${value}`" />
  </svg>
  <Icon
    v-else
    v-bind="$attrs"
    :type="value"
    v-on="$listeners"
  />
</template>

<script>
export default {
  name: 'Vicon',
  props: {
    value: {
      type: String,
      default: ''
    }
  },
  data() {
    return {};
  },
  computed: {
    ifEmsFont() {
      const val = this.value || '';
      return val.indexOf('icon') === 0;
    },
    isSvg() {
      const val = this.value || '';
      return val.indexOf('svg') === 0;
    }
  }
};
</script>

<style lang="less" scoped>
.svgicon {
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
}
</style>
