<!--Created by 熊超超 on 2018/4/25.-->
<template>
  <div style="display: inline-block" data-flex="cross:center">
    <svg :class="svgClass" :style="styleObj" aria-hidden="true" @click="$emit('click')" v-if="!name.startsWith('el-icon')">
    <use :xlink:href="iconName"></use>
  </svg>
  <i :class="name" v-else></i>
  </div>
</template>

<script>
export default {
  name: 'xt-icon',
  props: {
    name: { required: true, type: String },
    className: String,
    rotate: { type: Number, default: 0 },
    size: { type: [String, Number], default: 24 },
  },
  computed: {
    svgClass () {
      return ('svg-icon ' + (this.className || '')).trim()
    },
    iconName () {
      return `#icon-${this.name}`
    },
    styleObj () {
      return {
        transform: `rotate(${this.rotate}deg)`,
        fontSize: `${this.size}px`
      }
    },
  }
}
</script>

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