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

<script>
export default {
  name: 'SvgSon',
  inheritAttrs: false,
  props: {
    disabled: {
      type: Boolean,
      default: false
    },
    color: {
      type: String
    },
    size: {
      type: [String, Number]
    },
    iconClass: {
      type: String,
      required: true
    },
    className: {
      type: String,
      default: ''
    },
    width: {
      type: Number,
      default: 1
    },
    height: {
      type: Number,
      default: 1
    }
  },
  computed: {
    iconName () {
      return `#icon-${this.iconClass}`
    },
    iconSize() {
      const { width, height, size, color, disabled } = this
      return {width: width + 'em', height: height + 'em', fontSize: isNaN(size) ? size : size + 'px', color: disabled ? '#ccc' : color}
    },
    svgClass () {
      if (this.className) {
        return 'svg-icon ' + this.className
      } else {
        return 'svg-icon'
      }
    }
  }
}
</script>
